Set CheckNewObjects
to on persistently.
Run the code below in V8 in both EditPythonScript and in ScriptEditor (doesn’t matter Py2 or Py3). Select the curve in the file - deliberately chosen to produce a bad object.
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
#polyline
def pl_filt(rhino_object, geometry, component_index):
return rs.IsPolyline(geometry)
pl_id=rs.GetObject("Select polyline",4,custom_filter=pl_filt)
if pl_id:
pl_crv=rs.coercecurve(pl_id)
rc,pl=Rhino.Geometry.PolylineCurve.TryGetPolyline(pl_crv)
if rc:
tol=0.1
print("Original point count={}".format(pl.Count))
#reduce number of segments
pl.ReduceSegments(tol)
print("Reduced point count={}".format(pl.Count))
print("Polyline IsValid={}".format(pl.IsValid))
sc.doc.Objects.Replace(pl_id,pl)
sc.doc.Views.Redraw()
TestBadObj.3dm (2.2 MB)
When running in EditPythonScript, the “Invalid geometry…” warning from CheckNewObjects
will come up immediately when the script finishes.
Undo and run the code in ScriptEditor and no message is shown. Funny thing is if you Undo the script, THEN the dialog shows up - this despite the fact that undoing the script made the object valid again…
Also, in either case, pl.IsValid
remains True
after the operation even though the polyline is considered a bad object…