manddarran Posted August 25, 2011 Posted August 25, 2011 I am trying to write a routine that will copy and rename a Xref. 1. Select existing xref with clipping boundary. 2. Ask user to input new suffix for old xref. 3. Rename existing xref. 4. ask user for location of new xref 5. insert new xref with the same clipping boundary. Now I have a lisp that will do 1,2 and 3. I also have a way of inserting a new xref, but not with the clipping boundary intact. Here is what I have so far I know I have some syntax wrong, but I just don't do this enough to remember them. (defun c:xrn2(/ i ss pt ent lst Nrst) (vl-load-com) (setq adoc (vla-get-activedocument (vlax-get-acad-object) ) acsp (vla-get-block (vla-get-activelayout adoc) ) ) (vla-startundomark adoc) (setq ent (entsel "\nSelect Xref to be renamed:")) (setq item1 (vlax-ename->vla-object (car ent))) (vlax-put-property item1 'Layer "xref") (setq path (vlax-get item1 'Path)) ;(vla-put-Name item1 "DEMO") not working. ) (defun C:XRN () (vl-load-com) (vla-put-Name (vla-Item (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-Acad-Object))) (cdr (assoc 2 (entget (car (entsel "\n Select xref to rename: "))))) ) (getstring T "\n Enter new name for xref: ") ) );end defun Quote
manddarran Posted August 25, 2011 Author Posted August 25, 2011 This throws an error when I try and rename the xref. "Error: Automation Error. Key not found" (defun c:xrn2(/ i ss pt ent lst Nrst) (vl-load-com) (setq adoc (vla-get-activedocument (vlax-get-acad-object) ) acsp (vla-get-block (vla-get-activelayout adoc) ) ) (vla-startundomark adoc) (setq ent (entsel "\nSelect Xref to be renamed:")) (setq item1 (vlax-ename->vla-object (car ent))) (setq name1 (vlax-get item1 'Name)) (vlax-put-property item1 'Layer "xref") (vla-put-name item1 (getstring T "\n Enter new name for xref: ")) (setq path (vlax-get item1 'Path)) ;(vla-put-Name item1 "DEMO") not working. ) Quote
Lee Mac Posted August 25, 2011 Posted August 25, 2011 You cannot rename the Reference unless the new name exists as a Definition in the drawing (otherwise the reference won't be referencing anything). Instead, rename the Definition located in the Block Collection, and the Reference will then inherit this new name. Hope this helps, Lee Quote
manddarran Posted August 25, 2011 Author Posted August 25, 2011 Thx Lee. That unfortunately is over my head. However this works except for copying the clipping boundary. (defun c:xrn2(/ i ss pt ent lst Nrst) (vl-load-com) (setq adoc (vla-get-activedocument (vlax-get-acad-object) ) acsp (vla-get-block (vla-get-activelayout adoc) ) ) (vla-startundomark adoc) (setq ent (entsel "\nSelect Xref to be renamed:")) (setq item1 (vlax-ename->vla-object (car ent))) (setq name1 (vlax-get item1 'Name)) (vlax-put-property item1 'Layer "xref") (setq path (vlax-get item1 'Path)) (command "-rename" "b" name1 (getstring T "\n Enter new name for xref: ")) (command "-xref" "attach" path pause "" "" "") ) Quote
Lee Mac Posted August 25, 2011 Posted August 25, 2011 That unfortunately is over my head Looking at your other code you seem quite capable... Anyway, here is an example: (defun c:test ( / ent nme ) (while (and (setq ent (car (entsel "\nSelect XRef to be Renamed: "))) (zerop (logand 4 (cdr (assoc 70 (tblsearch "BLOCK" (cdr (assoc 2 (entget ent)))))))) ) (princ "\nPlease Select an XRef.") ) (if ent (progn (while (or (not (snvalid (setq nme (getstring t "\nSpecify New Name: ")))) (tblsearch "BLOCK" nme) ) (princ "\nName invalid or already exists.") ) (vla-put-name (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)) ) (cdr (assoc 2 (entget ent))) ) nme ) ) ) (princ) ) Quote
manddarran Posted August 25, 2011 Author Posted August 25, 2011 Much cleaner with the error trapping. Thx. Anyway to get the clipping boundary? I don't see that anywere in the dump. Quote
Lee Mac Posted August 25, 2011 Posted August 25, 2011 To help you out, I've just updated my Copy/Rename block program to work with XRefs Quote
manddarran Posted August 25, 2011 Author Posted August 25, 2011 You have some mad skills. I do this so infrequently that I just can't remember all the stuff.. Quote
halam Posted September 8, 2016 Posted September 8, 2016 Guess what... Today I was working on a phasing plan. different sheets wtih a lot of views all about 1 desing model While is was doing so i was thinking it would be an great idea if you copy / rename xrefs links the same way as blocks using Copy/Rename block Google helped me out. ..It sat here all along from 2011 .. Here is one to give you a idea how i use CB / Steal / xclips & layers for views and colors I use multiple links to a single! model. The idea is that if the model changes (it will..) all my plans change too AutoCAD can work modelbased perfectly, is what i think .. thanks for all your great coding work Lee Mac! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.