Message 1 of 12

Not applicable
05-23-2018
10:22 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am wondering if anyone with more experience with ActiveX methods can help me understand how to modify a code I found. Basically I am trying to rename an Xref that is in my drawing from "D#########SXS" to "XR-SXS". I found a code that sorta works on the forums (see below). When I run this, it identifies the "SXS" in the xref name but only replaces those 3 characters with whatever I input as StringtoPut. Is there a way to have it replace the entire file name with the StringtoPut input value?
Original code can be found at this original post:
(Defun C:Xref_Rename ( / StringtoFind StringtoPut) (setq StringtoFind (getstring "\nEnter string in Xref name: ") StringtoPut (getstring "\nEnter new string here: ") );setq (vlax-for MyXref (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)));<--go through all block objects (if (and (vl-string-search (strcase StringtoFind) (strcase (vla-get-name MyXref)));<---if the name contains your string (= (vla-get-isxref MyXref) :vlax-true);<---if it's an xref ) (progn (vla-put-name myxref (vl-string-subst StringtoPut;<---Change the name (substr (vla-get-name MyXref) (1+ (vl-string-search (strcase StringtoFind) (strcase (vla-get-name MyXref)))) (strlen StringtoPut));substr (vla-get-name myxref) );string subst );vla-put-name (vla-reload myxref) );progn );if );vlax-for (princ) );defun
Solved! Go to Solution.