PDA

View Full Version : XREF won't go to dialog in LISP



LanceMcHatton
2004-10-18, 04:44 PM
I wrote a quick little lisp for the keyboard CAD users. It creates the G-XREF layer and then executes the XREF command. The problem is that it will only execute the command line version, not the dialog version.

Here's the lisp:

(defun xr ()
(command "-layer" "m" "G-XREF" "")
(command "._xref")
(princ)
)

I tried just "xref" and then I tried "._xref" but it keeps taking me to the command line version. If I type "XREF" at the command line, I get the dialog version so all the right variables must be correct, right?

Thanks,
Lance

msretenovic
2004-10-18, 05:14 PM
Lance,

Try using initdia before calling the xref command.



(defun xr ()
(command "-layer" "m" "G-XREF" "")
(initdia)
(command "._xref")
(princ)
)


This is from help:

Forces the display of the next command's dialog box

(initdia [dialogflag])

Currently, the following commands make use of the initdia function: ATTDEF, ATTEXT, BHATCH, BLOCK, COLOR, IMAGE, IMAGEADJUST, INSERT, LAYER, LINETYPE, MTEXT, PLOT, RENAME, STYLE, TOOLBAR, and VIEW.

Arguments

dialogflag

An integer. If this argument is not present or is present and nonzero, the next use (and next use only) of a command will display that command's dialog box rather than its command line prompts.

If dialogflag is zero, any previous call to this function is cleared, restoring the default behavior of presenting the command line interface.

Return Values

nil

Examples

Issue the PLOT command without calling initdia first:

Command: (command "_.PLOT")

plot

Enter a layout name <Model>: nil

Enter a layout name <Model>:

AutoCAD prompts for user input in the command window.

Use the following sequence of function calls to make AutoCAD display the Plot dialog box:

(initdia)(command "_.PLOT")

LanceMcHatton
2004-10-18, 06:08 PM
Try using initdia before calling the xref command.


I tried that but it didn't work. Thanks, though!

whdjr
2004-10-18, 07:07 PM
Remove the "._" from the xref command.

(command "xref")

LanceMcHatton
2004-10-18, 09:08 PM
Remove the "._" from the xref command.

(command "xref")
I tried that in the very beginning but no luck. So then I tried this:

(defun xrt ()
(command "-layer" "m" "G-XREF" "")
(INITDIA)
(command "xref")
(princ)
)

but still no luck.

kennet.sjoberg
2004-10-18, 09:57 PM
Hi all !

(initdia 1 ) ; do not affect the xref command
(command "_xref") ; use standard AutoCAD commands, not foreign language version of AutoCAD
(command ".xref") ; avoid using redefined commands
(command "._xref"); both above

I am sorry but I do not have any solution for the problem, I have fought it earlier with no luck.
I also have the same problem with dimension and the getdata "M" in [Mtext/Text/Angle/Horizontal/Vertical/Rotated]
to call up the Mtext dialog, there should initdia work but do not.

: ) Happy computing !

kennet

LanceMcHatton
2004-10-19, 12:23 AM
Ok, how about this...


Is there a way to use a reactor to set the layer whenever the xref command is used?

I have never used reactors before so maybe someone could walk me through it.

Thanks,
Lance

Mike.Perry
2004-10-19, 07:17 AM
Hi

How about using the XAttach command -


(defun C:NewXref ()
(command "_.Layer" "_M" "G-XREF" "")
(command "._XAttach")
(while (> (getvar "CMDACTIVE") 0)
(command pause)
)
(princ)
)
Have a good one, Mike

kennet.sjoberg
2004-10-19, 09:56 AM
...hmmm Mike, that is to jump over the problem not to solve it, ( forces the display of the next command's dialog box ).

Xref Manager use XAttach, button [Attach..]

: ) Happy Computing !

kennet

Mike.Perry
2004-10-19, 10:54 AM
Hi

"Jump over the problem"?

Unless I'm really missing something here (probably), XAttach is a perfectly acceptable tool for Lance's requirement (in my humble opinion).

If it's not please explain what is the right tool for Lance's requirement.

The command Xref can't be used for Lance's requirement, hence the need to look at the problem from a different prospective.

Lance's reactor suggestion is probably the best solution for his needs.

Have a good one, Mike

stig.madsen
2004-10-19, 11:47 AM
I tried that in the very beginning but no luck. So then I tried this:

(defun xrt ()
(command "-layer" "m" "G-XREF" "")
(INITDIA)
(command "xref")
(princ)
)

but still no luck.
Displays the xref dialog just fine here (in r2004).

Mike.Perry
2004-10-19, 12:31 PM
Displays the xref dialog just fine here (in r2004).Hi

Not here in AutoCAD 2002, nor in AutoCAD 2005 when I tried at home last night.

