Hi,
In Rhino Common, I add an Object (Curve, Text etc.) to the Model Space by:
doc.Objects.AddXXX()
What’s the Equivalent to adding something to the Layout Space? Inserting a 2D Line, A Text, Dimensions and Block instances?
Thanks
Karl
Hi,
In Rhino Common, I add an Object (Curve, Text etc.) to the Model Space by:
doc.Objects.AddXXX()
What’s the Equivalent to adding something to the Layout Space? Inserting a 2D Line, A Text, Dimensions and Block instances?
Thanks
Karl
The document takes into account the active view when adding geometry. If you have a layout active, the geometry will be added to that specific layout.
As an alternative, you can create ObjectAttributes and set the ViewportId to that of the layout’s main viewport. Pass this ObjectAttributes to the Add functions.
Steve,
Is the second method working properly in Rhino 6?
For example, if I try to add a line on the “Page 1” layout using the code below inside a grasshopper C# component, this line always appears on the active layout.
Rhino.DocObjects.ObjectAttributes att = new Rhino.DocObjects.ObjectAttributes();
var view = RhinoDocument.Views.Find("Page 1", false);
att.ViewportId = view.MainViewport.Id;
RhinoDocument.Objects.AddLine(new Point3d(0, 0, 0), new Point3d(100, 100, 0), att);
Thanks,
Alan
Hi @atai,
I am not finding the second method working. I’ve logged a bug for that.
https://mcneel.myjetbrains.com/youtrack/issue/RH-49373
This, however, does work (from a plug-in command):
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
var page_views = doc.Views.GetPageViews();
if (null == page_views || 0 == page_views.Length)
return Result.Nothing;
const string page_name = "Page 1";
var page_view = page_views.FirstOrDefault(pg => pg.PageName.Equals(page_name, StringComparison.OrdinalIgnoreCase));
if (null == page_view)
{
RhinoApp.WriteLine("{0} page view not found.", page_name);
return Result.Nothing;
}
var plane = Plane.WorldXY;
var circle = new Circle(plane, 5.0);
doc.Views.RedrawEnabled = false;
var old_view = doc.Views.ActiveView;
doc.Views.ActiveView = page_view;
doc.Objects.AddCircle(circle/*, attributes*/);
doc.Views.ActiveView = old_view;
doc.Views.RedrawEnabled = true;
doc.Views.Redraw();
return Result.Success;
}
– Dale
Dale,
Thanks. Switching between active layout works.
Alan
Hi everyone, if you are working with detail in pageview then you should set pageview as active in order to add objects to page layout instead of the document in detail view. For example :
detail.DetailGeometry.IsProjectionLocked = true;
detail.CommitViewportChanges();
detail.CommitChanges();
pageview.SetPageAsActive();
doc.Views.ActiveView = pageview;
RhinoDoc.ActiveDoc.Objects.AddCurve(new Line(new Point3d(20, 20, 0), new Point3d(200, 20, 0)).ToNurbsCurve());
as this was googles first hit I will revive this topic and add an 2024 update:
There is a newer topic about adding or changing the space and viewport a Object is drawn to.
how-to-copy-objects-from-one-layout-to-another-with-rhinocommon
basically this approach uses Object Attributes - and this looks more handy approach.
the following c# snippet should point to this approach as well
RhinoView viewInfo = doc.Views.Find("Info", false);
if (viewInfo == null) return Result.Failure;
// attrs
ObjectAttributes attrs = new ObjectAttributes()
{
LayerIndex = layIndex,
ColorSource = ObjectColorSource.ColorFromObject,
ObjectColor = System.Drawing.Color.DarkBlue,
Space = ActiveSpace.PageSpace,
ViewportId = viewInfo.ActiveViewportID
};
doc.Objects.AddLine(li, attrs);
doc.Views.Redraw();