Make2D via a python script keeps crashing Rhino

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()

Hi Daniel -

There’s nothing here for the eMail address that you use here on Discourse…
image

Is this something that works fine on Rhino 7 but crashes the WIP?
-wim

Sorry Ive sent it using “daniel.krajnik@chetwoods.com

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).

Hi Daniel -

That might not be such a good idea, though:

At any rate, I’m not getting crashes here on Rhino 7 or the Rhino 8 WIP. Moving this thread to “Scripting”…
-wim

1 Like

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.

Untitled-Sheet.3dm (160.9 KB)
Untitled.3dm (166.6 KB)
BatchMake2D.py (3.7 KB)

Hi @Daniel_Krajnik,

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.

– Dale

1 Like

Thank you for looking into this.

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.

For crashes in core Rhino, no. You need access to our debug symbol library (pdb), which we don’t make available.

– Dale

No worries, thanks for letting me know.

I should add that you should try disabling all 3rd party plug-ins. I see you have V-Ray, perhaps others.

– Dale

1 Like

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):

it’s a complex model, I will try to send a simpler sample if that’s okay

Please see a “Proof Of Concept” attached - solving it would be extremely helpful:

Clipping Planes HiddenLineDrawing Issue - BatchMake2D.3dm (176.7 KB)
BatchMake2D.py (3.7 KB)

Or please let me know if it would be better to just abandon HiddenLineDrawing.Compute method altogether and just script -Make2D command instead :slight_smile:

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.

– Dale

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 :frowning:

It doesn’t unfortunately prompt for the crash report, but I found crash dumps in Appdata/Local/CrashDumps - please see them attached here: WeTransfer - Send Large Files & Share Photos Online - Up to 2GB Free

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)

Hi @Daniel_Krajnik,

Can you provide me a way to repeat this crash?

I’d also like to see the output of the SystemInfo command, as many of crashes indicate memory allocation and releasing are involved.

Thanks,

– Dale

1 Like

Sure, thank you - please see the models attached here: WeTransfer - Send Large Files & Share Photos Online - Up to 2GB Free

To crash:

  1. open model “4821-CA-ZZ-ZZ-M3-A-09001 Site.3dm”
  2. make sure to relink “4821-CA-ZZ-ZZ-M3-A-09002 Independent Living.3dm” (other links shouldn’t be relevant)
  3. open the layout “02111”
  4. Run command: RunPythonScript BatchMake2D.py (included in the above link)
  5. Choose 02111 in the list pop up and press OK

Rhino should crash at some point while processing the script. Sometimes it required two three tries, sometimes it was on almost instant.

SystemInfo:

Rhino 8 SR0 2023-1-10 (Rhino WIP, 8.0.23010.12305, Git hash:master @ 11f0f80af7d8c8b84087583e5b1f98523fb16dad)
License type: Commercial, build 2023-01-10
License details: Cloud Zoo
Expires on: 2023-02-24

Windows 10 (10.0.19045 SR0.0) or greater (Physical RAM: 32Gb)

Computer platform: DESKTOP 

Standard graphics configuration.
  Primary display and OpenGL: NVIDIA Quadro P2000 (NVidia) Memory: 5GB, Driver date: 9-12-2022 (M-D-Y). OpenGL Ver: 4.6.0 NVIDIA 517.40
    > Accelerated graphics device with 4 adapter port(s)
        - Secondary monitor attached to adapter port #0
        - Windows Main Display attached to adapter port #1

OpenGL Settings
  Safe mode: Off
  Use accelerated hardware modes: On
  Redraw scene when viewports are exposed: On
  Graphics level being used: OpenGL 4.6 (primary GPU's maximum)
  
  Anti-alias mode: 4x
  Mip Map Filtering: Linear
  Anisotropic Filtering Mode: High
  
  Vendor Name: NVIDIA Corporation
  Render version: 4.6
  Shading Language: 4.60 NVIDIA
  Driver Date: 9-12-2022
  Driver Version: 31.0.15.1740
  Maximum Texture size: 32768 x 32768
  Z-Buffer depth: 24 bits
  Maximum Viewport size: 32768 x 32768
  Total Video Memory: 5 GB

Rhino plugins that do not ship with Rhino

Rhino plugins that ship with Rhino
  C:\Program Files\Rhino 8 WIP\Plug-ins\Commands.rhp	"Commands"	8.0.23010.12305
  C:\Program Files\Rhino 8 WIP\Plug-ins\rdk.rhp	"Renderer Development Kit"	
  C:\Program Files\Rhino 8 WIP\Plug-ins\RhinoBonusTools.rhp	"Rhino Bonus Tools"	
  C:\Program Files\Rhino 8 WIP\Plug-ins\RhinoRenderCycles.rhp	"Rhino Render"	8.0.23010.12305
  C:\Program Files\Rhino 8 WIP\Plug-ins\RhinoRender.rhp	"Legacy Rhino Render"	
  C:\Program Files\Rhino 8 WIP\Plug-ins\rdk_ui.rhp	"Renderer Development Kit UI"	
  C:\Program Files\Rhino 8 WIP\Plug-ins\NamedSnapshots.rhp	"Snapshots"	
  C:\Program Files\Rhino 8 WIP\Plug-ins\RhinoCycles.rhp	"RhinoCycles"	8.0.23010.12305
  C:\Program Files\Rhino 8 WIP\Plug-ins\RhinoCode\RhinoRoslyn.rhp	"RhinoRoslyn"	8.0.23010.12305
  C:\Program Files\Rhino 8 WIP\Plug-ins\ConstraintsUI.rhp	"Constraints UI"	8.0.23010.12305
  C:\Program Files\Rhino 8 WIP\Plug-ins\RhinoCode\RhinoCodePlugin.rhp	"RhinoCodePlugin"	8.0.23010.12305
  C:\Program Files\Rhino 8 WIP\Plug-ins\RhinoCode\RhinoCPython.rhp	"RhinoCPython"	8.0.23010.12305
  C:\Program Files\Rhino 8 WIP\Plug-ins\Toolbars\Toolbars.rhp	"Toolbars"	8.0.23010.12305
  C:\Program Files\Rhino 8 WIP\Plug-ins\3dxrhino.rhp	"3Dconnexion 3D Mouse"	
  C:\Program Files\Rhino 8 WIP\Plug-ins\Displacement.rhp	"Displacement"	

Hi @Daniel_Krajnik,

I am able to reproduce the crash in the Rhino 8 WIP. Rhino 7 seems stable - I suggest using this version for this operation.

I have not pinned down the source of the crash. But I am suspect of .NET. Unlike Rhino 7, which uses .NET Framework 4.8, the Rhino 8 WIP uses .NET 7.

I’ll post here if I have any additional information.

Thanks,

– Dale

1 Like

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 :slight_smile:

Keep in mind that Rhino WIPs are “use at your own risk”. Often they are not stable or production-ready.