As stated earlier in this thread (initdia) has no affect on the Xref command (if the AutoLISP Reference Guide is to believed, would seem to be the case as it's not working for everyone).

Therefore maybe there's a system variable that has some control over this behaviour.... the obvious one's don't influence the outcome -

CmdDia
FileDia

Have a good one, Mike

stig.madsen
2004-10-19, 12:39 PM
Mike, I tried searching for a variable, too, to see what could affect it. I'm as blank now as before but it still stands that without INITDIA, the code above calls the command line version and with INITDIA it displays the Xref dialog.

I'll try with 2005 later and see if something can be figured out (probably something simple .. always is when it doesn't pop right up).

Mike.Perry
2004-10-19, 12:54 PM
Hi Stig

I will go and try AutoCAD 2004 here (just got to pop downstairs) back in a few minutes....

:beer: Mike

Glenn Pope
2004-10-19, 01:23 PM
I tried it on 2005 and it worked. So there is a variable somewhere.

Mike.Perry
2004-10-19, 02:36 PM
Hi

Back....

Definitely doesn't work in AutoCAD 2000i or 2002.

Works in AutoCAD 2004.

Will check AutoCAD 2005 again tonight (probably me doing something wrong). :idea: Come to think about it a little more I don't think I checked, instead I read the AutoLISP Reference Guide (dangerous I know) -

(initdia) Didn't show the Xref command in the list of commands that it affects (I think, will also confirm this tonight), therefore I added 2 + 2 and got 5.

Therefore it's probably not a system variable but (initdia) having been updated slightly in AutoCAD 2004.

Lance, what version of AutoCAD are you running?

Have a good one, Mike

thomas.stright
2004-10-19, 03:02 PM
Displays the xref dialog just fine here in 05 (plain vanillia)

CAB2k
2004-10-19, 04:41 PM
Here is the answer
http://www.google.com/groups?q=+%22xref+dialog+box%22+group:autodesk.autocad.customization&hl=en&lr=&selm=1FCF628886214DAD322A0E6E4008FC1F%40in.WebX.maYIadrTaRb&rnum=2

LanceMcHatton
2004-10-19, 04:51 PM
Hi

How about using the XAttach command -


(defun C:NewXref ()
(command "_.Layer" "_M" "G-XREF" "")
(command "._XAttach")
(while (> (getvar "CMDACTIVE") 0)
(command pause)
)
(princ)
)
Have a good one, Mike
While this does put the user in a dialog box, it does not put them in the xref manager dialog box.

Thanks for the suggestion, Mike. I really do appreciate everyone's comments.

Lance

LanceMcHatton
2004-10-19, 04:58 PM
Here is the answer
http://www.google.com/groups?q=+%22xref+dialog+box%22+group:autodesk.autocad.customization&hl=en&lr=&selm=1FCF628886214DAD322A0E6E4008FC1F%40in.WebX.maYIadrTaRb&rnum=2Ding ding ding!!

We have a winner! It works! Here's the code:

(defun xr ()
(command "-layer" "m" "G-XREF" "")
(vla-sendCommand
(vla-get-activedocument
(vlax-get-acad-object)
)
"._XREF\n"
)
(princ)
)

The above code sets the current layer to G-XREF and brings up the xref manager dialog for AutoCAD 2002.

Thanks, CAB!

CAB2k
2004-10-19, 05:18 PM
You are quite welcome.

Mike.Perry
2004-10-19, 07:54 PM
Definitely doesn't work in AutoCAD 2000i or 2002.

Works in AutoCAD 2004.

Will check AutoCAD 2005 again tonight (probably me doing something wrong). :idea: Come to think about it a little more I don't think I checked, instead I read the AutoLISP Reference Guide (dangerous I know) -

(initdia) Didn't show the Xref command in the list of commands that it affects (I think, will also confirm this tonight), therefore I added 2 + 2 and got 5.

Therefore it's probably not a system variable but (initdia) having been updated slightly in AutoCAD 2004.

Hi

I realise Lance has got his answer and is now happy (good find CAB)....

Please indulge me a little -

Ok! the routine works in AutoCAD 2005 here at this end (sorry I lied earlier).

Remove the (initdia) from the routine, Xref command runs on the command line (in AutoCAD 2005).

So it looks like no system variable is responsible, but a updating of (initdia) in AutoCAD 2004 to take into account the Xref command (at minimum).

If this is true, it would've been nice if Autodesk had updated the AutoLISP Reference Guide to make light of such a fact.

Have a good one, Mike

stig.madsen
2004-10-19, 08:11 PM
Goodie. Works on 2005 here too. Conclusion must be that INITDIA got updated then.


If this is true, it would've been nice if Autodesk had updated the AutoLISP Reference Guide to make light of such a fact.
Sure would!

