Add Geometry to doc

Hi all,

I am writing a C# component that adds curves to the rhino doc using AddCurve(curve, object attribute) method. This works quite well on the model spaces (Perspective, Top, Front, Right, etc) - whichever viewport is active, it creates the geometry at the same spot in the WorldXYZ space. However, if I run the code with the layout view active, it instead add the geometry in the layout.

There must be a way to let Rhino add the curve in model space even though the layout is set as an active view. Does anyone know how to do this?

public Guid Draw(Curve crv)
{
    // set object attribute
    var objctAttrbt = new Rhino.DocObjects.ObjectAttributes();
    objctAttrbt.DisplayOrder = 1;

    // add geometry to the doc
    var gid = doc.Objects.AddCurve(crv, objctAttrbt);

    // refresh
    doc.Views.Redraw();

    // return output
    return gid;
}

Just to better illustrate, the first picture below shows the result of the code - where I run the code in any of model space views, then set the layout view(paper) active to see the geometry in the proper position.

and this shows the result of the code ran in the layout view.

Any feedback will be much appreciated. Thanks,

W

objctAttrbt.Space = ActiveSpace.ModelSpace;

should do the trick I think.

1 Like

Ha that simple. Thanks a lot.

W

2022๋…„ 7์›” 7์ผ (๋ชฉ) ์˜คํ›„ 5:40, Menno Deij - van Rijswijk via McNeel Forum <notifications@mcneel.discoursemail.com>๋‹˜์ด ์ž‘์„ฑ:

@menno, I gave it a try, but it didnโ€™t work. Below is the code.


  public Guid Draw(Curve crv)
  {
    // set object attribute
    var objctAttrbt = new Rhino.DocObjects.ObjectAttributes();
    objctAttrbt.Space = Rhino.DocObjects.ActiveSpace.ModelSpace;

    // add geometry to the doc
    var gid = doc.Objects.AddCurve(crv, objctAttrbt);

    // refresh
    doc.Views.Redraw();

    // return output
    return gid;
  }

Any thoughts?

P.S. it looks like it is already in the model space. Please see below.

Answering my own question, just in case someone has the same question.

  public Guid Draw(Curve crv)
  {
    // set object attribute
    var objctAttrbt = new Rhino.DocObjects.ObjectAttributes();

    // set one of the detail views active 
    var pgVw = doc.Views.GetPageViews()[0];
    var dtlVw = pgVw.GetDetailViews()[0];    
    dtlVw.IsActive = true;

    // add geometry to the doc
    var gid = doc.Objects.AddCurve(crv, objctAttrbt);

    // deactivate the detail view
    dtlVw.IsActive = false;

    // refresh
    doc.Views.Redraw();

    // return output
    return gid;
  }

@menno , although the above works, I found it is resource intensive, especially in PCs (strangely it is much faster in Macs). Do you have any suggestions to do it without activating any of the model spaces? Thanks,

Hi,

I found a solution:
-1 bake the object
-2 set its attributes activespace to modelspace
-3 set its attributes viewportid to empty guid
-4 commit changes on the object

 var obj =  doc.Objects.FindId(doc.Objects.Add(geo, att));
 obj.Attributes.Space = ActiveSpace.ModelSpace;
 obj.Attributes.ViewportId = Guid.Empty;
 obj.CommitChanges();

@Ludovic,

Thanks for the reply. I havenโ€™t tried it yet, but does it place the geometry at its original spot?

W

Yes, in the world coordonate system