Jump to content

Need help filtering out xrefs from vla-get-blocks


Recommended Posts

Posted

I found this cool way of using regular expressions to search and replace text (sorry don't remember the source).

I want to use it to seek out a specific text string and replace it with an empty string to effectively delete it from the drawing, but I have run into a problem.

The code also seaches and replaces inside xrefs and I would like to avoid that, but I haven't been able to figure out how.

Is there a way to have vla-get-blocks skip external references or to filter them out after?

 

  ;remove any and all instances of NOT FOR CONSTRUCTION
  (setq regex (vlax-get-or-create-object "VBScript.RegExp"))
  (vlax-put-property regex 'global actrue)
  (vlax-put-property regex 'ignorecase actrue)
  (vlax-put-property regex 'multiline actrue)
  (vlax-put-property regex 'pattern "NOT FOR CONSTRUCTION")
  (vlax-for n (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
;;;    (if
;;;      (/= :vlax-true (vla-get-isxref n)
        (vlax-for m n
      (if (member (vla-get-objectname m) '("AcDbMtext" "AcDbText"))
        (vla-put-textstring m (vlax-invoke regex 'replace (vla-get-textstring m) ""))
      )
    )
;;;      )
;;;    )
  )
 

Posted
9 minutes ago, Tharwat said:

Just un-comment the codes and you are there. ;) 

only I would add a ')' at the end of

 (/= :vlax-true (vla-get-isxref n) 

😉

Posted
8 minutes ago, rlx said:

only I would add a ')' at the end of


 (/= :vlax-true (vla-get-isxref n) 

😉

Oops, You're right. :thumbsup: 

Posted
13 minutes ago, Tharwat said:

Oops, You're right. :thumbsup: 

 

no problem... just looked at this code and I suddenly realized this can save me a lot of coding. Its the same engine Lee uses in his batch editor and I new about it for years but never implemented it.. until now. So also thanx to OP for turning the light on :idea:

Posted
4 minutes ago, rlx said:

 

no problem... just looked at this code and I suddenly realized this can save me a lot of coding. Its the same engine Lee uses in his batch editor and I new about it for years but never implemented it.. until now. So also thanx to OP for turning the light on :idea:

I am really surprised that you did not use this expression that related to xref with the iteration on blocks table.

Its used a lot and specifically it depends on your goal of the codes if you would like to ignore or target the Xref block definition.

For me, I would prefer to use the :vlaxfalse against the <vla-object> and not to use <not equal> /=  to true as the OP demonstrated or posted.

Posted (edited)
21 hours ago, Tharwat said:

I am really surprised that you did not use this expression that related to xref with the iteration on blocks table.

Its used a lot and specifically it depends on your goal of the codes if you would like to ignore or target the Xref block definition.

For me, I would prefer to use the :vlaxfalse against the <vla-object> and not to use <not equal> /=  to true as the OP demonstrated or posted.

 

I actually use :vlax-false too.  😁    But I wasn't talking about the xref part but the regex part. Have a lot of vanilla code , still going strong if I may say so myself and also handy when batching with AutoCAD Core Console. But some apps will never be using the core , so time to do some upgrading (if I can find the time to do it)

Edited by rlx
Posted

The regex is a big ocean that you can dive in when you start using any of the .NET programming languages. ;) 

Posted

FWIW, you might also want to check if the object can be modified:

(if (and (vlax-write-enabled-p m) (member (vla-get-objectname m) '("AcDbMtext" "AcDbText")))
  (vla-put-textstring m (vlax-invoke regex 'replace (vla-get-textstring m) ""))
)

 

  • 1 year later...
Posted

Can some one tell me how to identify if an existing xref is "Overlay" or "Attached" using visual lisp?  I need to have my code bypass any "Attached" xrefs.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...