# Curves in CAD

**URL:** <https://forum.dynamobim.com/t/curves-in-cad/83997>\
**Category:** Uncategorized\
**Created:** [December 10, 2022, 4:43am UTC](https://forum.dynamobim.com/t/curves-in-cad/83997 "2022-12-10T04:43:32Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Omar.Elwan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/omar.elwan/32/127651_2.png) [@Omar.Elwan](https://forum.dynamobim.com/u/Omar.Elwan)\
**Post date:** [December 10, 2022, 4:43am UTC](https://forum.dynamobim.com/t/curves-in-cad/83997/1 "2022-12-10T04:43:32Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/2/0/20cbd153a10e68c5fd8835f5d3b9bb9a3ed2fb41.png)

---

<div class="post-metadata">

**Author:** ![Omar.Elwan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/omar.elwan/32/127651_2.png) [@Omar.Elwan](https://forum.dynamobim.com/u/Omar.Elwan)\
**Post date:** [December 10, 2022, 11:19am UTC](https://forum.dynamobim.com/t/curves-in-cad/83997/2 "2022-12-10T11:19:55Z")

</div>

Anyone?

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [December 10, 2022, 11:22am UTC](https://forum.dynamobim.com/t/curves-in-cad/83997/3 "2022-12-10T11:22:41Z")

</div>

Why not utilize the BiMorph node?

---

<div class="post-metadata">

**Author:** ![Omar.Elwan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/omar.elwan/32/127651_2.png) [@Omar.Elwan](https://forum.dynamobim.com/u/Omar.Elwan)\
**Post date:** [December 10, 2022, 12:08pm UTC](https://forum.dynamobim.com/t/curves-in-cad/83997/4 "2022-12-10T12:08:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [December 10, 2022, 12:27pm UTC](https://forum.dynamobim.com/t/curves-in-cad/83997/5 "2022-12-10T12:27:41Z")

</div>

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]`

---

<div class="post-metadata">

**Author:** ![Omar.Elwan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/omar.elwan/32/127651_2.png) [@Omar.Elwan](https://forum.dynamobim.com/u/Omar.Elwan)\
**Post date:** [December 10, 2022, 1:12pm UTC](https://forum.dynamobim.com/t/curves-in-cad/83997/6 "2022-12-10T13:12:55Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [December 10, 2022, 5:59pm UTC](https://forum.dynamobim.com/t/curves-in-cad/83997/7 "2022-12-10T17:59:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Omar.Elwan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/omar.elwan/32/127651_2.png) [@Omar.Elwan](https://forum.dynamobim.com/u/Omar.Elwan)\
**Post date:** [December 10, 2022, 9:37pm UTC](https://forum.dynamobim.com/t/curves-in-cad/83997/8 "2022-12-10T21:37:51Z")

</div>

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

```auto
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.
