PDA

View Full Version : renaming autocad layers


em3
01-28-2009, 10:05 PM
I am very new to maxscript and am trying to write a simple script that will automatically place materials on certain objects. It seems I am having a problem. It works sometimes on some objects but not on others. When I rename the layers to something else, it always works.

Here is the code:


myWeld = 15
for i = 1 to objects.count do
(
if objects[i].name == "Layer:Level 10" do
(
clearSelection()
select #($'Layer:Level 10')
$.material = meditMaterials[2]
macros.run "Modifier Stack" "Convert_to_Poly"
)
if objects[i].name == "Layer:Level 9" do
(
clearSelection()
select #($'Layer:Level 9')
$.material = meditMaterials[3]
macros.run "Modifier Stack" "Convert_to_Poly"
)
)


In this case, layer 10 will do the operation, Layer nine will be ignored. Does anyone else have this problem?

PiXeL_MoNKeY
01-28-2009, 10:28 PM
So you have objects named Layer:Level 10 and Layer:Level 9? Also is that exactly the names or just close?

-Eric

em3
01-29-2009, 01:57 AM
The names of the objects and the names of the layers are the same. Layer 9 seems to be the one that doesn't work. So Layer 8 works, Layer 10 works, but layer 9 doesn't. It's this way with all the drawings. Problem is I can't automatically rename it because of the same problem. Maybe I should try a find and replace of the ":" as its likely this is the cause of the problem?

PiXeL_MoNKeY
01-29-2009, 02:03 AM
Have you verified that the Layer:Layer 9 object is convertable to a Poly object? Can you post a simple file that shows the problem?

-Eric

em3
01-29-2009, 02:08 AM
yeah sure thing. I dont have it here so I will have to post the file when I get to work tomorrow. Thanks dude!

em3
01-29-2009, 02:58 PM
for i = 1 to objects.count do
(
if objects[i].name == "Layer:Level 13" do
(
clearSelection()
select #($'Layer:Level 13')
$.material = meditMaterials[1]
)
if objects[i].name == "Layer:Level 3" do
(
clearSelection()
select $'Layer:Level 3'
$.material = meditMaterials[2]
)
)


test scene is at http://www.treadster.com/test.max

Thanks!!

Zbuffer
01-30-2009, 08:17 AM
Hi,


try this:
(
Objs = for o in objects collect o

for o in Objs do
(
if o.name == "Layer:Level 13" do
(
o.material = meditMaterials[1]
ConvertTo o Editable_Poly
)
if o.name == "Layer:Level 3" do
(
o.material = meditMaterials[2]
ConvertTo o Editable_Poly
)
)
)

em3
01-30-2009, 02:55 PM
Thanks for that Zbuffer, is there a "Like" or "Contains" operator in maxscript?

em3
01-30-2009, 05:17 PM
I found the apropos() object instpector function I ran this but it appears to be in an endless loop...


(
Objs = for o in objects collect o

for o in Objs do
(
if o.name == apropos "?HP?" do
(
o.material = meditMaterials[1]
ConvertTo o Editable_Poly
)
if o.name == apropos "?LP?"
do
(
o.material = meditMaterials[2]
ConvertTo o Editable_Poly
)
)
)

ZeBoxx2
01-30-2009, 05:25 PM
apropos is definitely not what you're looking for - apropos exposes classes and the like to, say, a coder.

You might want to look into...
- findString (finds a specific string within another string, returns position if found, undefined otherwise )
- matchPattern (checks whether a specific string matches a wildcarded string (? and * wildcards), returns true/false )
- regex matching (see threads in this forum; requires .NET)

Piflik
01-30-2009, 05:36 PM
Wouldn't a case expression be a tad cleaner instead of that many if expressions?

Zbuffer
01-30-2009, 06:15 PM
Hi,
What you are looking for is the matchpattern function. Look it up the maxscript help
if matchpattern o.name pattern:"*LP*" do (...something...)

em3
01-30-2009, 07:45 PM
That's it!!

Thanks for all your help guys (and gals?)

final script:


(
Objs = for o in objects collect o

for o in Objs do
(
if matchpattern o.name pattern:"*LP*" do
(
o.material = meditMaterials[1]
ConvertTo o Editable_Poly
)
if matchpattern o.name pattern:"*HP*" do
(
o.material = meditMaterials[2]
ConvertTo o Editable_Poly
)
)
)

CGTalk Moderation
01-30-2009, 07:45 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.