Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Renaming xref....

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
sean.keohane
483 Views, 5 Replies

Renaming xref....

Hi,

This lsp was passed on to me from a colleague but he doesn't know where he got it. It does a useful procedure of placing each xref, residing in the drawing, to a unique layer. The layer name is derived from the xref name. I would like to edit this to take only part of the xref name. This system I work with requires all files to have the job number as a prefix eg LE1399901_Contours.dwg, so the xref name would be LE1299901_Contours by default. I want to remove the first 10 characters to be left with "X_Xref-Contours" layer name using this code.

I have no idea how to achieve this so all help is appreciated.

thanks

Sean

 

 

(defun dxf (i a) (cdr (assoc i a)))
 (defun c:lxr ( / ss cnt xrs en ed bn xp xbn )
    (setq ss (ssget "x" '((0 . "INSERT"))))
    (setq cnt 0)
    (setq xrs (list))
      (while (< cnt (sslength ss))
    (setq en (ssname ss cnt))
    (setq ed (entget en))
    (setq bn (dxf 2 ed))
      (if (/= 0 (logand 12 (dxf 70 (tblsearch "BLOCK" bn))))
        (progn
          (setq xp (dxf 1 (entget (tblobjname "block" bn))))
          (setq xbn (strcat "X_Xref-" bn))
          (command "-layer" "new" xbn "")
          (vlax-put (vlax-ename->vla-object en) 'Layer xbn)
        )
      )
    (setq cnt (1+ cnt))
  )
  (princ)
 )

5 REPLIES 5
Message 2 of 6
pbejse
in reply to: sean.keohane


@sean.keohane wrote:

Hi,

....number as a prefix eg LE1399901_Contours.dwg, so the xref name would be LE1299901_Contours by default. I want to remove the first 10 characters to be left with "X_Xref-Contours" layer name using this code.

I have no idea how to achieve this so all help is appreciated.

thanks

Sean

 

 


Question is will it always be 10 characters?

Better to target the "_" character

 (substr bn (+ 2 (vl-string-position 95 bn nil t)))

 

Like this

  (setq xbn (strcat "X_Xref-" (substr bn (+ 2 (vl-string-position 95 bn nil t)))))

 

 

Message 3 of 6
sean.keohane
in reply to: pbejse

Wow, that was quick. Yes it has been up to now but I like your idea of targeting the underscore character, Our system limits the underscore use as a seperator between jobnumber and file description. I just tested this and it works great. thank you. Forgive my ignorance but Is this code identifying the underscore or counting the characters?

Thanks very much for helping me out.

Regards

Sean

Message 4 of 6
pbejse
in reply to: sean.keohane


@sean.keohane wrote:

 Forgive my ignorance but Is this code identifying the underscore or counting the characters?..

 


More of telling you what position the character is if found. from right to left. and it gives you the position as to where it starts or ends depending on the argument used.

Now if you are absolutely sure that there are no other underscore character on the filename. might as well start from Right to left.

(setq str "This_is a test string")

(substr str (+ 2 (vl-string-position 95 str nil t)));<---from end
"is a test string"
(substr str (+ 2 (vl-string-position 95 str)));<-- from start
"is a test string"

Doesnt make a diffrence does it?

But with this (setq str2 "This_is a test_string")
(substr str2 (+ 2 (vl-string-position 95 str2 nil t)));<---from end
"string"
(substr str2 (+ 2 (vl-string-position 95 str2)));<---from start
"is a test_string"

Clear as mud?

 

 Smiley Happy


@sean.keohane wrote:

Thanks very much for helping me out.

Regards

Sean


You are welcome. Glad i could help

Cheers.

EDIT: Man whats with the text formatting...

 

Message 5 of 6
sean.keohane
in reply to: pbejse

I was just studying the meaning of vl-string-position 95 in your code, thanks for the tutorial. Regards Sean

Message 6 of 6
pbejse
in reply to: sean.keohane


@sean.keohane wrote:

I was just studying the meaning of vl-string-position 95 in your code, thanks for the tutorial. Regards Sean


Good for you glad it helps.

Cheers Sean

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost