Assign material by layer

I am working in autocad and use the file link manager to link my cad files. Since I use architectural objects, I need a script to assign materials to my layers.

I am trying this script without any luck.

(
clearSelection()
$'*3D-concrete'.material = meditMaterials[1]
$'*3D-glass'.material = meditMaterials[2]
$'*3D-brick'.material = meditMaterials[3]
)

What do I do wrong?

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
miauu's picture

*3D-concrete This is the name

*3D-concrete

This is the name of one of your layers?

jesperkl's picture

My layer name is 3D-concrete,

My layer name is 3D-concrete, not *3D-concrete to be precise.

Later I would like to use wildcard like *concrete* to find all layers containing concrete in the layer name.

miauu's picture

.

Try the code below. I hope that you can change it to add your layer names and materials. If you want to use * put it in the names of the layers.

(
	local layersNameAndMatArr = #(#("3D-concrete", meditMaterials[1]), \
		#("*2D-concrete", meditMaterials[2]), \
		#("1D-concrete", meditMaterials[3])	)
 
	for i = 0 to LayerManager.count - 1 do
	(
		local layer = LayerManager.getLayer i
		for j = 1 to layersNameAndMatArr.count do
		(
			if matchPattern layer.name pattern:layersNameAndMatArr[j][1] do
			(
				local theNodes
				layer.nodes &theNodes
				theNodes.material = layersNameAndMatArr[j][2]
			)
		)
	)
)
thdarch's picture

This looks really close to

This looks really close to what we are trying to do: Import geometry from SketchUp, and apply materials by layer name - with a unique set of characters (string) in both the layer name and the material name, such as the last 6 characters of both names. So, a layer in the SketchUp model would end with "CONC01" and this would be assigned the material whose name contains "CONC01".

Actually, if multiple layers could have the same material applied that would be ideal. We would have layers like "front_steps_CONC01" and "porch_footings_CONC01" and they'd both have the material whose name contains "CONC01" applied.

We would have to take care that the material names only had unique strings - that's why the idea of using the last 6 characters came to mind. I haven't begun to look into that sort of text handling in Max Script yet.

I guess, in the sense of "just get it working", it wouldn't be so difficult to just have the layer names and the material names match 1:1.

The script example above is nice and compact, but at my level of knowledge, I'm still a ways from fully understanding how it works to modify it.

jesperkl's picture

Solution :-)

Dear Miauu

It worked just fine. I really appreciate your quick and professionel answer.

All the best.

Jesper

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.