AutoCAD/Change xref type
Expert: Bill DeShawn - 6/7/2010
QuestionQUESTION: Bill,
You have helped me in the past with autolisp questions. I lost your e-mail so I apologize I can't just send you the code as an attachment.
I am trying to modify this code so that it will not permit the user to run the function in model space, but instead will alert them to run it in paperspace. If the user is in paperspace the function will run.
Thanks.
Nathan
Code below:
(defun c:RCD (/ CECHO
CLAY CLOUDARCSIZE CLOUDCOLOR
CLOUDLAYER CLOUDLINETYPE CLOUDPRELAYER
LAYERCHECK LTYPECHECK OMODE
REVISIONCHECK REVISIONNUMBER REVPOINT
TAGBLOCKNAME TAGCOLOR TAGLAYER
TAGLINETYPE TAGPRELAYER USERREVISIONNUMBER
)
(acet-error-init
(list (list "cmdecho" 0
"osmode" (getvar "osmode")
"clayer" (getvar "clayer")
"attdia" (getvar "attdia")
);list
T
);list
);acet-error-init
(cond (= "tilemode" 0
(defun CreateLayer (Name Color Linetype /)
(setq LayerCheck (tblsearch "LAYER" Name)
LTypeCheck (tblsearch "LTYPE" Linetype)
)
(if (not LTypeCheck)
(alert
"Linetype not in drawing.\nPlease insert Linetype and re-run this routine."
)
(progn
(if (not LayerCheck)
(command "-Layer" "N" Name "C" Color Name "L" Linetype Name "")
)
)
)
)
;; Save original layer
(setq CLay (getvar "CLAYER"))
;; Save original OSMODE
(setq OMode (getvar "OSMODE"))
;; Save original CMDECHO
(setq CEcho (getvar "CMDECHO"))
;; Disable CMDECHO
(setvar "CMDECHO" 0)
;; Disable ATTDIA
(setq ATTDIAmode (getvar "ATTDIA"))
(setvar "ATTDIA" 0)
;; Disable OSMODE
(if (and (> OMode 0)(< OMode 16384))
(setvar "OSMODE" (+ OMode 16384))
)
;; Define Revision Tag Layer Values
(setq TagPreLayer "Revision-Deltas-" ;<- Tag Layer Name
TagColor 6 ;<- Tag Layer Color
TagLinetype "Continuous" ;<- Tag Layer Linetype
)
;; Define Revision Block Name
(setq TagBlockName "Q:/AutoCad/RWB/Blocks/Revision-Delta") ;<- Adjust tag block name here
;; Define Revision Cloud Layer Values
(setq CloudPreLayer "Revision-Clouds-" ;<- Cloud Layer Name
CloudColor 6 ;<- Cloud Layer Color
CloudLinetype "Continuous" ;<- Cloud Layer Linetype
)
;; Define Revision Cloud Arc Size
(setq CloudArcSize 0.25) ;<- Revision Arc radius
;; Initialize Revision Number
(setq RevisionNumber 1)
;; Check for Previous Revisions based on Layer names
(setq RevisionCheck
(tblsearch
"LAYER"
(strcat TagPreLayer (itoa RevisionNumber))
)
)
;; Keep Checking
(While RevisionCheck
(setq RevisionNumber (1+ RevisionNumber))
(setq RevisionCheck
(tblsearch
"LAYER"
(strcat TagPreLayer (itoa RevisionNumber))
)
)
)
(initget 128)
;; Ask User for Revision Number with a prompt of the next available
;; number
(setq UserRevisionNumber
(getint (strcat "\nEnter Revision Number <"
(itoa RevisionNumber)
">: "
)
)
)
;; If User changed the Revision Number adjust variable
(if UserRevisionNumber
(setq RevisionNumber UserRevisionNumber)
)
;; Calculate Layer Names for Tag and Cloud
(setq TagLayer (strcat TagPreLayer (itoa RevisionNumber))
CloudLayer (strcat CloudPreLayer (itoa RevisionNumber))
)
;; Create Tag Number Layer
(CreateLayer TagLayer TagColor TagLinetype)
;; Create Cloud Layer
(CreateLayer CloudLayer CloudColor CloudLinetype)
(setvar "CLAYER" CloudLayer)
;; Freeze other clouds
(command "_.-Layer" "_F" (strcat CloudPreLayer "*") "")
;; Execute Revision Cloud command with desired arc values
(command "_.revcloud" "_A"
(rtos CloudArcSize 2 (getvar "luprec"))
(rtos CloudArcSize 2 (getvar "luprec"))
)
;; Continue Revision Cloud command until user exits command
(while (> (getvar "cmdactive") 0)
(command "\\") ;<- The Pause symbol will not pause the command. Backslash used instead.
)
(setvar "CLAYER" TagLayer)
;; Ask user for Tag Location
(setq RevPoint (getpoint "\nSpecify Revision Tag Location: "))
(while (not RevPoint)
(setq RevPoint (getpoint "\nPlease Specify Revision Tag Location: "))
)
(if RevPoint
(progn
;; Insert Tag Block
(command "_.Insert"
TagBlockName ;<- This is a variable holding the name of the tag block
RevPoint
"1"
"1"
"0"
(itoa RevisionNumber)
)
)
)
(setvar "CLAYER" CLay)
(setvar "OSMODE" OMode)
(setvar "CMDECHO" CEcho)
(setvar "ATTDIA" ATTDIAmode)
(acet-error-restore)
)
(t
(princ "\nRevision cloud not permitted in Model space. Please switch to Layout or go to sheet file.")
)
);end conditional statement
(princ)
)
ANSWER: In my experience, I found it best to check to see if the name of the current tab is "Model", and if it is, alert the user. But if it's not "Model", then just run the PSPACE command.
(if
(= (getvar "ctab") "Model");cond
(progn
(alert "Please run this function in a paper space layout.");then
(exit)
)
(command "_.pspace");else
)
Keep in touch
Bill DeShawn
http://my.sterling.net/~bdeshawn
---------- FOLLOW-UP ----------
QUESTION: Hi Bill. I'm afraid I'm stuck again. Your answer above worked great and our company has been using the lisp extensively. Another small issue has come up involving this lisp that I can't figure out.
I'd like to alert the user to change the current layer if the current layer is set to one of the revision cloud layers, which get frozen if a subsequent revision number is chosen. As you know, the current layer can't be frozen. Currently the routine errors without an explanation that many of our users can't figure out. I'd like to make it more user friendly.
Thanks for your help. Let me know if you need further explanation.
ANSWER: Here's some sample code that you I think you should be able to apply to this routine:
(defun c:test1 ()
(if
(= (cdr (assoc 70 (tblsearch "layer" cloudlayer))) 0)
(setvar "clayer" cloudlayer)
(progn
(alert (strcat "Aborting routine. Cloud layer is frozen.\nCannot set layer " cloudlayer " current."))
(exit)
)
)
(princ)
)
or
(defun c:test2 ()
(if
(= (cdr (assoc 70 (tblsearch "layer" cloudlayer))) 0)
(setvar "clayer" cloudlayer)
(command "_.layer" "_t" cloudlayer "_s" cloudlayer "")
)
(princ)
)
Let me know how it goes.
Bill DeShawn
http://my.sterling.net/~bdeshawn
---------- FOLLOW-UP ----------
QUESTION: Hi again Bill. I haven't gotten your sample code for the revision cloud to work yet but I will keep playing with it.
I have another question for you if you don't mind. Is it possible to change the xref type (attach to overlay and vice versa) using LISP? I'm trying to find a way to automate the process. On a single drawing it is fine to change the xref type manually on one or more xrefs, but if a LISP could do it then I could run a script on multiple drawings.
Thanks in advance. You are always a big help.
AnswerDo you know how to change the XREF from attach to overlay using the palette or dialog? Depending on the version, you can do it either of two ways.
The older versions work better than the newer versions. In the old version, you open the XREF Manager dialog, and find the file you want to change, look under the Type columns and find "Attach" and double-click on it and it changes to Overlay. Very simple.
But now in the newer palette versions, You open the XREF palette, you select the File Reference, then you go to the bottom of the palette where it says "Details", look underneath for "Type", double-click on "Attach" and select "Overlay". Isn't that great? If AutoCAD gets any more advanced we won't get any work done.
Keep in touch
Bill DeShawn
http://my.sterling.net/~bdeshawn