Curves in CAD

Hello, All,
I want to return the curves in the linked DWG. I have no idea how to do that with the API (withouth Bimorph Packadge). I have searched the forum and got some hints but I cannot step further due to this error. The DWG has two layers which contain many lines. If someone can help me to go deeper, I will be grateful. Thank you.

Anyone?

Why not utilize the BiMorph node?

The node is perfect but I have a node based dynamo library and I started a personal project to convert this library to a revitAPI based one. The reason for this is to gain more knowledge about API as I noticed that more horizons open for me and therefore, more efficiency to my work.

Not sure if you have a link type or a link instance or an import or… Also it’s a bit hard to expand code when given an image.

That said, it may be that now that you have the geometry you just need to convert it to a Dynamo geometry. Get rid of the erroring line and use something along the lines of this (make sure you have the right boilerplate for geometry conversion tools).

DynaGeo = [g.ToProtoType() for g in Geo]

I have tried your line but it gives me attribute error “Geometry Instnace has no attribute ToProtoType()” and then I changed it to

DynaGeo = [g.GetInstanceGeometry() for g in Geo]

and it gives me the geometries.

The reason for giving me the error in the image above is that I assigned the method (GetInstanceGeomery()) to a list. However, it gives the error “‘GeometryElement’ object is not subscriptable” when I assign the method to the first item in the list. I mean, Geo[0].GetInstanceGeomery()
It only works in the case of using for loop.
Isn’t that strange? Is this a specific type of list?

Likely the error is in the Geo[0] bit, as the item returned from the previous method is an array, enumerator or other type of .net collection which doesn’t automatically convert to a Python list.

1 Like

Yeah, It works now.
Here is my script FYI.

import clr

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure 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 DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

#Preparing inputs from Dynamo
II = UnwrapElement(IN[0])
LayerName=IN[1]

#Layers in the CAD (As SubCategories)
Layers= II.Category.SubCategories
#The Target Layer (As Category)
TLayer= Layers[LayerName]

#Preparing Geometry Option
Opt=Options()
Opt.ComputeReferences
Opt.IncludeNonVisibleObjects

#Getting All Geometries in the CAD (As Geometry Element)
GeoElement=II.get_Geometry(Opt)
#Converting to Geometry Instances (Curves)
GeoInstances = [g.GetInstanceGeometry() for g in GeoElement][0]

Curves=[]
#Getting Geometries in the Target Layer
for j in GeoInstances:
	GStyleId=j.GraphicsStyleId
	GS=doc.GetElement(GStyleId)
	GeoCat= GS.GraphicsStyleCategory
	if TLayer.Id==GeoCat.Id:
		Curves.append(j)
	else:
		pass

OUT = Curves

Thanks, Jacob.

4 Likes