New to ActiveX Customization - Renaming Xrefs

New to ActiveX Customization - Renaming Xrefs

Anonymous
Not applicable
1,456 Views
11 Replies
Message 1 of 12

New to ActiveX Customization - Renaming Xrefs

Anonymous
Not applicable

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

 

0 Likes
Accepted solutions (1)
1,457 Views
11 Replies
Replies (11)
Message 2 of 12

cadffm
Consultant
Consultant

the code isn't very safe, but that is not the question, i know.

 

 

If you can AutoLisp, you can edit the code with autolisp funtions, it isn't a problem to merge both functions..

 

old

(strlen StringtoPut)

change to

(strlen StringtoFind)

 

should fix the problem, or?

Sebastian

0 Likes
Message 3 of 12

dlanorh
Advisor
Advisor

@Anonymous wrote:

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);<<== rename lisp and saveas new name
  (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;comment out all red below insert Blue
       (vla-put-name myxref StrtoPut);(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)<<===== not sure if this should be out or in try both, when in uncomment (progn and );progn
       ;);progn
   );vlax-for
  (princ)
  );defun

 Not knowing your input to the two strings; if you know the whole old name, just replace it with the new name, or am i being thick, or is the D######## part a path to the xref and the lisp is working correctly?

 

Make above changes to copy of lisp. Load then type whole xref name for String to find and new name for string to put. TEST on COPY of DRAWING


 

I am not one of the robots you're looking for

0 Likes
Message 4 of 12

dlanorh
Advisor
Advisor
I've just re-read your post. If you're typing "SXS" for the string to find this is also the string to be replaced so the lisp is working correctly.

If you want to replace the "D####..." part, and this isn't a path, then "D####..." is what you type for string to find

I am not one of the robots you're looking for

0 Likes
Message 5 of 12

Anonymous
Not applicable
@dlanorh wrote:
I've just re-read your post. If you're typing "SXS" for the string to find this is also the string to be replaced so the lisp is working correctly.

If you want to replace the "D####..." part, and this isn't a path, then "D####..." is what you type for string to find

I'm getting "malform list on input" from your suggested modifications. 

 

For some additional background information, whats happening is those # signs represent "client-year-job" codes that will be different every time the routine is run and a user wont be prompted to input the information. This is a small part of a larger coding project that sets up plan sets and brings in Xrefs based on an originating site plan file location. Ideally after the other parts of the code bring in the Xref D#########SXS (no matter what the numbers are) it will be able to identify the overlaid xref with "*SXS" in the name and rename it to "XR-SXS" to conform to our internal company standards.

 

Thanks again for your input!

0 Likes
Message 6 of 12

dlanorh
Advisor
Advisor

Sorry, my fault, i must have inadvertantly removed a closing brace. Below should now load without an error.

 

(Defun C:Xref_Rename ( / StringtoFind StringtoPut);<<== rename lisp and saveas new name
  (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;comment out all red below insert Blue
       (vla-put-name myxref StrtoPut);(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)<<===== not sure if this should be out or in try both, when in uncomment (progn and );progn
       ;);progn
    );end_if   
  );vlax-for
  (princ)
);defun

I am not one of the robots you're looking for

0 Likes
Message 7 of 12

Anonymous
Not applicable

@dlanorh wrote:

Sorry, my fault, i must have inadvertantly removed a closing brace. Below should now load without an error.

 

(Defun C:Xref_Rename ( / StringtoFind StringtoPut);<<== rename lisp and saveas new name
  (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;comment out all red below insert Blue
       (vla-put-name myxref StrtoPut);(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)<<===== not sure if this should be out or in try both, when in uncomment (progn and );progn
       ;);progn
    );end_if   
  );vlax-for
  (princ)
);defun

modified to this as suggested. It loads but does not rename even if I give it the full string.

(Defun C:Xref_Rename ( / StringtoFind StringtoPut);<<== rename lisp and saveas new name
  (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;comment out all red below insert Blue
       (vla-put-name myxref StringtoPut)
       ;(vla-reload myxref)
    );end_if   
  );vlax-for
  (princ)
);defun
0 Likes
Message 8 of 12

dlanorh
Advisor
Advisor
Accepted solution

OK. Basic spelling mistake Robot surprised

 

Below is revised code. The "(vla-reload " was needed. I've renamed it rnx so type rnx to run.For the "to find string" any unique partial string will do. The replace string needs to be the new name.

 

You can also rename via the external reference manager by double clicking on the file.

 

(Defun C:rnx ( / StringtoFind StringtoPut);<<== rename lisp and saveas new name
  (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 StringtoPut)
				(vla-reload myxref)
			);progn
		);end_if   
  );vlax-for
  (princ)
);defun

 

I am not one of the robots you're looking for

0 Likes
Message 9 of 12

dlanorh
Advisor
Advisor

A quick question will you only ever have one xref with "sxs" as part of it's name per drawing? If not i think we're going down the wrong road as the lisp will fail the moment it finds a second and tries to rename it as it will be a duplicate name.

I am not one of the robots you're looking for

0 Likes
Message 10 of 12

Anonymous
Not applicable

@dlanorh wrote:

A quick question will you only ever have one xref with "sxs" as part of it's name per drawing? If not i think we're going down the wrong road as the lisp will fail the moment it finds a second and tries to rename it as it will be a duplicate name.


Any situation where this would be used there would only be one file with the suffix "SXS" Any other drawing file would have a different suffix based on the type of plan. I am trying your revised code this morning, I'll be sure to report back. Thanks again!

0 Likes
Message 11 of 12

Anonymous
Not applicable

@dlanorh wrote:

OK. Basic spelling mistake Robot surprised

 

Below is revised code. The "(vla-reload " was needed. I've renamed it rnx so type rnx to run.For the "to find string" any unique partial string will do. The replace string needs to be the new name.

 

You can also rename via the external reference manager by double clicking on the file.

 

(Defun C:rnx ( / StringtoFind StringtoPut);<<== rename lisp and saveas new name
  (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 StringtoPut)
				(vla-reload myxref)
			);progn
		);end_if   
  );vlax-for
  (princ)
);defun

 


This worked perfectly! This was the last piece of my coding project that will ultimately help our team save 2-3 hours per project. I couldn't have done it without your help, thanks again!

0 Likes
Message 12 of 12

dlanorh
Advisor
Advisor
No problem, glad i could help.

I am not one of the robots you're looking for

0 Likes