TheSwamp
CAD Forums => CAD General => Topic started by: NOT SURE on November 26, 2016, 01:32:49 PM
-
Is there a way to assign a material to multiple layers in one action? It's pretty cumbersome having to drag and drop a material to each individual layer.
-
Dang, still no luck with this. I haven't done much programming lately, but I guess I'll have a look see and hopefully find a solution. Basically, I just want to be able to assign a certain material 'bylayer' to any layer that has a key word in the name of the layer.
Howdy, by the way. It's been a while.
-
Perhaps:
(setq mat
"Anodized - Blue-Gray") (setq pat
"*mylayerfilter*") (vl
-catch
-all
-apply 'vla
-put
-material
(list l mat
)) )
)
)
-
Hey there Ron. :-) It's been way too long since I've done any coding, but I see (kinda) where you're going with this. After testing this:
(defun c:Mat2Lay (/ mat pat)
(setq mat "Anodized - Blue-Gray")
(setq pat "Container001 - Left Side")
(vlax-for l (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
(and (wcmatch (strcase (vla-get-name l)) (strcase pat))
(vl-catch-all-apply 'vla-put-material (list l mat))
)
)
(princ)
)
It's still not changing the material. Here's a screen shot of what I'm trying to accomplish:
(https://i.imgur.com/uUbVWc9.jpg)
Also, I tried (setq (entsel)) to grab an object on the target layer, but I'm not sure how to list it's properties, after using View->Inspect like you're showing above in the VLISP editor to see exactly what the material name is. I think not having the proper material name may be throwing it, or at least if not, I can narrow things down a bit.
I appreciate the help tho amigo.
-
I think you need to have the material available in the drawing before it can be assigned ( I may be wrong but this is my observation ).
Use this to see what's available.
(vlax-for m (vla-get-materials (vla-get-activedocument (vlax-get-acad-object)))
(print (vla-get-name m))
)
From my limited testing it's assigning the material to the layer .. then the objects just need to be set to material ByLayer.
Here's a way to add the material:
(vla-add (vla-get-materials (vla-get-activedocument (vlax-get-acad-object))) "American Cherry")
-
That worked like a charm! Thank you! This has been a thorn in my side for working on legacy drawings. Not anymore. I owe you a beer or 12.
Here's what initially worked, but I'll add to it as needed.
(defun c:Mat2Lay (/ mat pat)
(setq mat "Dark Red"); Material must be loaded in dwg
(setq pat "Container*"); Wild card for all layers beginning with 'Container'
(vlax-for l (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
(and (wcmatch (strcase (vla-get-name l)) (strcase pat))
(vl-catch-all-apply 'vla-put-material (list l mat))
)
)
(princ)
)
Thanks again!
-
That worked like a charm! Thank you! This has been a thorn in my side for working on legacy drawings. Not anymore. I owe you a beer or 12.
Here's what initially worked, but I'll add to it as needed.
(defun c:Mat2Lay (/ mat pat)
(setq mat "Dark Red"); Material must be loaded in dwg
(setq pat "Container*"); Wild card for all layers beginning with 'Container'
(vlax-for l (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
(and (wcmatch (strcase (vla-get-name l)) (strcase pat))
(vl-catch-all-apply 'vla-put-material (list l mat))
)
)
(princ)
)
Thanks again!
Glad to help out :) .. I may take you up on the beer offer someday *cheers*.
-
Just say when. :wink:
-
@DeeGeeCees
Why do you use 2 usenames, if I may ask?
-
Dr. J / Mr. H.
-
@DeeGeeCees
Why do you use 2 usenames, if I may ask?
I couldn't log in with my old account. I can log in on my older PC that I used to create the old account, but any new PC I use doesn't recognize the same credentials. *shrug*
Dr. J / Mr. H.
(http://www.cinemastance.com/wp-content/uploads/2016/09/jekyll-and-hyde-lab.jpg)