Hi,
I have a script and I created a button. Now I would like to choose which elements (alignments) script will run. Is it any way to select alignment and then script will run at this one?
The normal object selection nodes donât have trigger events or incoming ports that would let you do this.
The best option you might have is to use a code block that can trigger an object prompt, and pass that object to the next node.
You can get the âcurrently selectedâ, but usually running a command (via your button) that launches Dynamo will clear the active selection.
There are options though.
This bit of Python shoudl give some breadcrumbs:
from Autodesk.AutoCAD.ApplicationServices import Application #we need to know which document we're working with so we need the applicaton class
from Autodesk.AutoCAD.EditorInput import Editor #we need to work with the active editor to use the selection methods
from Autodesk.AutoCAD.DynamoNodes import SelectionByQuery, Document #we need to convert from ACAD objects to wrapped Dynamo references thereto.
### If you already control your "button" to only trigger functions when the selected object is valid for your use this may work well enough - be careful of invalid selections though.
prev = [ SelectionByQuery.ObjectByHandle(Document.Current, str(i.Handle)) for i in Application.DocumentManager.MdiActiveDocument.Editor.SelectPrevious().Value.GetObjectIds() ] #gets the previously selected content.
###If you want to tell the user to select a new object (incase the one selected when the button wasn't valid, or if you're worried previous might be an invalid object type) this can be of use
forceNewSelection = [ SelectionByQuery.ObjectByHandle(Document.Current, str(i.Handle)) for i in Application.DocumentManager.MdiActiveDocument.Editor.GetSelection().Value.GetObjectIds() ] #triggers the user to make a new selection.
OUT = prev, forceNewSelection
Note that dynamo will start to run for the âforce selectionâ if you havenât selected something in the editor since Dynamo launched or last ran. So watch both the Dynamo and the Civil 3D command line when experimenting.
Thank you very much. Itâs great!
1 Like