Aftertouch Posted March 23, 2017 Share Posted March 23, 2017 Hello all, Im looking for a way to execture a commando before and after the original command. In this case im looking for the following: When using any of the 'ATTACH' commands: (ATTACH, XATTACH, PDFATTACH etc.... etc... - set UCS to world. - place Xrefs - set UCS back to original UCS. I tried to use the 'UNDEFINE' function, but for some reason i get an 'unknown' command error from the lisp, but when i use the exact same like in autocad one-by-one there is no problem... It looks like AutoCAD cannot handle multiple UNDEFINE functions... Quote Link to comment Share on other sites More sharing options...
Grrr Posted March 23, 2017 Share Posted March 23, 2017 I did attempt with command reactor (with combination of sendcommand) - It did not work (weird behaviour - perhaps because of the stacked command calls and the attach dialog popup). My next attempt was with insert reactor - result was: no reaction at all. And my final attempt was with xref reactor (using beginAttach / endAttach / abortAttach events) - It did not work (no reaction). So I have no idea how this can be solved. Quote Link to comment Share on other sites More sharing options...
jonathann3891 Posted March 23, 2017 Share Posted March 23, 2017 This is my go at it, but I cant get the ucs to restore. Maybe someone can chime in with a solution. I'm sure it can be written much better.... (defun c:test (/ xtype) (setq sfv (getvar "UCSNAME")) (initget 1 "Image Xref PDF") ; [1 = no enter allowed] (setq xtype (getkword (strcat "\nSelect Plot [image/Xref/PDF]:"))) (cond ((= xtype "Image") (Image)) ((= xtype "Xref") (Xref)) ((= xtype "PDF") (PDF)) ) ) (defun Image () (command "UCS" "WORLD" "") (command "_attach" "~") ) (defun Xref () (command "UCS" "WORLD" "") (command "_xattach" "~") ) (defun PDF () (command "UCS" "WORLD" "") (command "_pdfattach" "~") ) (progn (command "ucs" "NA" "R" sfv)) (princ) Quote Link to comment Share on other sites More sharing options...
broncos15 Posted March 23, 2017 Share Posted March 23, 2017 I can look into it, but just as an FYI, this is why it is generally better to not use UCS, and rather just have a LISP routine that twists using dview and the angbase and snapang variables. That way you never have issues with xrefs and you are always actually located in the correct location in space. Quote Link to comment Share on other sites More sharing options...
jonathann3891 Posted March 23, 2017 Share Posted March 23, 2017 I typically save a VIEW and not the actual ucs. Quote Link to comment Share on other sites More sharing options...
tombu Posted March 23, 2017 Share Posted March 23, 2017 I can look into it, but just as an FYI, this is why it is generally better to not use UCS, and rather just have a LISP routine that twists using dview and the angbase and snapang variables. That way you never have issues with xrefs and you are always actually located in the correct location in space. In Civil work everything is laid out and located with coordinates. Anything other than WCS could cause a disaster! Quote Link to comment Share on other sites More sharing options...
broncos15 Posted March 23, 2017 Share Posted March 23, 2017 In Civil work everything is laid out and located with coordinates. Anything other than WCS could cause a disaster!Exactly, which is why I always recommend to people to use dview versus UCS. Quote Link to comment Share on other sites More sharing options...
Aftertouch Posted March 23, 2017 Author Share Posted March 23, 2017 Dview as a few disadvantages versus an new unnamed UCS when it comes to drawing. We always use an unnamed ucs but keep Xrefs in WCS. Quote Link to comment Share on other sites More sharing options...
tombu Posted March 23, 2017 Share Posted March 23, 2017 Dview as a few disadvantages versus an new unnamed UCS when it comes to drawing. We always use an unnamed ucs but keep Xrefs in WCS. Plan views created by Civil 3D are all dview twisted views as well as those created by every Civil software I've ever seen. What possible disadvantages could dview have that nobody in our industry has discovered before? Are you aware of what would happen if the wrong coordinates for a job were used to lay it out? Quote Link to comment Share on other sites More sharing options...
Aftertouch Posted March 27, 2017 Author Share Posted March 27, 2017 I did it, woohoo! All works with original commands. for those interested: (defun UNDEFINEATTACH() (setvar "cmdecho" 0) (command "UNDO" "BEGIN") (command "UNDEFINE" "ATTACH") (princ) ) (defun C:ATTACH() (if (= (getvar 'worlducs) 1)(ASKFORUCS)) (command ".ATTACH" "~") (RESTOREUCS) (princ) ) (UNDEFINEATTACH) (defun UNDEFINEXATTACH() (command "UNDEFINE" "XATTACH") (princ) ) (defun C:XATTACH() (if (= (getvar 'worlducs) 1)(ASKFORUCS)) (command ".XATTACH" "~") (RESTOREUCS) (princ) ) (UNDEFINEXATTACH) (defun UNDEFINEIMAGEATTACH() (command "UNDEFINE" "IMAGEATTACH") (princ) ) (defun C:IMAGEATTACH() (if (= (getvar 'worlducs) 1)(ASKFORUCS)) (command ".IMAGEATTACH" "~") (RESTOREUCS) (princ) ) (UNDEFINEIMAGEATTACH) (defun UNDEFINEDWFATTACH() (command "UNDEFINE" "DWFATTACH") (princ) ) (defun C:DWFATTACH() (if (= (getvar 'worlducs) 1)(ASKFORUCS)) (command ".DWFATTACH" "~") (RESTOREUCS) (princ) ) (UNDEFINEDWFATTACH) (defun UNDEFINEDGNATTACH() (command "UNDEFINE" "DGNATTACH") (princ) ) (defun C:DGNATTACH() (if (= (getvar 'worlducs) 1)(ASKFORUCS)) (command ".DGNATTACH" "~") (RESTOREUCS) (princ) ) (UNDEFINEDGNATTACH) (defun UNDEFINEPDFATTACH() (command "UNDEFINE" "PDFATTACH") (princ) ) (defun C:PDFATTACH() (if (= (getvar 'worlducs) 1)(ASKFORUCS)) (command ".PDFATTACH" "~") (RESTOREUCS) (princ) ) (UNDEFINEPDFATTACH) (defun UNDEFINEPOINTCLOUDATTACH() (command "UNDEFINE" "POINTCLOUDATTACH") (princ) ) (defun C:POINTCLOUDATTACH() (if (= (getvar 'worlducs) 1)(ASKFORUCS)) (command ".POINTCLOUDATTACH" "~") (RESTOREUCS) (princ) ) (UNDEFINEPOINTCLOUDATTACH) (defun UNDEFINECOORDINATIONMODELATTACH() (command "UNDEFINE" "COORDINATIONMODELATTACH") (command "UNDO" "END") (setvar "cmdecho" 1) (princ) ) (defun C:COORDINATIONMODELATTACH() (if (= (getvar 'worlducs) 1)(ASKFORUCS)) (command ".COORDINATIONMODELATTACH" "~") (RESTOREUCS) (princ) ) (UNDEFINECOORDINATIONMODELATTACH) (defun ASKFORUCS() (setq reply (ACET-UI-MESSAGE "Change UCS to World?" "SET UCS WORLD" (+ Acet:YESNO Acet:ICONQuestion))) ;; Yes = 6, ;; No = 7 (if (= reply 6) (progn (command "UCS" "World") (setq ucsaangepastnaarworld 1) (princ "\nUCS aangepast naar WSC.") ) (progn (setq ucsaangepastnaarworld 0) (princ "\nUCS ongewijzigd.") ) ) (princ) ) (defun RESTOREUCS() (if (= ucsaangepastnaarworld 1) (progn (command "UCS" "P") (setq ucsaangepastnaarworld 0) (princ "\nUCS hersteld naar vorige instelling.") ) (progn (setq ucsaangepastnaarworld 0) (princ "\nUCS ongewijzigd.") ) ) (princ) ) (princ) Quote Link to comment Share on other sites More sharing options...
OMEGA-ThundeR Posted March 27, 2017 Share Posted March 27, 2017 That is a complex way to add an xref and keeping UCS settings. I made one myself a few months ago: (also some dutch words in the code ) (Defun c:xrl (/ huidigelaag xrefbestand) (setq huidigelaag (getvar "clayer")) (setq xrefbestand (getfiled "Kies het bestand dat je als Xref wilt gebruiken:" "X:/Hoofdmap/Projectmap/" "dwg" 10)) (command "UCS" "Named" "Save" "TEMP-UCS" "Y") (command "UCS" "world") (command "-layer" "make" "X-XX-AL-REFERENTIE-G" "") (command "_-xref" "overlay" xrefbestand '(0 0 0) "1" "1" "0") (Command "-Layer" "set" huidigelaag "") (command "UCS" "NAmed" "Restore" "TEMP-UCS") (princ "\nXref geplaatst.") ) The line with 'setq xrefbestand' can be deleted or changed. In my personal case it opens the main projects folder so it skips some explorer work. Dutch explanation: Slaat de huidige laag op, en de huidige UCS. Vervolgens verandert het de UCS naar WORLD, plaatst het XREF bestand (DWG) in een goede (NLCS) laag en zet vervolgens de UCS weer op de oude instelling terug en maakt ook de vorige laag weer actief. Zo kun je dus direct doorwerken in de zelfde UCS en laagnaam als voordat je de XREF hebt toegevoegd. Quote Link to comment Share on other sites More sharing options...
Aftertouch Posted March 27, 2017 Author Share Posted March 27, 2017 @OMEGA-Thunder, Your method created a new command with only XREF support. So i assume that you cannot use the XREF Toolpallet anymore? Also, mine works for PDF, IMAGE, DGN, POINTCLOUd etc.etc. all attach functions. Quote Link to comment Share on other sites More sharing options...
OMEGA-ThundeR Posted March 27, 2017 Share Posted March 27, 2017 I guess you are right on the new command part. But it works in my case and you can perhaps get some parts from the code to edit your own . My 'toolpalette' works just fine, but DWG files are 99% of the time the only thing i add to my drawings that way. Images and other files usually don't need to go on coördinates, so i just drag them in the drawing to get the results i need. Quote Link to comment Share on other sites More sharing options...
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.