Change Layer Transparency in Autocad File

I am trying to update layer transparency values through Dynamo in Civil 3D 2020. I also was updating other values like color or line type and did not experience any problems.

According to docs (https://help.autodesk.com/view/OARX/2020/ENU/?guid=OARX-ManagedRefGuide-Autodesk_AutoCAD_Colors_Transparency_Transparency_byte), transparency can be created with byte value.

When I am using Transparency(b’50’ or bytes(50)) I get a warning “TypeError: expected Byte, got bytes”.
When insert normal int value like Transparency(50) I get “Cannot convert numeric value 50 to TransparencyMethod. The value must be zero.” I don’t get any error with zero, but obviously the point is to introduce my own values, not zero.

def set_layer_transparency(layer, layerTransparency):
	
	global adoc
	with adoc.LockDocument():
		with adoc.Database as db:
			with db.TransactionManager.StartTransaction() as t:
			
				_layerTable = t.GetObject(db.LayerTableId, OpenMode.ForRead)
				
				if _layerTable.Has(layer.Name):
					_layerTableRecord = t.GetObject(_layerTable[layer.Name], OpenMode.ForWrite)
					
					# Amend layer transparency
					_layerTableRecord.Transparency = Transparency(b'50')

				t.Commit()

	return _layerTableRecord

try

Transparency (0x50)

for decimal 80

oh… I see you are using python -

3 Likes

Thanks!

I have also tried Byte, however then I get a message “NameError: global name ‘Byte’ is not defined”. However, for some reason, I now tried only with mapping the number:

alpha = 255 * (100 - transparency) / 100
_layerTableRecord.Transparency = Transparency(alpha)

If I take any of the values that alpha returns (let’s say 50), and put Transparency(50) it still does not work. But I guess it needs to be passed as a double-precision number and then it’s not complaining about byte format.

Hi @lunajs

Could you drop your complete python here?