Yes, it only works with curves but I don’t know yet any other solution to export on different CAD layers, so I thought it could be worth a look. Here is what’s in the ActiveX.ExportCurvesToAutoCAD node:
poly=RemoveIfNot(CRX, "PolyCurve");
cir=RemoveIfNot(CRX, "Circle");
nur=RemoveIfNot(CRX, "NurbsCurve");
mix=Flatten({cir, nur});
CRV=Flatten({SetDifference(CRX, mix), poly.Curves()});
spt=CRV.StartPoint;
ept=CRV.EndPoint;
mid=CRV.PointAtParameter(0.5);
lin=Line.ByStartPointEndPoint(spt, ept);
arc=Arc.ByThreePoints(spt, mid, ept);
crv=(lin.Length==CRV.Length)?lin:arc;
Flatten({crv, mix});
And the Python code:
#LinkDWG Core DYF by Koz Jono YEOH
#kozmosovia@hotmail.com
#Copyright(C) 1994-2017 KozMos Inc.
#Copyright(C) 2011-2017 Neila Heaven Networks
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
from math import *
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
import System
from System import Array
def _List(xobj):
if hasattr(xobj,"__iter__"):
return xobj
else:
return [xobj]
def _VLOPoint(pt):
return Array[float]([pt.X, pt.Y, pt.Z])
def _MapLayer(lname, lrgb):
rtn=None
CAD.Layers.Add(lname)
for abc in CAD.Layers:
if rtn == None and abc.Name == lname:
rtn = abc
tcc = rtn.TrueColor
tcc.SetRGB(lrgb[0], lrgb[1], lrgb[2])
rtn.TrueColor = tcc
return rtn
rtn=[]
if IN[0] == True:
CAD=System.Runtime.InteropServices.Marshal.GetActiveObject("Autocad.Application").ActiveDocument
_MapLayer(IN[3], IN[4])
if CAD.ActiveSpace == 1:
SPACE = CAD.ModelSpace
else:
SPACE = CAD.PaperSpace
for abc, typ in zip(IN[1], IN[2]):
vlo=None
if typ == "Point":
vlo=SPACE.AddPoint(_VLOPoint(abc))
if typ == "Line":
vlo=SPACE.AddLine(_VLOPoint(abc.StartPoint), _VLOPoint(abc.EndPoint))
if typ == "Circle":
vlo=SPACE.AddCircle(_VLOPoint(abc.CenterPoint), abc.Radius)
if typ == "Arc":
p0=abc.CenterPoint
p1=abc.StartPoint
v1=Vector.ByTwoPoints(p0, p1)
a1=Vector.AngleAboutAxis(v1, Vector.XAxis(), Vector.ZAxis())
a1=a1*-0.017453293
p2=abc.EndPoint
v2=Vector.ByTwoPoints(p0, p2)
a2=Vector.AngleAboutAxis(v2, Vector.XAxis(), Vector.ZAxis())
a2=a2*-0.017453293
vlo=SPACE.AddArc(_VLOPoint(p0), abc.Radius, a1, a2)
if typ == "NurbsCurve":
px=[]
for p0 in abc.ControlPoints():
px.append(p0.X)
px.append(p0.Y)
px.append(p0.Z)
px=Array[float](px)
t0=abc.TangentAtParameter(0)
t0=Array[float]([t0.X, t0.Y, t0.Z])
t1=abc.TangentAtParameter(1)
t1=Array[float]([t1.X, t1.Y, t1.Z])
vlo=SPACE.AddSpline(px, t0, t1)
if vlo != None:
vlo.Layer=IN[3]
rtn.append(vlo)
OUT = rtn