See the top rated post in this thread. Click here

Results 1 to 9 of 9

Thread: Issue with wcmatch xrefs

  1. #1
    Member
    Join Date
    2019-05
    Posts
    8
    Login to Give a bone
    0

    Default Issue with wcmatch xrefs

    I have some code that is meant to search through xrefs in a drawing, and if it finds one xref with particular text, I'd like to extract some other text from that same xref's name.

    Code:
     (defun C:CUS-PAGE-CONFIG (/ activedocument xrefs xref psetup psize)
    	;
    	(vl-load-com)
    	
    	(setq activedocument (vla-get-activedocument (vlax-get-Acad-Object)))
    	;	
    	(setq xrefs (vla-get-blocks activedocument))
    	;
    	(vlax-for item xrefs								;looking through xrefs 
    	(setq yesxref (vlax-get-property item 'isXref))
    	(if (= yesxref :vlax-true)
    	(setq xref (vlax-get-property item 'Name))
    	);if
    	);vlax-for
    	;
    	(if (wcmatch (strcase xref) "*TBLOCK*")				;if any xref matches TBLOCK then setq psize
    	(setq psize (substr xref 10 2))	    
    	);if
    
    	; ... (rest of code not important)
    
    )
    It seems to work fine for when there is only one xref in the drawing, but as soon as there are more, I'm told "Error: bad argument type: stringp nil".

    Any help would be greatly appreciated.

  2. #2
    All AUGI, all the time Tharwat's Avatar
    Join Date
    2010-06
    Posts
    897
    Login to Give a bone
    0

    Default Re: Issue with wcmatch xrefs

    Hi,
    You have the Xref matches out of the iteration circuit but even though the routine would return only the last subtracted string from the last Xref reference that might match the criteria.

  3. #3
    Member
    Join Date
    2019-05
    Posts
    8
    Login to Give a bone
    0

    Default Re: Issue with wcmatch xrefs

    Thanks for the response!

    Yes, so I guess my question is how should I arrange it so that the routine will look through ALL the xref names and return the one that I am searching for...

  4. #4
    All AUGI, all the time Tharwat's Avatar
    Join Date
    2010-06
    Posts
    897
    Login to Give a bone
    0

    Default Re: Issue with wcmatch xrefs

    Quote Originally Posted by mruu88781911 View Post
    Thanks for the response!

    Yes, so I guess my question is how should I arrange it so that the routine will look through ALL the xref names and return the one that I am searching for...
    You're welcome.

    This is what I meant with my previous reply.
    Code:
    (defun C:CUS-PAGE-CONFIG (/ activedocument xrefs xref psetup psize) ;
      (setq activedocument (vla-get-activedocument (vlax-get-Acad-Object)))
      (setq xrefs (vla-get-blocks activedocument))
      (vlax-for item xrefs                  ;looking through xrefs 
        (setq yesxref (vlax-get-property item 'isXref))
        (if (= yesxref :vlax-true)
          (setq xref (vlax-get-property item 'Name))
        )                                   ;if
        (if (wcmatch (strcase xref) "*TBLOCK*") ;if any xref matches TBLOCK then setq psize
          (setq psize (substr xref 10 2))
        )                                   ;if
      )                                     ; ... (rest of code not important)
    )
    (vl-load-com)

  5. #5
    Member
    Join Date
    2019-05
    Posts
    8
    Login to Give a bone
    0

    Default Re: Issue with wcmatch xrefs

    Quote Originally Posted by Tharwat View Post
    You're welcome.

    This is what I meant with my previous reply.
    Code:
    (defun C:CUS-PAGE-CONFIG (/ activedocument xrefs xref psetup psize) ;
      (setq activedocument (vla-get-activedocument (vlax-get-Acad-Object)))
      (setq xrefs (vla-get-blocks activedocument))
      (vlax-for item xrefs                  ;looking through xrefs 
        (setq yesxref (vlax-get-property item 'isXref))
        (if (= yesxref :vlax-true)
          (setq xref (vlax-get-property item 'Name))
        )                                   ;if
        (if (wcmatch (strcase xref) "*TBLOCK*") ;if any xref matches TBLOCK then setq psize
          (setq psize (substr xref 10 2))
        )                                   ;if
      )                                     ; ... (rest of code not important)
    )
    (vl-load-com)
    Ok so I had actually tried that as you suggested but it stopped it from working all together (multiple xrefs and SINGLE xref too).

    It's weird because it definitely makes more sense but something's preventing it from working...

  6. #6
    All AUGI, all the time Tharwat's Avatar
    Join Date
    2010-06
    Posts
    897
    Login to Give a bone
    0

    Default Re: Issue with wcmatch xrefs

    Hi,
    I have changed the entire code beside that the routine name so please try this instead and let me know.
    NOTE: the return would be as a list if any xref name matched otherwise nil.

    Code:
    (defun c:Test (/ bkn lst)
      (vlax-for item (vla-get-blocks (vla-get-activedocument (vlax-get-Acad-Object)))                 
        (if (and (= (vla-get-isxref item) :vlax-true)
                 (wcmatch (strcase (setq bkn (vla-get-name item))) "*TBLOCK*")
                 (< 9 (strlen bkn))
                 )
          (setq lst (cons (substr bkn 10 2) lst))
          )
        )
      lst
      )
    (vl-load-com)

  7. #7
    Member
    Join Date
    2019-05
    Posts
    8
    Login to Give a bone
    0

    Default Re: Issue with wcmatch xrefs

    Ok that seems to be returning the correct value! However when I incorporate my next line it responds with "Error: bad argument type: stringp ("B1")"

    Code:
    (defun c:Test (/ bkn lst psetup)
      (vlax-for item (vla-get-blocks (vla-get-activedocument (vlax-get-Acad-Object)))                 
        (if (and (= (vla-get-isxref item) :vlax-true)
                 (wcmatch (strcase (setq bkn (vla-get-name item))) "*TBLOCK*")
                 (< 9 (strlen bkn))
                 )
          (setq lst (cons (substr bkn 10 2) lst))
          )
        
    )
    (if (wcmatch (strcase (getvar "dwgname")) "*yy*")
    	 		 (setq 	psetup 	(strcat lst "xxx"))
    				(setq 	psetup 	(strcat lst "zzz"))
    	)
    )
    "lst" is a string isn't it? So it's value can be added to something to make a new string??

  8. #8
    All AUGI, all the time Tharwat's Avatar
    Join Date
    2010-06
    Posts
    897
    Login to Give a bone
    1

    Default Re: Issue with wcmatch xrefs

    The variable 'lst' is a list of strings and not a string and that's why you've received an error because you can't concatenate a list with a string.
    You have another mistake which is the first line while you upper case the drawing name then the compared string is in lower case.

    If the variable 'lst' may contain only one string and you are sure of this, then just use car function to get the string from the list like this:

    Code:
    (car lst)

  9. #9
    Member
    Join Date
    2019-05
    Posts
    8
    Login to Give a bone
    0

    Default Re: Issue with wcmatch xrefs

    Yes! you are right about the lst.

    I got ahold of a sort of a work-around to convert the list into a single string.

    Code:
    (defun :GetAllXrefNames  (/ blk lst)
      (vlax-for blk (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
        (if (eq (vla-get-isXref blk) :vlax-true)
          (setq lst (cons (vla-get-name blk) lst))))
      lst
    )
    
    (defun LM:lst->str ( lst del )      ;CONVERTS LIST STRING TO SINGLE LINE STRING
        (if (cdr lst) 
            (strcat (car lst) del (LM:lst->str (cdr lst) del))
            (car lst) 
        )  
    ) 
    
    ;;;;;;;;
    
    (defun c:PAGE_CONFIG (/ lst)	;TYPE THIS COMMAND HERE	(PAGE_CONFIG)	
    
        (vl-load-com)
    	(vlax-for y (vla-get-plotconfigurations
        (vla-get-activedocument (vlax-get-acad-object)))
    		(if (/= "Model" (vla-get-name y))
    			(vla-delete y)
    		)
        )
    											
      (foreach xname (:GetAllXrefNames)
        (if (wcmatch (strcase xname) "*XXX*")
          (setq lst (cons (substr xname 10 2) lst))
    	)
       )
       
       (if (wcmatch (strcase (getvar "dwgname")) "*ABC*")
    	 		 (setq psetup (strcat (LM:lst->str lst "") "XYZ"))
    				(setq psetup (strcat (LM:lst->str lst "") "ZYX"))
    )

Similar Threads

  1. Problems with wcmatch
    By deheylen690271 in forum AutoLISP
    Replies: 4
    Last Post: 2019-06-13, 12:31 PM
  2. Project Navigator - xrefs? what xrefs?
    By rodg in forum CAD Management - General
    Replies: 0
    Last Post: 2008-11-04, 08:21 AM
  3. Project Navigator - xrefs? what xrefs?
    By rodg in forum CAD Management - General
    Replies: 0
    Last Post: 2008-11-04, 08:20 AM
  4. wildcarding tblobjname BLOCK with wcmatch?
    By mnelson.92099 in forum AutoLISP
    Replies: 1
    Last Post: 2007-12-12, 07:08 PM
  5. XREFS - MSG not xrefs "Not Found"
    By spencer.67965 in forum VBA/COM Interop
    Replies: 0
    Last Post: 2005-01-18, 03:45 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •