×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

lisp to automatically set a predefined layer current

lisp to automatically set a predefined layer current

lisp to automatically set a predefined layer current

(OP)
i have created a XREF layer in our template and here's my plan:
instead of asking people to remember to set the XREF layer current before xref-ing drawings in, i would like to automate this with a lisp, so that, every time someone types xr or xref in the command line, the lisp would trigger and automatically set the XREF layer in the drawing current. this is in reason that i have seen a lot of situations where the xref drawing was brought in with the viewport or defpoints layer active and people go crazy trying to figure out why the xref does not plot or show up in plot preview. i would really appreciate if someone has a lisp handy to do this trick can pass it on. also, a little direction to how/where to put it so that it loads automatically would be of great help as well.also, along the same lines, is there a setting i can change in civil 3D so that the xref is not fixed path by default? i would like to make the xref operation as relative path by default.
regards...

RE: lisp to automatically set a predefined layer current

Put it in the Acad.lsp file.
Make sure Acad.lsp is loaded into every drawing (set ACADLSPASDOC=1)
The lisp you are looking for will be similar to:
( DEFUN C:XR ()
  (SETQ CURRENTLAYER (GETVAR "CLAYER"))
  (SETVAR "CLAYER" "XREF")
  (COMMAND "XATTACH" "XREFNAME" "" "")
  (SETVAR "CLAYER" CURRENTLAYER)
)
You will probably want to add code to check for the existence of the XREF layer etc.

RE: lisp to automatically set a predefined layer current

(OP)
thanks for the lisp IFRs. but i noticed that it only works when i type XR. if i type XREF at the command line, it will bring up the xref manager, and then if i click on ATTACH DRAWING button, it does not do it. do you think that is do-able?

RE: lisp to automatically set a predefined layer current

My young friend - you are going to have to read and understand the LISP fragment I hastily scribbled down.  Then modify it for yourself and expand or copy it to another one that defines a new command "XREF".

For example:

DEFUN C:XR DEfines a new Function that is permenant by virtue of the "C:" and is called XR.

The SETQ defines a local varibvle I called "CURRENTLAYER" and sets it's value to the current layer name, to be used later.

The SETVAR line changes an AUTOCAD variable CLAYER (Current Layer) to "XREF", which works only if it exists, that is.

The COMMAND line executes an AUTOCAD command just as if you typed it on the command line, in this case "XATTACH" which is the same as attaching an xref from a fancy dialog box...

The final SETVAR sets the CLAYER (current layer) back to what it was before we started this program.

The more you know, the better able you are to propel yourself forward!!

Good luck (never give up / never surrender!!!)

RE: lisp to automatically set a predefined layer current

(OP)
copying the code for a defun c:xref was my initial thought; but it didnt work. that's when i thought i am mising something. also, i found that a better place to put the lisp was acaddoc.lsp that acad.lsp. anyway, i appreciate you taking the time in explaining, and thanks for the good explanation. i will take it and try to propel forward as you said!

RE: lisp to automatically set a predefined layer current

I believe it worked for you for "xr", as the lisp routine replaced a shortcut.  But a lisp command function will not take precedence over the regular "xref" command.  There are ways around this, including "undefining" the native xref' command, along with new functions for "xr", "xref" "-xref" "ddlxref" or whatever the dialog box version is.  I believe use of 'reactors' is a cleaner way to do this, as in the example in the first link below.  Good luck!

http://www.cadforum.cz/cadforum_en/qaID.asp?tip=5131

http://www.afralisp.net/lispa/lisp46.htm
 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources