Whenever a geometry is added to Rhino document from ghpython component, “SelLast” command fails to catch it the first time it is ran. It just outputs: “SelLast selection set is empty.”
It gets caught only when “SelLast” command has been ran the second time.
What is causing this? I perfectly understand that ghpython targets Grasshopper document, however the fact that we can also add geometry to Rhino document, would mean that we should be able to select it with SelLast first call. Or am I wrong?
The issue does not exist with Rhino Python Editor, only with ghpython component on both Rhino 5 and Rhino 6, regardless of the fact if we switch from Grasshopper to Rhino document or not (sc.doc = Rhino.RhinoDoc.ActiveDoc, sc.doc = ghdoc)
Here is a short example.
Any help would be appreciated.
import rhinoscriptsyntax as rs
import Rhino
sph = Rhino.Geometry.Sphere(Rhino.Geometry.Point3d(0,0,0), 5)
id = Rhino.RhinoDoc.ActiveDoc.Objects.AddSphere(sph)
I don’t know how _SelLast is implemented. Features like this one (I am really thinking of _Undo) usually use some knowledge derived from the state of the command that is running, so this might be the cause. @dale or @lowell might be able to tell more.
Hello @dale, @lowell, @stevebaer
I have just tested Rhino 7 beta ( version 7.0.20301.12003, 10/27/2020) and the issue is still present.
Is there a hope it will be fixed with the first release of Rhino 7?
Coming in from the side, but, FWIW, the list for 7.0 is “closed” at this point and, given that this is on the Future list, I’d say that there is no chance of that happening, no.
Hello,
Bump again on this issue.
As Wim pointed out the Release target for it is Future.
All my hopes that this will be fixed in Rhino 7 have been drowned :(. Is there at least some workaround that we can do until then? A workaround through code?
Hi Steve,
Thank you for the reply.
Is there a workaround until this is fixed? Selecting the last added geometries to the document through code?
A code that I can assign to an alias, and essentially make something a command: SelLast2?
Something similar to what Giulio showed?
record = Rhino.RhinoDoc.ActiveDoc.BeginUndoRecord("AddingSphere")
print (record) #record is 0. Rhino.RhinoDoc.ActiveDoc.CurrentUndoRecordSerialNumber shows an existing number
sph = Rhino.Geometry.Sphere(Rhino.Geometry.Point3d(0,0,0), 5)
id = Rhino.RhinoDoc.ActiveDoc.Objects.AddSphere(sph)
Rhino.RhinoDoc.ActiveDoc.EndUndoRecord(record)
Probably not for 8.0 due to my current set of features/bugs that need attention. I moved the issue to 8.x with hopes that I can dig further into it once we have the 8.0 list completed
Have you tried first ending the current undo record. Then starting a new one?
The code below draws a line that can be undone and redone. And sellast seems to work also.
import Rhino
import Rhino.Geometry as rg
AD= Rhino.RhinoDoc.ActiveDoc; do= AD.Objects;
sn=AD.CurrentUndoRecordSerialNumber
AD.EndUndoRecord(sn);
undo_num= AD.BeginUndoRecord("My Line")
if undo_num!= 0:
line=rg.Line(rg.Point3d(0,0,0),rg.Point3d(20,40,0))
do.AddLine(line,None)
AD.EndUndoRecord(undo_num)
else: print "Undo recording caused My Line to fail"
AD.Views.Redraw();
Hi @jim ,
Thank you for the reply and the effort.
It does not work - it still requires running _SelLast command two times.
(P.S. this whole topic is about Ghpython component. In the youtrack correspondence it seems the same issue exists for C# and VB.NET components).
Well, I’m a devout Curmudgeon and don’t do Grasshopper or Facebook or Twitter or any of the other things that are Verboten for us Curmudgeons.
But
If after running your script it requires 2 sellast for the sellast command to work then I would try adding one sellast command to the end of your script…
Like this:
Rhino.RhinoApp.RunScript('sellast')
What I came to understand due to my training in the above mentioned religious beliefs is that when working with RhinoCommon you have to expect the documentation to be awful and the advice from McNeel to be even worse.
If you start from those assumptions and just experiment to find out what really will work regardless of what McNeel says, you will get a lot more done.