TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: CADaver on September 11, 2004, 06:01:13 PM

Title: Extracting XREF strings after the "|"
Post by: CADaver on September 11, 2004, 06:01:13 PM
Is there a nifty VLA or (GET-sumptin) or something that will extract block names and layer names as a string without the xref name itself??

FROM
MainRack|W14X43

to
W14x43
Title: Extracting XREF strings after the "|"
Post by: Kerry on September 11, 2004, 06:20:18 PM
Something like this ??
Code: [Select]

(setq xx "MainRack|W14X43")

(if (setq index (vl-string-search "|" xx))
 (setq
   prefix (substr xx 1 index)
   suffix (substr xx (+ 2 index))
 )
)
Title: Extracting XREF strings after the "|"
Post by: Jeff_M on September 11, 2004, 06:24:30 PM
Sure, here ya go....
Usage: (setq str "MainRack|W14X43")
           (setq newstr (strip2bar str))
Code: [Select]

(defun strip2bar (str / pos)
  (setq pos (vl-string-search "|" str))
  (if (not pos) (setq pos -1));set pos incase "|" not found
  ;increment pos by 2, 1 for 0 vs 1 based index, 1 for next character
  (substr str (+ pos 2))
  )
Title: Extracting XREF strings after the "|"
Post by: Jeff_M on September 11, 2004, 06:26:47 PM
Arghhh! Beat out by Kerry.....no one's even here on Saturday/Sunday and I still get beat by a few minutes...... :/
Title: Extracting XREF strings after the "|"
Post by: Kerry on September 11, 2004, 06:34:00 PM
Dont feel bad Jeff.  I beat myself all the time.  

Oops, too much information ??
Title: Extracting XREF strings after the "|"
Post by: Ron Heigh on September 11, 2004, 06:51:07 PM
:)
Title: Extracting XREF strings after the "|"
Post by: CADaver on September 11, 2004, 07:28:15 PM
Arrrrggghhh...  you won't believe how many times I went through the book and help files looking for vl-string-search and missed it every time.

Someday when I learn some of this lispy stuff, I might actually be useful.

Thanks a load guys, appreciate the help.
Title: Extracting XREF strings after the "|"
Post by: SPDCad on September 11, 2004, 09:52:12 PM
If you modify Jeff's code to the following you can search and extract any string. May come in handy when stripping the layer names in bound drawings.


(defun stripstr (str itm/ pos)
  (setq pos (vl-string-search itm str))
  (if (not pos) (setq pos -1));set pos incase item looking for not found not found
  ;increment pos by 2, 1 for 0 vs 1 based index, 1 for next character
  (substr str (+ pos 2))
);

 enjoy! :)