Export Parameter Values as DWG Layers

Hey all,

Is it possible to export a Revit model to an AutoCAD DWG and import parameter values as object layers?

I made a shared parameter for Parts called Pour ID, and I’m looking to make a new layer for each unique Pour ID value.

With the packages I have installed (Bumblebee, Grimshaw, Clockwork, LunchBox, Rhythm, Springs, and SteamNodes) I do not have a node that looks like it gives me any sort of options. The only one I see that might work would be Tool.ExportDWF from SteamNodes, but getting from a DWF to a DWG isn’t a great option.

Cheers!

The best suggestion I could think of would be to use Dynamo to create view specific graphic overrides for each element based on the Pour ID, then export your DWGs with “Export layer options:” set to “Export all properties BYLAYER, and create new layers for overrides”. This will create a new layer for each element that has graphic overrides, but I don’t think you would have much control over the layer naming :thinking:

1 Like

This thread could also bring additional ideas:

1 Like

@Yna_Db I thought about that LinkDWG node, but it seems @cnealy is exporting 3D views and that node needs curve inputs… I suppose it could work by getting the geometry of the elements in the 3D views as curves first :thinking:

1 Like

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
1 Like

Another suitable option would be the View.ExportDWG node from Chynamo but I am not sure it will not only export separate files. Maybe a combination of both could lead to something interesting…

import clr
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

import System
from System.Collections.Generic import *

import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)

def _ExportDwg(xfolder, xview):
	options = DWGExportOptions()
	views = List[ElementId]()
	id=ElementId(xview.Id)
	views.Add(id)
	xname="Export-" + xview.Name + ".DWG"
	try:
		rtn = DOC.Export(xfolder, xname, views, options)
	except: 
		rtn=None
	return rtn

XFOLDER = IN[1]
XVIEW = IN[2]
DOC = DocumentManager.Instance.CurrentDBDocument
rtn = "Export DWGs failed"

if IN[0] == True:
	for abc in XVIEW:
		try:
			rtn = _ExportDwg(XFOLDER, abc)
			rtn = "Export DWGs successful"
		except:
			rtn = "Export DWGs failed"

OUT=rtn