Jump to content

Execute commando before and after original command


Aftertouch

Recommended Posts

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...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

@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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...