Misalignment of CAD lines using different method

Misalignment of CAD lines using different method

hengjiyong
Observer Observer
320 Views
1 Reply
Message 1 of 2

Misalignment of CAD lines using different method

hengjiyong
Observer
Observer

Hello everybody, 

 

First of all, This is my first post on Autodesk forum. 

 

I am trying to achieve extracting line from AutoCAD inside Revit using only RevitAPI. I uses the way shown in the post (link below). However, the lines ended up showing at different location compare to AutoCAD inside Revit.  

https://forums.autodesk.com/t5/revit-api-forum/automatic-column-creation-from-imported-cad-drawing/t...

 

I decided to check the location of curves inside Dynamo, 

First, I converted my Revit lines to Dynamo Lines using Python script

Second, I uses a nodes from BimorphNodes 

 

At the end, I find out that lines from Python script is incorrect and yet BimorphNodes have the same location of AutoCAD shown in Revit.

 

May I know is there anything wrong in my Python script ? 

hengjiyong_0-1631534498342.png

 

Thanks in advance. 

 

Here is my python script:

import clr
import sys
sys.path.append('C:\Program Files (x86)\IronPython 2.7\Lib')
import System
from System import Array
from System.Collections.Generic import *
from System.Collections.Generic import List as netList
clr.AddReference("System.Core")
clr.ImportExtensions(System.Linq)
from System.Linq import Enumerable
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

clr.AddReference("RevitAPI")
clr.AddReference("RevitAPIUI")

import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *
from Autodesk.Revit.Creation import *

clr.AddReference("DSCoreNodes")
from DSCore import *

def toList(input):
if isinstance(input,list) == False:
return [input]
else:
return input

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

#DWG = UnwrapElement(IN[0])
lyrsIds = []

try:
lyrs = DWG.Category.SubCategories.GetEnumerator()
while lyrs.MoveNext():
lyrsIds.append(lyrs.Current.Name)
except:
pass

sel = app.Selection
obj = Selection.ObjectType.Element

class SelectionFilter(Selection.ISelectionFilter):
def __init__(self, e):
self.e = e
def AllowElement(self, e):
if ".dwg" in e.Category.Name:
return True
else:
return False
def AllowReference(self, ref, point):
return False

importInstance = FilteredElementCollector(doc).OfClass(Autodesk.Revit.DB.ImportInstance).WhereElementIsNotElementType().ToElements()

# Create a CAD filter for ISelection
filter = SelectionFilter(".dwg")

## For user to pick that object
CAD_ref = sel.PickObject(obj, filter)

CAD = doc.GetElement(CAD_ref)

CAD = importInstance[1]

CAD = toList(CAD)

## Get all the geometry in CAD and the particular layer both geometry and CAD layer name in parallel list ##
layer_Names = []
lines = []

default_Option = Options()
default_Option.ComputeReferences = False
default_Option.IncludeNonVisibleObjects = False

for c in CAD:
c1 = c.get_Geometry(default_Option)
for a in c1:
c2 = a.GetSymbolGeometry()
for b in c2:
try:
c3 = doc.GetElement(b.GraphicsStyleId).GraphicsStyleCategory.Name
layer_Names.append(c3)
lines.append(b)
except:
layer_Names.append("null")
lines.append(b)

## Get the particular CAD layer geometry, according to the stated layer name
rec_Column_Cad_lines = []

layer_Name = "C1"#"S-COL-GF"

for lay, l in zip(layer_Names, lines):
if lay == layer_Name:
try:
rec_Column_Cad_lines.append(l.GetCoordinates())
except:
continue

ha = []
for h in lines:
try:
ha.append(h.ToProtoType())
except:
continue

OUT = ha

0 Likes
321 Views
1 Reply
Reply (1)
Message 2 of 2

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @hengjiyong ,

 

I think it is better to ask Revit dynamo-related questions in the Dynamo forum.

https://forum.dynamobim.com/c/revit/12 

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes