Dynamo for C3D - Get Layer Line Weight

Is there a way to get the line weight of a layer using Dynamo? I see Lineweight List to set the line weight of a layer, but not a way to get the line weight of an existing layer. Is this possible?

Hi @Cadguru42,

As far as I know, there currently isn’t a node to get the lineweight of a layer. However, it is certainly possible! We could write up a quick Python node if you want, otherwise I’ve added it to the to-do list for the next update of the Camber package.

2 Likes

Hi @Cadguru42

Meanwhile, you can try this with python:

# Load the Python Standard and DesignScript Libraries
import clr

# Add Assemblies for AutoCAD and Civil 3D APIs
clr.AddReference('acmgd')
clr.AddReference('acdbmgd')
clr.AddReference('accoremgd')

# Create an alias to the Autodesk.AutoCAD.ApplicationServices.Application class
import Autodesk.AutoCAD.ApplicationServices.Application as acapp

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

adoc = acapp.DocumentManager.MdiActiveDocument

# Ensures list of objects.
toList = lambda x : x if hasattr(x, "__iter__") else [ x ]
# Function
def get_layer_lineweight(layer):
	try:
		out = []
		global adoc
		with adoc.LockDocument():
			with adoc.Database as db:
				with db.TransactionManager.StartTransaction() as t:
					layerTable = t.GetObject(db.LayerTableId, OpenMode.ForRead)
					for r in layer:
						if layerTable.Has(r.Name):
							layerTableRecord = t.GetObject(layerTable[r.Name], OpenMode.ForRead)
							out.append(layerTablRecord.LineWeight)
					t.Commit()
	
	except:
		# if error occurs anywhere in the process catch it
		import traceback
		errorReport = traceback.format_exc()
		out.append(errorReport)
	return out

OUT = get_layer_lineweight(toList(IN[0]))

5 Likes

That helped a lot! However, the output seems to be in MM instead of Inches. My drawing is using Inches for lineweights and the output doesn’t match.

For example, I’m getting an output of LineWeight030 for 0.012", LineWeight025 for 0.01", etc.

@Cadguru42 Is this what you’re trying get?

1 Like

My ultimate goal is to make two functions. One to export the current layers layers to either a CSV or an Excel and the second to make an import layers function. With that line weight PS I was able to export a CSV, but then ran into the issues of having layer descriptions with commas, which of course messes up the CSV. So then I thought I’d just use the ExportExcel, but I’m having trouble with that one. I get a “Warning: Data.ExportExcel operation failed.”

I’m going to look more into the ExportExcel node to see what I’m messing up.

There have been a lot of issues like this. If you search around the forum you’ll probably find more posts, but basically I think the solution is to run a repair on Office 365 or completely uninstall and reinstall.

1 Like

FYI there are nodes for this in Camber v3.0.0.

In which format do we need to provide the lineweight to Layer.SetLineweight?
so far I have tried
0.20
0.20 mm
0.20mm
0.2
and all give “Warning: Invalid Lineweight”.

Even feeding back the output of Layer.Lineweight gives errors.

@Malchert.joly - I would just use the OOTB dropdown node for lineweights so you don’t have to worry about formatting. You’ll see that it is outputting a different string than what is displayed to the user and what you are used to seeing in AutoCAD. This is how the enumeration values look under the hood.

1 Like