Error when adding a wcmatch to a conditional inside a loop

Error when adding a wcmatch to a conditional inside a loop

TaytaRuiz
Participant Participant
582 Views
6 Replies
Message 1 of 7

Error when adding a wcmatch to a conditional inside a loop

TaytaRuiz
Participant
Participant

Hello everyone,

 

I have been using a functioning LISP that turns all the SOLID hatches to a specific hatch. Now I wanted to add a conditional filter for layers with 

 

(wcmatch (vla-get-layer x) "*MASS*")

 

but I only obtain errors.

 

The two codes that I tried in AutoCAD 2021 and that return "nil" results are below. In the first I added it in line 5 and in the second in line 7:

 

(defun c:hdwsol2was ( / doc )
   (vlax-for blk (vla-get-blocks (setq doc (vla-get-activedocument (vlax-get-acad-object))))
       (if (= :vlax-false (vla-get-isxref blk))
           (vlax-for obj blk
               (if 
                   (and
                       (wcmatch (vla-get-layer x) "*MASS*")
                       (= "AcDbHatch" (vla-get-objectname obj))
                       (= "SOLID" (strcase (vla-get-patternname obj)))
                       (vlax-write-enabled-p obj)
                   )
                   (progn
                       (vla-setpattern obj achatchpatterntypepredefined "CORK")
                       (vla-put-patternscale obj 50)
                   )
               )
           )
       )
   )
   (vla-regen doc acallviewports)
   (princ)
)
(vl-load-com) (princ)

 

 

 

(defun c:hdwsol2was ( / doc )
   (vlax-for blk (vla-get-blocks (setq doc (vla-get-activedocument (vlax-get-acad-object))))
       (if (= :vlax-false (vla-get-isxref blk))
           (vlax-for obj blk
               (if (wcmatch (vla-get-layer x) "*MASS*")
                   (and
                       (= "AcDbHatch" (vla-get-objectname obj))
                       (= "SOLID" (strcase (vla-get-patternname obj)))
                       (vlax-write-enabled-p obj)
                   )
                   (progn
                       (vla-setpattern obj achatchpatterntypepredefined "CORK")
                       (vla-put-patternscale obj 50)
                   )
               )
           )
       )
   )
   (vla-regen doc acallviewports)
   (princ)
)
(vl-load-com) (princ)

 

 

I'd appreciate it if anyone could point to my error.

 

Thank you.

Eloy

0 Likes
Accepted solutions (2)
583 Views
6 Replies
Replies (6)
Message 2 of 7

ВeekeeCZ
Consultant
Consultant
Accepted solution

get layer of ??

0 Likes
Message 3 of 7

hak_vz
Advisor
Advisor
Accepted solution
(wcmatch (vla-get-layer x) "*MASS*")

It should stand

(wcmatch (vla-get-layer obj) "*MASS*")

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 4 of 7

TaytaRuiz
Participant
Participant

Thank you both,
I changed it and now the first variant does what I want, but not the second.
In my head they mean the same, so I'd assume that I still have some reading to do about conditionals and loops.

(defun c:hdwsol2was ( / doc )
   (vlax-for blk (vla-get-blocks (setq doc (vla-get-activedocument (vlax-get-acad-object))))
       (if (= :vlax-false (vla-get-isxref blk))
           (vlax-for obj blk
               (if 
                   (and
				       (wcmatch (vla-get-layer obj) "*MASS*")
                       (= "AcDbHatch" (vla-get-objectname obj))
                       (= "SOLID" (strcase (vla-get-patternname obj)))
                       (vlax-write-enabled-p obj)
                   )
                   (progn
                       (vla-setpattern obj achatchpatterntypepredefined "net3")
                       (vla-put-patternscale obj 50)
                   )
               )
           )
       )
   )
   (vla-regen doc acallviewports)
   (princ)
)
(vl-load-com) (princ)

 
Cheers

0 Likes
Message 5 of 7

ВeekeeCZ
Consultant
Consultant

Well, it should. Post a dwg sample that gives you the error.

0 Likes
Message 6 of 7

hak_vz
Advisor
Advisor

@TaytaRuiz 

 

Code works as it should. Create solid pattern objects in layer *mass* (it has mass in its name) and convert to block.

Run code and it changes block pattern to net3

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 7 of 7

Sea-Haven
Mentor
Mentor

Is it non Autocad may need "NET3" agree works.

0 Likes