Jump to content

Lisp to strip a prefix out of block names?


YZ

Recommended Posts

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

Link to comment
Share on other sites

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)
         

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Or you could do it the hard way. Use the rename command

old 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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 7 years later...
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

 

Link to comment
Share on other sites

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...