Script below keeps crashing the model. Make2D command works fine.
import Rhino.Geometry
from Rhino.DocObjects import ObjectType
from Rhino.Display import RhinoPageView
import scriptcontext as sc
import rhinoscriptsyntax as rs
def BatchMake2D():
selected_page_names = rs.MultiListBox([i.PageName for i in sc.doc.Views.GetPageViews()])
if selected_page_names == None:
return
selected_pages = [i for i in sc.doc.Views.GetPageViews() if i.PageName in selected_page_names]
for selected_page in selected_pages:
detail_views = RhinoPageView.GetDetailViews(selected_page)
for detail_view in detail_views:
if detail_view.Name == None:
continue
if "CGeo" in detail_view.Name:
continue
first_corner = Rhino.Geometry.Point2d(detail_view.Viewport.Bounds.Left, detail_view.Viewport.Bounds.Bottom)
second_corner = Rhino.Geometry.Point2d(detail_view.Viewport.Bounds.Right, detail_view.Viewport.Bounds.Top)
detail_view.IsActive = True
rhino_objects = sc.doc.Objects.FindByCrossingWindowRegion(detail_view.Viewport,
first_corner, second_corner,
True, ObjectType.AnyObject)
parameters = Rhino.Geometry.HiddenLineDrawingParameters()
parameters.AbsoluteTolerance = sc.doc.ModelAbsoluteTolerance
parameters.Flatten = True
parameters.IncludeHiddenCurves = False
parameters.IncludeTangentEdges = False
parameters.IncludeTangentSeams = False
parameters.SetViewport(detail_view.Viewport)
for obj in rhino_objects:
parameters.AddGeometry(obj.Geometry, obj.Id)
# find a corresponding detail view - one with '-CGeo' suffix in the name
for vp in detail_views:
if vp.Name and detail_view.Name in vp.Name and "CGeo" in vp.Name:
cgeo_viewport = vp.Viewport
cgeo_viewport_plane = Rhino.Geometry.Plane(cgeo_viewport.CameraTarget,
cgeo_viewport.CameraX,
cgeo_viewport.CameraY)
xform = Rhino.Geometry.Transform.PlaneToPlane(Rhino.Geometry.Plane.WorldXY, cgeo_viewport_plane)
hld = Rhino.Geometry.HiddenLineDrawing.Compute(parameters, True)
for hld_curve in hld.Segments:
if not hld_curve:
continue
if not hld_curve.ParentCurve:
continue
if hld_curve.ParentCurve.SilhouetteType == Rhino.Geometry.SilhouetteType.None:
continue
if hld_curve.SegmentVisibility == Rhino.Geometry.HiddenLineDrawingSegment.Visibility.Visible:
source_obj_attribs = rs.coercerhinoobject(hld_curve.ParentCurve.SourceObject.Tag).Attributes
curve = hld_curve.CurveGeometry.DuplicateCurve()
curve.Transform(xform)
sc.doc.Objects.AddCurve(curve, source_obj_attribs)
sc.doc.Views.Redraw()
BatchMake2D()
I havent checked that, but will test it by the end of today
If you tested the exact script above one thing to note is that it requires two viewports on a layout named xxxxx and xxxxx-CGeo (e.g. “viewport1” and “viewport1-CGeo”) to work.
I’ve tried it again on another machine and Make2D stopped crashing:
Changing unit absolute tolerance from 0.001 to 1 made a huge difference in the output - I think this might have caused the crashes…
Interestingly though blocks were not being processed by the script, but they did work in the Make2D command. I’ve exploded them and the script worked fine. It would be useful though to find why blocks are being ignored to avoid the step of exploding them
It’s the same Rhino version though (WIP 8 8.0.23010.12305, 2023-01-10).
Thanks for letting me know, you are right 0.01 works even better.
There may still be an issue though with Making2D of linked blocks when run from a script (example 3dm file with a simple box and a sheet linking it attached here). It does work when run from “Make2D” command.
If you knew what might be causing it please let me know.
I see your crashing in the Rhino 8 WIP. Can you repeat the crash in Rhino 7?
I can see you’ve reported two crashes under the email of daniel.krajnik@chewoods.com, fwiw.
One of the crashes occurs deep in the .NET framework in what looks like a text (glyph) drawing routine. The crash occurs pretty far away from any Rhino function call. I’d suggest running Windows Updates and install all of them, expecially any .NET Framework or .NET Core updates.
The other crash is incomplete and, thus, inconclusive. But it does appear to be related to drawing.
It may be a bit tricky, there are many linked blocks that will need to be saved as Rhino 7…
There should be one more crash under dan94kra@gmail.com from earlier today - I will try to use this email from now on to avoid confusion.
That is really good to know - thank you. I will look for the latest updates then.
A follow up question: Is this type of diagnostic something that a user can do as well (using for example dotMemory/dotPeek/dotTrace or similar tools)? Or does it usually require the core source code? It sounds like a really useful technique that might explain a lot of crashes.
That’s true, there were some crashes even before installing vray, but if .NET Updates won’t help I will try removing plugins.
A bigger concern for me though is that make2d from the above python script doesn’t produce correct results in combination with clipping planes - solving this would really bring value for us now (model on the left, make2d(HiddenLineDrawing.Compute()) results on the right):
Well, you should try the Make2d command first. It is written in C# and calls the same APIs that are available to you. So if it works and your code does not, then there is something missing from your implementation.
Thanks, I’ve ended up using Make2D command and it seems to perform better than HiddenLineDrawing.Compute() (linked blocks and clipping planes all worked out fine).
However, even after updating to the latest .Net platform and removing a lot of plugins (Vray and other third parties) crashes still occur
Rhino crashed always when running Make2D on a particularly big linked block.
If you could please look at them it would be really helpful. Hopefully, they explain what may be causing Make2D to crash. Updated-BatchMake2D.py (3.6 KB)
Thanks for checking this. It’s good to hear that it’s reproducible. If you find out more please do update us. Due to many linked blocks moving back to Rhino 7 isnt straightforward, so hopefully some way to fix it will come up as well