Linetype & color by Object

I want to achieve the exact opposite mentioned in this thread, namely getting first the Layer styles for Color and Linetype, then transfer these settings to the objects as Object styles. Reason for this is using CAD Links in Revit and maintaining Object styles after Layer Merge in Civil 3D. Revit has a known problem with CAD Links containing many DWG Layers and Linetypes.

This doesn’t seem to hard to do, there is a SetColor node with Object input but I didn’t find any SetLinetype node with Object input, only Layer.

Anyone know how to do this?

This isn’t great, but it works. I didn’t get the Python script to handle sublists in the time that I had - that’s why you have to flatten everything first. Maybe you can make it better.

# Load the Python Standard and DesignScript Libraries
import sys
import clr

# Add Assemblies for AutoCAD and Civil3D

# Import references from AutoCAD
from Autodesk.AutoCAD.Runtime import *
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.EditorInput import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *

# Import references from Civil3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *

adoc = Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor

def set_object_props(handles,linetype):
	if not isinstance(handles,list):
		handles = [handles]
	global adoc
	output = []
	errorReport = None
	count = 0
	with adoc.LockDocument():
		with adoc.Database as db:
			with db.TransactionManager.StartTransaction() as t:
				for handle in handles:
					obj = []
					obj.append(t.GetObject(oid, OpenMode.ForWrite))
						for i in obj:
							i.Linetype = linetype[count]
						import traceback
						errorReport = traceback.format_exc()
	if errorReport == None:
		return output
		return errorReport

OUT = set_object_props(IN[0],IN[1])

Thanks @mzjensen, will have a look at your script. Hope we will get a standard Object.SetLinetype added someday. I managed the lists already in my script and was able to do the colors which is working nicely.

1 Like

I’m noticing an error in the code above. It should be:

i.Linetype = linetype[count]

I’ve edited the post.

1 Like