Hello,
I am trying to import a DWG file to Dynamo, through API.
The DWG file contains just one cube-like solid. I attached an example of it.
test.dwg (29.1 KB)
Here is the code I am using:
import clr
# dynamo dlls
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
import Revit.Elements as rn
clr.AddReference('DSCoreNodes')
import DSCore
from DSCore import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# revit dlls
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI.Selection import *
doc = DocumentManager.Instance.CurrentDBDocument
# a) get '3D' view
elColl = FilteredElementCollector(doc) \
.OfClass( clr.GetClrType(View) )
elColl.WhereElementIsNotElementType()
view_L = elColl.ToElements()
for view in view_L:
if (view.Name == '{3D}'):
break
# b) import DWG
options = DWGImportOptions()
options.ThisViewOnly = False
TransactionManager.Instance.EnsureInTransaction(doc)
el_id__clr = clr.StrongBox[ElementId]()
DWGfilepath = r"C:\revit\test.dwg"
success = doc.Import(DWGfilepath, options, view, el_id__clr)
TransactionManager.Instance.TransactionTaskDone()
if success:
el_id = el_id__clr.Value
el = doc.GetElement(el_id)
OUT = el # outputs 'ImportInstance'
The last line in the upper code outputs an ImportInstance object.
How can I get a Dynamo/Revit solid from it?
The el.get_Geometry(Options())
didn’t work.
There seems to be a GetGeneratingElementIds method, but it requires a GeometryObject input, which I don’t know how to define.
Any help is welcomed.