Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Autoselect layer for dimensions (AutoCAD 2014)

12 REPLIES 12
Reply
Message 1 of 13
Anonymous
1955 Views, 12 Replies

Autoselect layer for dimensions (AutoCAD 2014)

Hello :-),

 

I'm new to the the forum and hope i am at the right place for this:
When selecting any dimension type (from the standard AutoCAD toolbars) i would like it to already be in the layer "dimensions". Currently it starts in layer 0. 

I've been browsing the web a bit and found a lot about it but people are talking about LISP's?? I can do magic things in AutoCAD but i am a complete stranger to LISP's, Macro's, etc... Would like to learn but where to start..

Anyway i can cover this with something else then writing an LISP?

Thanks in advance!

Patrick

12 REPLIES 12
Message 2 of 13
BlackBox_
in reply to: Anonymous


@Anonymous wrote:

 

When selecting any dimension type (from the standard AutoCAD toolbars) i would like it to already be in the layer "dimensions". Currently it starts in layer 0. 

... Would like to learn but where to start..


Welcome to the forum!

 

This is a pretty common place to start customizing AutoCAD, so know that many of us can relate to your situation.

 

Give this a try:

(vl-load-com)
;;;--------------------------------------------------------------------;
(defun CommandReactor:Start ()
  (or *CommandReactor*
      (setq *CommandReactor*
             (vlr-command-reactor
               nil
               '(
                 (:vlr-commandcancelled . CommandReactor:CommandEnded)
                 (:vlr-commandended . CommandReactor:CommandEnded)
                 (:vlr-commandfailed . CommandReactor:CommandEnded)
                 (:vlr-commandwillstart . CommandReactor:CommandWillStart)
                )
             )
      )
  )
  (prompt "\nCommand reactor loaded. ")
  (princ)
)
;;;--------------------------------------------------------------------;
(defun CommandReactor:CommandEnded (rea cmd)
  (if (and *OldClayer*
           (wcmatch (strcase (car cmd)) "*DIM*")
      )
    (progn
      (setvar 'clayer *OldClayer*)
      (setq *OldClayer* nil)
    )
  )
)
;;;--------------------------------------------------------------------;
(defun CommandReactor:CommandWillStart (rea cmd)
  (if (wcmatch (strcase (car cmd)) "*DIM*")
    (progn
      (setq *OldClayer* (getvar 'clayer))
      (vla-add
        (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
        (setq layerName "DIMENSION")
      )
      (setvar 'clayer layerName)
    )
  )
)
;;;--------------------------------------------------------------------;
(CommandReactor:Start)
(princ)

 

 



"How we think determines what we do, and what we do determines what we get."

Message 3 of 13
BlackBox_
in reply to: Anonymous

I forgot to localize layerName, an Autodesk's forum won't allow me to correct my post from iPhone... Grrr :o(


"How we think determines what we do, and what we do determines what we get."

Message 4 of 13
_Tharwat
in reply to: BlackBox_

BlackBox , I guess you forgot to check if the Layer Name is already existed and set it on instead of creating the same

Layer Name everytime the user invoke any Dimension command call . Smiley Wink

Message 5 of 13
Anonymous
in reply to: Anonymous

Blackbox many thanks for the reply!

The suggested solution i need to copy paste into the visual lisp editor? I am really unskilled in all this so i might need some more help i reckon... 

 

The layer i'd like to use as a standard for my dimensions is actually called "Dimension". 

 

-Patrick

Message 6 of 13
BlackBox_
in reply to: Anonymous

Tharwat - You didn't try the code before posting, did you? *tisk tisk*

Because if you did, you'd have realized that the vla-Add Method returns either the new item Object created, or the exiting Object without throwing an Exception.


"How we think determines what we do, and what we do determines what we get."

Message 7 of 13
BlackBox_
in reply to: Anonymous

No worries; we all start somewhere.

Yes, copying the code and loadin it via VLIDE is one way to test the code posted above.

If you choose to keep the code, you'll want to save it to a .LSP and load it with each Document via AcadDoc.lsp.

Feel free to replace the layerName variable's string value to anything you like.


"How we think determines what we do, and what we do determines what we get."

Message 8 of 13
_Tharwat
in reply to: BlackBox_


@BlackBox_ wrote:
Tharwat - You didn't try the code before posting, did you? *tisk tisk*

Because if you did, you'd have realized that the vla-Add Method returns either the new item Object created, or the exiting Object without throwing an Exception.


I am sorry , I didn't try the code but just read the code .Smiley Sad

 

It's good to know that the vla-add function is not throwing an error if objects are already existed .

 

Sorry for the confusion and thanks for the info as well .

Message 9 of 13
Anonymous
in reply to: BlackBox_

Hi blackbox,

 

You make it look so easy but i am doing something wrong i think..

I typed in Autocad "VLIDE", copy pasted your quoted text, saved that as an .lsp file.

With "load application" in autocad i tried to load it but then it says it can't be loaded?

I think i need babysteps! Smiley Embarassed

 

Message 10 of 13
BlackBox_
in reply to: _Tharwat


@_Tharwat wrote:

@BlackBox_ wrote:
Tharwat - You didn't try the code before posting, did you? *tisk tisk*

Because if you did, you'd have realized that the vla-Add Method returns either the new item Object created, or the exiting Object without throwing an Exception.


I am sorry , I didn't try the code but just read the code .Smiley Sad

 

It's good to know that the vla-add function is not throwing an error if objects are already existed .

 

Sorry for the confusion and thanks for the info as well .


No worries, my friend. :beer:



"How we think determines what we do, and what we do determines what we get."

Message 11 of 13
BlackBox_
in reply to: Anonymous


@Anonymous wrote:

You make it look so easy but i am doing something wrong i think.


That is kind of you to say, Triek.

 

No worries; we all start somewhere... I stopped using Startup Suite a long, long time ago, so I'll explain how I use AcadDoc.lsp instead (you may have done some of this already, which is fine😞

 

  1. Save the copied code to a .LSP file, and note where that location is.
  2. Open AcadDoc.lsp and include a LOAD statement for the previously saved .LSP file.
  3. Ensure that the location for the recently saved .LSP file is either added to SFSP, or hard-coded into the LOAD satement.
  4. If using 2013 SP1, or 2014, and SECURELOAD is enabled, also be sure that this folder is added to TRUSTEDPATHS otherwise you may be prompted to load this file each time a drawing is opened.

 

 

So, for demonstration purposes, if I were to save the above code to C:\BlackBox\lisp\FOO.lsp, then I would add C:\BlackBox\lisp\ to my SFSP, and add this to AcadDoc.lsp:

(load "FOO.lsp")

 



"How we think determines what we do, and what we do determines what we get."

Message 12 of 13
Anonymous
in reply to: BlackBox_

I will look into this again to see if i can get it working. Had some sweet vacatanial time since last time :-). I will most likely gonna need a crashcourse on writing LISP's, i am the so called newbie in this :-).

Message 13 of 13
fenton.webb
in reply to: Anonymous

As you mention SECURELOAD in this thread, I'm posting this white paper for you guys to checkout http://adndevblog.typepad.com/autocad/2013/07/all-you-need-to-know-about-autocad-secureload-au.html




Fenton Webb
AutoCAD Engineering
Autodesk

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost