Use lisp to get material name ??

Use lisp to get material name ??

Anonymous
Not applicable
1,952 Views
5 Replies
Message 1 of 6

Use lisp to get material name ??

Anonymous
Not applicable

i need help. i use autodesk autocad 2016

 

I have a 3d solid , Solid type = Box, i use command  CMATERIAL  and  chose material name is "Layer_M7" ( i have this material in my drawing)  i  use command  MATERIALASSIGN  to assingn this meterial to my box ;     then  i type  CMATERIAL  again and  chose material name is "Layer_M2" i  use command  MATERIALASSIGN  to assingn this meterial to one face of this box ( a box have 6 face).

when i  type    LIST command and chose this Box, i have a result .

Command: LIST

Select objects: 1 found

Select objects:

                  3DSOLID   Layer: "bemat"

                            Space: Model space

                    Material: Layer_M7

                   Handle = af4

   Face1 Material = Layer_M2

         History = None

    Show History = No

   Bounding Box: Lower Bound X = -27.8004 , Y = 31.6771  , Z = 0.0000

                 Upper Bound X = 78.9335  , Y = 138.3119 , Z = 202.3191

 

My problem is :  i want to get  the material name by lisp, include  Material:Layer_M7 and  Face1 Material = Layer_M2.

I have  used  this code :

(vl-load-com)

(defun c:getmaterialname ()

    (setq acadObj (vlax-get-acad-object))

    (setq doc (vla-get-ActiveDocument acadObj))

(setq K (Ssget))    

(setq textObj (ssname K  0))

(setq textObj  (vlax-ename->vla-object textObj))

(setq m1

(VLA-GET-material textObj))

(alert m1)

)

 

It  is Ok , but  it get  the name    Material: Layer_M7 only;    

i want to use Autolisp to get  Face1 Material in that box,  could anyone help me? Thanks  alot.

0 Likes
Accepted solutions (3)
1,953 Views
5 Replies
Replies (5)
Message 2 of 6

Ranjit_Singh
Advisor
Advisor
Accepted solution

Try below code. Tested for a very simple case

;;Ranjit Singh
;;6/19/17
(defun c:somefunc (/ ent etdata) (mapcar 'print (cons (vla-get-material (vlax-ename->vla-object (setq ent (car (entsel))))) (vl-remove nil (mapcar '(lambda (x) (and (= "MATERIAL" (cdr (assoc 0 (setq etdata (entget (cdr (assoc 331 (entget (cdr x)))))))))) (cdr (assoc 1 etdata))) (cdr (vl-remove-if-not '(lambda (x) (= 360 (car x))) (entget (cdr (assoc 360 (entget (cdr (assoc 350 (entget ent))))))))))))) (princ))
Message 3 of 6

Anonymous
Not applicable
Accepted solution

 

 

Command: LIST

Select objects: 1 found

Select objects:

                  3DSOLID   Layer: "bemat"

                            Space: Model space

                    Material: Layer_M7

                   Handle = af4

   Face1 Material = Layer_M2

         History = None

    Show History = No

   Bounding Box: Lower Bound X = -27.8004 , Y = 31.6771  , Z = 0.0000

                 Upper Bound X = 78.9335  , Y = 138.3119 , Z = 202.3191

 

 

Thank you Ranjit Singh   but your code get only the main Material , i want to get the Face1 Material , Could you give me another code to get it?

 

0 Likes
Message 4 of 6

Ranjit_Singh
Advisor
Advisor
Accepted solution

It works for me. What error do you get? Do a screencast to describe better the results. It will help if you post a drawing.Material_List.gif

Message 5 of 6

Anonymous
Not applicable

I try but it is not work, is there a problem?

0 Likes
Message 6 of 6

Anonymous
Not applicable

i sent you a my drawing  and  a screencast, it show how to i assing the material to my box, and show the lisp do not work completly.  (I hold crt key to select and assing  material to face of box. and you also use command "Materialassign" to assign  material to box and face of box . )

0 Likes