Author Topic: Materials in AutoCAD 2017 Vanilla  (Read 4173 times)

0 Members and 1 Guest are viewing this topic.

NOT SURE

  • Guest
Materials in AutoCAD 2017 Vanilla
« 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.

DeeGeeCees_V.2.0

  • Newt
  • Posts: 154
Re: Materials in AutoCAD 2017 Vanilla
« Reply #1 on: February 28, 2018, 11:00:57 AM »
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.

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Materials in AutoCAD 2017 Vanilla
« Reply #2 on: February 28, 2018, 01:22:01 PM »
Perhaps:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ mat pat)
  2.   (setq mat "Anodized - Blue-Gray")
  3.   (setq pat "*mylayerfilter*")
  4.     (and (wcmatch (strcase (vla-get-name l)) (strcase pat))
  5.     (vl-catch-all-apply 'vla-put-material (list l mat))
  6.     )
  7.   )
  8.   (princ)
  9. )

« Last Edit: February 28, 2018, 01:25:02 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

DeeGeeCees_V.2.0

  • Newt
  • Posts: 154
Re: Materials in AutoCAD 2017 Vanilla
« Reply #3 on: February 28, 2018, 02:35:18 PM »
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:

Code: [Select]
(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:



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.

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Materials in AutoCAD 2017 Vanilla
« Reply #4 on: February 28, 2018, 03:18:00 PM »
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.
Code: [Select]
(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:
Code: [Select]
(vla-add (vla-get-materials (vla-get-activedocument (vlax-get-acad-object))) "American Cherry")

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

DeeGeeCees_V.2.0

  • Newt
  • Posts: 154
Re: Materials in AutoCAD 2017 Vanilla
« Reply #5 on: February 28, 2018, 03:57:15 PM »
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.

Code: [Select]
(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!

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Materials in AutoCAD 2017 Vanilla
« Reply #6 on: February 28, 2018, 04:28:01 PM »
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.

Code: [Select]
(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*.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

DeeGeeCees_V.2.0

  • Newt
  • Posts: 154
Re: Materials in AutoCAD 2017 Vanilla
« Reply #7 on: March 01, 2018, 08:36:11 AM »
Just say when.  :wink:

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Materials in AutoCAD 2017 Vanilla
« Reply #8 on: March 01, 2018, 09:21:12 AM »
@DeeGeeCees
Why do you use 2 usenames, if I may ask?
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Materials in AutoCAD 2017 Vanilla
« Reply #9 on: March 01, 2018, 09:41:40 AM »
Dr. J / Mr. H.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

DeeGeeCees_V.2.0

  • Newt
  • Posts: 154
Re: Materials in AutoCAD 2017 Vanilla
« Reply #10 on: March 01, 2018, 10:27:01 AM »
@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.