hemuni Posted September 5, 2018 Posted September 5, 2018 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) "")) ) ) ;;; ) ;;; ) ) Quote
Tharwat Posted September 5, 2018 Posted September 5, 2018 Just un-comment the codes and you are there. Quote
rlx Posted September 5, 2018 Posted September 5, 2018 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) Quote
Tharwat Posted September 5, 2018 Posted September 5, 2018 8 minutes ago, rlx said: only I would add a ')' at the end of (/= :vlax-true (vla-get-isxref n) Oops, You're right. Quote
rlx Posted September 5, 2018 Posted September 5, 2018 13 minutes ago, Tharwat said: Oops, You're right. 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 Quote
Tharwat Posted September 5, 2018 Posted September 5, 2018 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 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. Quote
rlx Posted September 5, 2018 Posted September 5, 2018 (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 September 6, 2018 by rlx Quote
Tharwat Posted September 5, 2018 Posted September 5, 2018 The regex is a big ocean that you can dive in when you start using any of the .NET programming languages. Quote
ronjonp Posted September 5, 2018 Posted September 5, 2018 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) "")) ) Quote
MBrynildsen Posted November 25, 2019 Posted November 25, 2019 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. Quote
Tharwat Posted November 25, 2019 Posted November 25, 2019 35 minutes ago, MBrynildsen said: 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. Read the DXF Group 70 in the following link: http://help.autodesk.com/view/OARX/2019/ENU/?guid=GUID-66D32572-005A-4E23-8B8B-8726E8C14302 Quote
Recommended Posts
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.