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

Attach xref

6 REPLIES 6
Reply
Message 1 of 7
jjorovi
558 Views, 6 Replies

Attach xref

Hi all.

I have this code to insert references, only selecting the file and the insertion point.
The problem I have is that the command does not work the first time I run it when I start new drawings or start the autocad.
What's going on?

 

(defun c:AT (/)
(initdia)
(command "_.-XREF" "_Attach" "_None" MYPOINT "")
(setq MYPOINT (getpoint "\nselect an insertion point"))
  (while (> (getvar "CMDACTIVE") 0) (command ""))
  (princ)
)

 

6 REPLIES 6
Message 2 of 7
Kent1Cooper
in reply to: jjorovi


@jjorovi wrote:

Hi all.

I have this code to insert references, only selecting the file and the insertion point.
The problem I have is that the command does not work the first time I run it when I start new drawings or start the autocad.
What's going on?

 

(defun c:AT (/)
(initdia)
(command "_.-XREF" "_Attach" "_None" MYPOINT "")
(setq MYPOINT (getpoint "\nselect an insertion point"))
  (while (> (getvar "CMDACTIVE") 0) (command ""))
  (princ)
)

 


You have it trying to use the MYPOINT variable before it has been set.  And you're not going to be able to feed in the options such as Attach and the location from a (command) function if you're in the dialog box.  Try getting that point first, and a file name first also [see the (getfiled) function], and then, without the (initdia), feed them into an Xref command.

Kent Cooper, AIA
Message 3 of 7
jjorovi
in reply to: Kent1Cooper

Something like this?

 

(defun c:AT ()
(setq FILEN (getfiled "Select File" "C:/" "dwg" 8))
(setq MYPOINT (getpoint "\nselect an insertion point"))
(command "_.-XREF" "_Attach" FILEN MYPOINT "")
(while (> (getvar "CMDACTIVE") 0) (command ""))
  (princ)
)

 

How I can go back to the previous folder address where I selected the last reference?

Message 4 of 7
hmsilva
in reply to: jjorovi

If I understood correctly, something like this perhaps.

(defun c:AT (/ BASE FILEN MYPOINT)
  (setq BASE "c:/")
  (while (and (setq FILEN (getfiled "Select File" BASE "dwg" 8))
	      (setq MYPOINT (getpoint "\nselect an insertion point"))
	 );; and
    (command "_.-XREF" "_Attach" FILEN MYPOINT "" "" "")
    (setq BASE (strcat (vl-filename-directory FILEN) "\\"))
  );; while
  (princ)
);; AT

HTH

Henrique

EESignature

Message 5 of 7
stevor
in reply to: hmsilva

And HMSilva's example might be further modified to use a global variable for the BASE variable. This allows reentry using the previous, plus the global, *BASE, could be reset by other 'setq functions for other dwg groups. (defun c:AT (/ FILEN MYPOINT) ; global *BASE (if (not *BASE) (setq *BASE "c:/") ) (while (and (setq FILEN (getfiled "Select File" *BASE "dwg" 8)) (setq MYPOINT (getpoint "\nselect an insertion point")) );; and (command "_.-XREF" "_Attach" FILEN MYPOINT "" "" "") (setq *BASE (strcat (vl-filename-directory FILEN) "\\")) ; selectee );; while (princ) ) ; AT Henrique mod-global
S
Message 6 of 7
stevor
in reply to: stevor

And HMSilva's example might be further modified to use a global variable for the BASE variable. This allows reentry using the previous, plus the global, *BASE, could be reset by other 'setq functions for other dwg groups. (defun c:AT (/ FILEN MYPOINT) ; global *BASE (if (not *BASE) (setq *BASE "c:/") ) (while (and (setq FILEN (getfiled "Select File" *BASE "dwg" 8)) (setq MYPOINT (getpoint "\nselect an insertion point")) );; and (command "_.-XREF" "_Attach" FILEN MYPOINT "" "" "") (setq *BASE (strcat (vl-filename-directory FILEN) "\\")) ; selectee );; while (princ) ) ; AT Henrique mod-global And a Rich Text version.
S
Message 7 of 7
hmsilva
in reply to: stevor

Nice mod, stevor!

Henrique

EESignature

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

Post to forums  

Autodesk Design & Make Report

”Boost