Hello friends. I just started to get acquainted and learn Python Script, hope you guys can help me answer this problem. I try to draw line from Autocad Layer, for example i have 3 shapes with layer name 0, when i draw line from layer 0 this can only make 1 shape, is there any way i can draw line for 3 shapes is the class name 0 or not? Hope you can help. Thanks very much
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 *
import collections
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
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
importDWG = UnwrapElement(IN[1])
nameOfLayersToImport = IN[2]
def tolist(object):
if hasattr(object, "__init__"):
return [object]
else:
return object
Tolist = tolist(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]
getgeo = [GetGeometry(i) for i in Tolist]
def Flatten(listelement):
if isinstance(listelement, collections.Iterable):
return [element for elements in listelement for element in Flatten(elements)]
else:
return [listelement]
flattenlist = Flatten(getgeo)
def CreateLine(getgeo):
Points = []
for geo_int in getgeo:
geo_ele = geo_int.GetInstanceGeometry()
for polyline in geo_ele:
element = doc.GetElement(polyline.GraphicsStyleId)
is_target_layer = element.GraphicsStyleCategory.Name == nameOfLayersToImport
is_polyline = polyline.GetType().Name == "PolyLine"
if is_polyline and is_target_layer:
pts = polyline.GetCoordinates()
for p in pts:
Points.append(p.ToPoint())
line = []
for i in range(len(pts)):
while (i< len(pts)-1):
l = Line.CreateBound(pts[i],pts[i+1])
line.append(l)
break
return [i.ToProtoType() for i in line]
TransactionManager.Instance.EnsureInTransaction(doc)
cre = CreateLine(flattenlist)
TransactionManager.Instance.TransactionTaskDone()
OUT = cre