Dimension Automatically layer assigning lisp

Dimension Automatically layer assigning lisp

Anonymous
Not applicable
3,161 Views
7 Replies
Message 1 of 8

Dimension Automatically layer assigning lisp

Anonymous
Not applicable

Dear all,

I am a beginner in auto lisp program and i have made one lisp for dimension assigning to layer automatically but i need after commands end current layer should back to zero. If anyone expert kindly please help me.

My lisp code is following below:

(defun c:dli()
(command "._layer" "_n" "Z-Dimentions" "_c" "1" "Z-Z002-S-Dimentions" "_th" "Z-Dimentions" "_on" "Z-Dimentions" "_s" "Z-Dimentions" "")
(initdia)
(vl-cmdf "._dimlinear")
(setvar "clayer" 0)
(princ)
)

 

Looking forward your kind support and help in this

0 Likes
Accepted solutions (4)
3,162 Views
7 Replies
Replies (7)
Message 2 of 8

vinodkl
Mentor
Mentor
Accepted solution

Hi @Anonymous 

 

Here is a similar lisp which does the work which you are asking for🙂

http://www.lee-mac.com/layerdirector.html 

You can modify the lisp(change "dimension" layer name) to suit your needs. Read the description completely to know how the lisp works.

--------------------------------------------------------------------------------------------------------------------------
ವಿನೋದ್ ಕೆ ಎಲ್( System Design Engineer)
Likes is much appreciated if the information I have shared is helpful to you and/or others.

Please mark "Accept as Solution" if my reply resolves the issue or answers your question, to help others in the community.
--------------------------------------------------------------------------------------------------------------------------
Message 3 of 8

cadffm
Consultant
Consultant
Accepted solution

Hi,

 

CLAYER is a variable for the current Layer,

Layernames are STRINGs , but you trying to feed CLAYER with a NUMBER.

 

The Layername is "0" and not 0

(setvar "CLAYER" "0")

 

But better is to store the last current layer (setvar oldclayer (getvar "clayer"))

and at the and (setvar "clayer" oldclayer)

And for both layers (clayer), make sure the layer is THAWed

 

 

For non-programming solution:

a) Draw dimlinear on your layer, drag the dimlinear to yout toolpalette [CTRL]+[3]

b) Simple use: Setvar DIMLAYER

 

offtopic

For Lisp questions, please use the LISP board

If you have error messages, please add them to your initial post

 

Sebastian

Message 4 of 8

ВeekeeCZ
Consultant
Consultant
Accepted solution
What version of AutoCAD you have?
Does it have DIMLAYER variable?
Message 5 of 8

ВeekeeCZ
Consultant
Consultant
Accepted solution

Here is a basic approach for such a routine. Commented.

 

(defun c:DLi ( / *error* lay)    ; *error* MUST alway be localized, all the rest should be
  
  (defun *error* (errmsg)   ; must be localized!
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (if lay (setvar 'clayer lay)) ; restore layer in case of error
    (princ))

  
  
  ; ------------------------------------------------------------------------------------------------------------------
  
  (setq lay (getvar 'clayer))
  (command "._-layer" "_t" "Z-Dimentions" "_make" "Z-Dimentions" "_c" "1" "Z-Z002-S-Dimentions" "")  ; MAKE options makes layer on and current. also creates new if doesn't exist
  ; (initdia) useless, dimlinear has no dialog
  (command "._dimlinear")
  (while (> (getvar 'cmdactive) 0) (command pause))  ;; stay within command until done.
  (setvar 'clayer lay) ; restore layer

(princ)
)

 

Message 6 of 8

Anonymous
Not applicable

Thank you for your kind support

Message 7 of 8

Anonymous
Not applicable

How to add single lisp command  multiple defun c: function command

for example:

(defun c:DIMX(dimension) if(not(defun c:DIMY)

 

Looking forward your kind support 

 

 

0 Likes
Message 8 of 8

ВeekeeCZ
Consultant
Consultant

Not really sure what you're after, but you can do something like this.

 

(defun c:dimxy (/ tmp)

  (initget "Vertical")
  (setq tmp (getkword "Would you like make a horizontal dimension? [no, Vertical] : "))
  (if tmp
    (c:dimx)
    (c:dimy))
  (princ)
  )

(defun c:dimx ()
  ;something ...
  )

(defun c:dimy ()
  ;something ...
  )

 

You need to explain better....

0 Likes