YZ Posted September 6, 2016 Posted September 6, 2016 My blocks have a prefix, "SYMBOL_" when coming from third party software. Would someone kindly give me a head start on how I could learn to remove that prefix on any instance of a block that has that prefix? For example, these blocknames SYMBOL_PP SYMBOL_SMH SYMBOL_TREE become PP SMH TREE Quote
Tharwat Posted September 6, 2016 Posted September 6, 2016 Hi, Try this program; (defun c:test ( / name new ) ;; Tharwat - 06.Sep.2016 ;; (vlax-for blk (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) (and (= :vlax-false (vla-get-isxref blk)) (= :vlax-false (vla-get-islayout blk)) (wcmatch (setq name (vla-get-name blk)) "SYMBOL_*") (not (tblsearch "BLOCK" (setq new (substr name ))) (vla-put-name blk new)) ) (princ) )(vl-load-com) Quote
steven-g Posted September 6, 2016 Posted September 6, 2016 Or you could do it the hard way. Use the rename command old name "SYMBOL_*" new name "*" Quote
BIGAL Posted September 7, 2016 Posted September 7, 2016 I 2nd Steven-g idea -rename will run as command line no dialouge very quick. Tharwat nice code, only problem "substr name 8" this is ok for hard code SYMBOL_ maybe version 2 ask for prefix, I have a PM from YZ so know that YZ will require other block name like 15 character prefix. Maybe ver 2A use a list. If I can find time will incorporate your code Tharwat into a more eleborate multi function clean up to suit the 3rd party output as per other YZ questions. Once done will post here for others. Quote
Tharwat Posted September 7, 2016 Posted September 7, 2016 BIGAL, please don't modify my codes for any reason and just write your own codes. Quote
YZ Posted September 13, 2016 Author Posted September 13, 2016 Hi, Try this program; (defun c:test ( / name new ) ;; Tharwat - 06.Sep.2016 ;; (vlax-for blk (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) (and (= :vlax-false (vla-get-isxref blk)) (= :vlax-false (vla-get-islayout blk)) (wcmatch (setq name (vla-get-name blk)) "SYMBOL_*") (not (tblsearch "BLOCK" (setq new (substr name ))) (vla-put-name blk new)) ) (princ) )(vl-load-com) Hi Tharwat, that works! Thanks for taking the time. My colleague and I are getting better at reading LISP, so I can actually follow along with this one. Quote
YZ Posted September 13, 2016 Author Posted September 13, 2016 Or you could do it the hard way. Use the rename commandold name "SYMBOL_*" new name "*" Yes, I was actually working on an old fashioned one. The problem is that if a different symbol was ever part of the file then a macro could not cope with it. Because the -rename command cannot use wildcards, only the dialog box can use wildcards. Still, last week I decided to write a macro that did each of our standard symbols one at a time. But that was because I'd tried writing a lisp but could not solve the logic myself. Quote
Tharwat Posted September 13, 2016 Posted September 13, 2016 Hi Tharwat, that works! Thanks for taking the time. My colleague and I are getting better at reading LISP, so I can actually follow along with this one. You are most welcome. Happy to help. Quote
Kvlar Posted June 15, 2024 Posted June 15, 2024 On 9/6/2016 at 3:07 PM, Tharwat said: Hi, Try this program; (defun c:test ( / name new ) ;; Tharwat - 06.Sep.2016 ;; (vlax-for blk (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) (and (= :vlax-false (vla-get-isxref blk)) (= :vlax-false (vla-get-islayout blk)) (wcmatch (setq name (vla-get-name blk)) "SYMBOL_*") (not (tblsearch "BLOCK" (setq new (substr name ))) (vla-put-name blk new)) ) (princ) )(vl-load-com) I tried this code in 2024. I got an error like this: ; error: too few arguments Did I make a mistake or does this code really not work anymore? Thank You 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.