See the top rated post in this thread. Click here

Results 1 to 9 of 9

Thread: Issue with wcmatch xrefs

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Member
    Join Date
    2019-05
    Posts
    15
    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
    Join Date
    2010-06
    Posts
    962
    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
    15
    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
    Join Date
    2010-06
    Posts
    962
    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
    15
    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
    Join Date
    2010-06
    Posts
    962
    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)

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
  •