If xrefs+blocks conatin any 1 of 5 values, create a string based on that value

If xrefs+blocks conatin any 1 of 5 values, create a string based on that value

Anonymous
Not applicable
808 Views
4 Replies
Message 1 of 5

If xrefs+blocks conatin any 1 of 5 values, create a string based on that value

Anonymous
Not applicable

Hi there. Basically i'm trying to find the papersize of my drawing by looking through the xrefs+blocks. 

 

; Loop through drawing's xrefs and blocks (until i get a match)
;  
; If match *-A0-* then setq ps "A0"  
; ElseIf *-B1-* then setq ps "B1"
; ElseIf *-A1-* then setq ps "A1"
; ElseIf *-A2-* then setq ps "A2"
; ElseIf *-A3-* then setq ps "A3"
; end if

Excuse the mixture of VBA logic - it's kind of what I'm use to and makes more sense to me. 

I actually did have a code that achieved this, but it involved lists which ended up creating way more problems down the track than it solved 😕

0 Likes
Accepted solutions (1)
809 Views
4 Replies
Replies (4)
Message 2 of 5

dbhunia
Advisor
Advisor

You may try like this...

 

(setq Block_Col (vla-get-blocks (vla-get-ActiveDocument (vlax-get-acad-object))))
(setq BN nil)
(while (setq B (tblnext "block" (null B)))
  (setq BN (cons (cdr (assoc 2 B)) BN))
)
(foreach Name BN
	(setq blk (vl-catch-all-apply 'vla-Item (list Block_Col (strcat Name))))
	;(if (= :vlax-true (vla-get-isxref blk))
		;(progn
			(setq blk_name (vla-get-name blk))
			(if (wcmatch blk_name "*-A0-*") (setq ps "A0")) 
			(if (wcmatch blk_name "*-A1-*") (setq ps "A1")) 
			(if (wcmatch blk_name "*-A2-*") (setq ps "A2")) 
			(if (wcmatch blk_name "*-A3-*") (setq ps "A3")) 
			(if (wcmatch blk_name "*-B1-*") (setq ps "B1")) 
		;)
	;)
)

 

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 3 of 5

Anonymous
Not applicable

Great!! That did it!! Thank you dbhunia

0 Likes
Message 4 of 5

_Tharwat
Advisor
Advisor

Hi,

I think the following is more than enough.

(while (and (setq b (tblnext "block" (not b)))
            (not (vl-some '(lambda (x) (and (wcmatch (cdr (assoc 2 b)) x) (setq ps (substr x 3 2))))
                          '("*-A0-*" "*-A1-*" "*-A2-*" "*-A3-*" "*-B1-*")
                          )
                 )
            )
  )

 

0 Likes
Message 5 of 5

ronjonp
Advisor
Advisor
Accepted solution

I'd use a conditional statement:

(setq ps (cond ((wcmatch blk_name "*-A0-*") "A0")
	       ((wcmatch blk_name "*-A1-*") "A1")
	       ((wcmatch blk_name "*-A2-*") "A2")
	       ((wcmatch blk_name "*-A3-*") "A3")
	       ((wcmatch blk_name "*-A4-*") "A4")
	       ((wcmatch blk_name "*-B1-*") "B1")
	 )
)