Import DWG to dynamo

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.

@george ,

What is the purpose of it?

do you want it in the Project?

it recommendable load your cube to a generic model and than load it into your project!
it also recommandable to clean up your family before loading.

KR

Andreas

1 Like

Hi @Draxl_Andreas ,
Thank you for replying.
I have a dwg file with some solid, for which I would like to perform volume, size analysis in Dynamo. They are not all cubes (I just did this as an example). These solids do not have to appear in the Project, I just need them as designscript ‘Solid’ in Dynamo.

I didn’t understand you this part:

@george ,

each import (.dwg) creates a contamination of materials and layers (Object Styles)…
it creates unused data… be aware of that.

H @Draxl_Andreas ,
Thank you, I was not aware of this.
I am not going to save this .rvt file.
The purpose of importing/linking dwg file is just to perform size/volume analsysis of the solids inside the .dwg file.

Do you know how to get the DesignScript ‘Solid’ (or Autodesk.Revit.DB.Solid) from the Autodesk.Revit.DB.ImportInstance object?

@george ,

there are smooth work arounds you can create a cubiod and make a boundingBox.
so you can ask what is in it?


Hi @Draxl_Andreas ,
The solids in the .dwg file are not all cuboids. Or even if they all are, I need to reference them from the .dwg file, not manually create them in Dynamo.
I am not looking for an advice how to obtain measurements (boundingbox…) from the cuboid. But how to get a DesignScript ‘Solid’ object or Revit API Solid object from a .dwg file.

Thank you for your answers, anyhow.