Glenn Pope
2004-10-19, 09:29 PM
If this is true, it would've been nice if Autodesk had updated the AutoLISP Reference Guide to make light of such a fact.Thats a smashing idea. Wonder why they never thought about it :roll:

kennet.sjoberg
2004-10-21, 07:32 AM
hrrmmm ding ding dong ... I still can not get it to work as I wish


(defun c:XrLay ( / OldLay )
(setq OldLay (getvar "CLAYER" ) ) ; save current layer
(setvar "CLAYER" "XrLay" ) ; change to an existing xref layer
(vla-sendCommand (vla-get-activedocument (vlax-get-acad-object) ) "._XREFn" ) ; attach the xref
(setvar "CLAYER" OldLay ) ; restore previous layer
(princ)
)

it seem to me that vla-send.. runs after the lisp program and ignore the layer flips,
but if You run the code line by line it works perfect. ( AutoCAD 2002 )

Any hints ?

: ) Happy Computing !

kennet

Mike.Perry
2004-10-21, 09:25 AM
Hi

I think you're missing a very important "\". When added your routine works in AutoCAD 2002 (does for me here) -

(defun c:XrLay (/ OldLay)
(setq OldLay (getvar "CLAYER")) ; save current layer
(setvar "CLAYER" "XrLay") ; change to an existing xref layer
(vla-sendCommand ; attach the xref
(vla-get-activedocument (vlax-get-acad-object))
"._XREF\n" ; <- Missing "\" here
)
(setvar "CLAYER" OldLay) ; restore previous layer
(princ)
)
Have a good one, Mike

kennet.sjoberg
2004-10-21, 10:15 AM
nope Mike, that "\" disappear when I [Submit Reply], "\n" turns in to "n"
I must [ Edit ] and [ Save Changes ] the message to keep the "\n" format.
I think the [Spell Check] removes the "\n" without asking. YES.

But the layer flip do not flip, the xref is inserted on active layer.
Does it really work for You ?

: ) Happy Computing !

kennet

Mike.Perry
2004-10-21, 10:49 AM
Hi Kennet

Ok! my bad, I understood the code you posted was not opening the Xref Dialog Box when ran; by adding "\" the code appeared to run fine here for me (Xref Dialog Box opened....).

I now see / understand the problem, the Xref attached isn't placed on the "XrLay" Layer (that's also true for me here).

If the purpose of the routine is just to attach and Xref to a Layer could you not use my humble offering earlier in the thread (even though it "jumps over the problem").

:beer: Mike

ps The "\" is very frustrating, I noticed the same problem when I posted (but I went back and corrected so it would show my intentions clearly).

Have made a post within Forum Feedback (http://forums.augi.com/forumdisplay.php?f=49) area, regarding "\" -

\ (backslash) disappers from message when posted (http://forums.augi.com/showthread.php?t=9713)

kennet.sjoberg
2004-10-21, 12:36 PM
if I modify the code with (princ..


(defun c:XrLay ( / OldLay )
(setq OldLay (getvar "CLAYER" ) ) ; save current layer
(setvar "CLAYER" "XrLay" ) ; change to an existing xref layer
(princ "\n**** Before **** \n" )
(vla-sendCommand (vla-get-activedocument (vlax-get-acad-object) ) "._XREF\n" ) ; attach the xref
(princ "\n**** After **** \n" )
(setvar "CLAYER" OldLay ) ; restore previous layer
(princ)
)

The Command window will show :

Command: xrlay

**** Before ****

**** After ****

Command:
Command: ._XREF

You see,, the ._XREF is to late

: ) Happy Computing !

kennet

CAB2k
2004-10-21, 01:50 PM
This gets it on the correct layer but I can't get the previous layer restored.

(defun c:XrLay ( / OldLay )
(setq OldLay (getvar "CLAYER" ) ) ; save current layer
(command "-layer" "m" "XrLay" "" ) ; change to an existing xref layer
(vla-sendCommand (vla-get-activedocument (vlax-get-acad-object) ) "._XREF\n" ) ; attach the xref
)

kennet.sjoberg
2004-10-22, 05:48 AM
I have tried difference solutions like
(setvar..
(command "layer..
(vla-send..
(vl-cmdf..
(defun...
to change back to previous layer with no luck,
it seem that AutoCAD lose the contact with XrLay after the (vla-sendCommand..
and do not find the way back, is there a call function to use with (vla- ?

: ) Happy Computing !

kennet

ps. thanks Mike for reporting the [Spell Check] bug

ian.93794
2010-10-05, 01:56 AM
Someone else had the solution for me going from 2009 to 2011

(COMMAND "_xattach") ; 20o9
(COMMAND "_xattach" "~") ; 2011
http://forums.autodesk.com/t5/AutoCAD-2010/Using-xattach-in-2010/m-p/2507053