Answers for "get line cad link dynamo revit"

0

get line cad link dynamo revit

import clr
import System
from System.Collections.Generic import *

clr.AddReference("ProtoGeometry")
from Autodesk.DesignScript.Geometry import *

clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference("RevitAPIUI")
from Autodesk.Revit.UI import *

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
view = doc.ActiveView
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

importDWG = IN[1]
nameOfLayersToImport = IN[2]

if isinstance(importDWG, list):
    importDWG = UnwrapElement(importDWG)
else:
    importDWG = UnwrapElement([importDWG])

def GetGeometry(element):
    opt = Options()
    opt.ComputeReferences = True
    opt.IncludeNonVisibleObjects = True
    opt.View = doc.ActiveView
    geometry = element.get_Geometry(opt)
    return [i for i in geometry]
def Flatten(listgeo):
    re = []
    for i in listgeo:
        if len(i) != 0:
            for j in i:
                re.append(j)
        else:
            re.append(i)
    return re
getgeo = Flatten([GetGeometry(i) for i in importDWG])
TransactionManager.Instance.EnsureInTransaction(doc)
for geo_int in getgeo:
    geo_ele = geo_int.GetInstanceGeometry()
    for polyline in geo_ele:
        element = doc.GetElement(polyline.GraphicsStyleId)
        if not element:
            continue
        is_target_layer = element.GraphicsStyleCategory.Name == nameOfLayersToImport
        is_polyline = polyline.GetType().Name == "PolyLine"
        if is_polyline and is_target_layer:
            begin = None
            for pts in polyline.GetCoordinates():
                if not begin:
                    begin = pts
                    continue
                #end = pts
                #line = Line.CreateBound(begin,end)

TransactionManager.Instance.TransactionTaskDone()
OUT = polyline.GetCoordinates()
Posted by: Guest on August-14-2021

Python Answers by Framework

Browse Popular Code Answers by Language