im trying to automate the creation of a leader so it automatically populates the object name of a selected object using a simple marco but cant figure it out.
this is what I have so far but its not working. any help greatly appreciated.
I’ve asked for this before, so… +1
It should be possible to script this functionality.
- Create a functional leader from scratch as per your current process, or
- Copy an existing leader and assign it to a new part
(sorry, not a very helpful comment in hindsight)
it would be easy to do in a simple macro button im sure. I just cant work out what I need to put in the button.
I have the following but its not working.
Yeah, you don’t get a chance to select an object with -Leader. You can force it with a script-
! -Runscript ( Call Main() Sub Main() Rhino.Command "-Leader" If Rhino.LastCommandResult <> 0 Then Exit Sub Dim sLeader: sLeader = Rhino.LastCreatedObjects()(0) If isNull(sLeader) Then Exit Sub If Not Rhino.IsLeader(sLeader) Then Exit Sub Dim text : text = "%<objectname" & "(" & chr(34) Dim sObj: sobj = Rhino.GetObject() If isNull(sObj) Then Exit Sub text = text & sobj & chr(34) & ")>%" Rhino.LeaderText sLeader, text End Sub )
You can also create the leader in the script, I used the Rhino command here. Enter when it asks for leader text, then select the named object.
that nearly works. only issue now is as im adding these leaders in a layout tab im unable to select the named objects displayed in a viewport…
is there a way to make this happen in your script?
Hmmm - so the leaders are in layout and the objects in model space? I guess we could pop up a list of named objects and have you select from there - would that be OK?
there are thousands of named objects in my model. it would take me 5 mins per leader to find the correct one.
I note when you make a leader manually in a layout tab, assign a function (fx) button and then select named object rhino will let you choose objects that are displayed in a viewport without even activating the viewport.
If rhino can do this natively would it be possible to script it?
Hi Dax - it does seem to work to just activate a model tab, select the object, then go back to the layout.
How about this:
! -Runscript ( Call Main() Sub Main() Dim sLayout: sLayout = Rhino.CurrentView(, False) Rhino.Command "-Leader" If Rhino.LastCommandResult <> 0 Then Exit Sub Dim sLeader: sLeader = Rhino.LastCreatedObjects()(0) If isNull(sLeader) Then Exit Sub If Not Rhino.IsLeader(sLeader) Then Exit Sub Dim text : text = "%<objectname" & "(" & chr(34) Rhino.CurrentView "Top" Dim sObj: sobj = Rhino.GetObject() Rhino.CurrentView sLayout If isNull(sObj) Then Exit Sub text = text & sobj & chr(34) & ")>%" Rhino.LeaderText sLeader, text End Sub )
getting better, I like your thinking
its kind of difficult to select the object by directing me back the a view (top) or other view as the viewports have many layers turned off that allow me to easily select parts buried deep in the model. when your script directs me back to the top view or any other view its very difficult to find the part im after.
I really need to be able to select the part from the viewport window as the native rhino command does.
any advances on version 2.0 with the above in mind?
I’ll poke at it some more- we may be able to just make a detail current in the script as well.
ok cool, that would be excellent.