Is it possible to retrieve selected objects from screen by python code? if yes, may i know how
Look into the Tool.GetRevitSelection node in Steamnodes package.
You can also try writing code on your own. This is where you should start:
http://www.revitapidocs.com/2018.1/4af3bdc7-e69c-8aa6-406d-865d7f036927.htm
i wrote the code as below. its not working perfectly. donât know where is the mistake.
import clr
clr.AddReference(âRevitAPIâ)
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Mechanical import *
#from Autodesk.Revit.UI.Selection import *
clr.AddReference(âRevitAPIUIâ)
from Autodesk.Revit.UI import *
clr.AddReference(âSystemâ)
from System.Collections.Generic import List
clr.AddReference(âRevitNodesâ)
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
clr.AddReference(âRevitServicesâ)
import RevitServices
from RevitServices.Persistence import *
#from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import *
#from RevitServices.Transactions import TransactionManager
#The inputs to this node will be stored as a list in the IN variables.
doc1 = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc = uiapp.ActiveUIDocument
doc = uidoc.Document
sel = uidoc.Selection
selid = sel.GetElementIds()
OUT = selid
Try this:
import clr
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
OUT = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument.Selection.GetElementIds()
this is same as the which i posted. both are working at one time. second time it is not working !
Itâs perfectly normal. Youâre not changing the inputs/wire/etc., so fore Dynamo perspective, there is no need to reevaluate this script.
Try connecting a âpseudo-inputâ to the script and change its value everytime you want to re-run the script (e.g. a true/false button, that youâd switch every time).
Add second input Refresh bool true/false.
now its working.
that means we canât use Dynamo as a plugin, right?
Glad it worked!
We can use. It depends how you build your script.
Please mark the post as solved.
It means that scripts that use selection are better run from Dynamo Player rather than from opened Dynamo.