I have 30 blocks per drawing about 60 drawings. Each block starts with the jobname has other block info and then the block type. For example
Bldg31-MechEquip_ABC
Bldg33-MechText_DEF
Bldg45-ElecEquip_GHI
I want the output to be just ABC, DEF, and GHI.
I have a rename script but I dont know where to go from here. How can I tell it to remove everything up and including the "_" symbol?
Thanks!
Solved! Go to Solution.
Solved by pbejse. Go to Solution.
@Anonymous wrote:...
Bldg31-MechEquip_ABC
Bldg33-MechText_DEF
Bldg45-ElecEquip_GHI
I want the output to be just ABC, DEF, and GHI.
...
(defun c:renb (/ i a m p be) (while (setq a (tblnext "block" (not a))) (if (and (not (= 4 (logand 4 (cdr (assoc 70 (tblsearch "BLOCK" (setq m (cdr (assoc 2 a)))) ) ) ) ) ) (setq p (vl-string-position 95 m)) ) (command "_.rename" "block" m (if (tblsearch "BLOCK" (setq b (substr m (+ 2 p)))) (progn (setq i 0) (while (tblsearch "block" (strcat b (itoa (setq i (1+ i))))) ) (strcat b (itoa i)) ) b ) ) ) ) (princ) )
HTH
Wow, thanks it works exactly as I need.
What line is it referencing the character "_". Just out of curiosity, if I wanted to use this script for another application where I wanted to delete everything upto and including a different character like "-" or the series of letters "ab" instead of "_" character, where would I change this in the script. I was reviewing the code expecting something like "_" that I could just replace with another character if needed but this script is above my understanding.
@Anonymous wrote:....
What line is it referencing the character "_". Just out of curiosity, if I wanted to use ... a different character like "-" or the series of letters "ab" instead of "_" character, where would I change this ....
I don't mean to "steal" the opportunity to reply from pbejse, but here I am with a few minutes....
It's this that's finding the _ character:
(vl-string-position 95 m)
That function takes an ASCII character code. You could do the same with a different function, quoting the actual character [or more than one, e.g. your "ab"]:
(vl-string-search "_" m)
Look into those two functions, plus (ascii) and (char) if you want to find out what the code is for a given character [e.g. your "-"].
@Kent1Cooper wrote:
......I don't mean to "steal" the opportunity to reply from pbejse, but here I am with a few minutes....
.... , quoting the actual character [or more than one, e.g. your "ab"]:
(vl-string-search "_" m)...
No offense taken , Your input is always welcome kent.
i agree, vl-string-search it is.
@Anonymous wrote:Wow, thanks it works exactly as I need.
Just out of curiosity, if I wanted to use this script for another application where I wanted to delete everything upto and including a different character like "-" or the series of letters "ab" instead of "_" character, ..
Try this code:
(defun c:renb (/ i a m p be) (vl-load-com) (setq ch (getstring "\nEnter Character(s) to Find: ")) (if (eq ch "") (princ "\Invalid character") (while (setq a (tblnext "block" (not a))) (if (and (not (= 4 (logand 4 (cdr (assoc 70 (tblsearch "BLOCK" (setq m (cdr (assoc 2 a)))) ) ) ) ) ) (setq p (vl-string-search (strcase ch)(strcase m))) ) (command "_.rename" "block" m (if (tblsearch "BLOCK" (setq b (substr m (+ 1 (strlen ch) p)))) (progn (setq i 0) (while (tblsearch "block" (strcat b (itoa (setq i (1+ i))))) ) (strcat b (itoa i)) ) b ) ) ) ) ) (princ) )
command: Renb
Enter Character(s) to Find: _
command: Renb
Enter Character(s) to Find: ab
HTH
@Kent1Cooper wrote:
....
Look into those two functions, plus (ascii) and (char) if you want to find out what the code is for a given character [e.g. your "-"].
Oops -- make that (chr).
Can't find what you're looking for? Ask the community or share your knowledge.