Anuncios

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Dimension layer lisp for 2015

Anonymous

Dimension layer lisp for 2015

Anonymous
No aplicable

I have a lisp that we use at work for putting dimensions automatically into the "DIMENSION" layer.  It worked in the past for AutoCAD 2012, but for some reason does not work for 2015.  Does anyone have an idea what might be wrong or what would have changed?  I'm not exactly a code guy, so I've struggled a little... (someone else originally wrote this lisp).

 

Thanks for your help!

 

;;;************************************** Dimension Redefinition ******************************************
;;;
;;; This program Redefines the Dimension commands. The new command incorperates a checks for the dimension
;;; layer and
;;;
;;;
;;;
;;;
;;;********************************************************************************************************

(defun layrchek (layr colr lstyl / layr colr lstyl chklyr)
  (setq layr   (strcase layr)
 colr   (strcase colr)
 lstyl  (strcase lstyl)
 chklyr (tblsearch "layer" layr)
  )
  (if chklyr
    (progn
      (if (or (equal colr nil) (equal colr ""))
 (setq colr (itoa (cdr (assoc 62 chklyr))))
      )
      (if (or (equal lstyl nil) (equal lstyl ""))
 (setq lstyl (cdr (assoc 6 chklyr)))
      )
      (command "_.-layer"    "on"   layr   "t"   layr  "s" layr
        "u"    layr   "c"    colr   layr   "l"  lstyl layr
        ""
       )
    )
    (progn
      (if (or (equal colr nil) (equal colr ""))
 (setq colr "7")
      )
      (if (or (equal lstyl nil) (equal lstyl ""))
 (setq lstyl "CONTINUOUS")
      )
      (command "_.-layer" "m" layr "u" layr "c" colr layr "l" lstyl layr
        "")
    )
  )
  (princ)
)


(setvar "cmdecho" 0)

(if (not (tblsearch "layer" "dimension"))
  (layrchek "dimension" "green" "")
)

(setq dmclst (list "dimlinear"       "dimaligned"
     "dimangular"       "dimbaseline"
     "dimcenter"       "dimcontinue"
     "dimradius"       "dimdiameter"
     "dimordinate"
    )
)

(foreach item dmclst
  (command "undefine" item)
  (setq cmd (strcat "c:" item))
  (if (not (eval (read cmd)))
    (eval
      (read
 (strcat
   "(defun "
   cmd
   " ()"
   "(setq oldlayer (getvar \"CLAYER\") oldos (getvar \"OSMODE\"))"
   "(setvar \"cmdecho\" 0)"
   "(command \"._undo\" \"m\")"
   "(setq lyr (getvar \"clayer\"))"
   "(setvar \"clayer\" \"dimension\")"
   "(setvar \"cmdecho\" 1)"
   "(command \""
   (strcat "_.acad_dim." item)
   "\")"
   "(while (> (getvar \"cmdactive\") 0) (command pause))"
   "(setvar \"cmdecho\" 0)"
   "(setvar \"clayer\" lyr)"
   "(setvar \"CLAYER\" oldlayer)"
   "(setvar \"OSMODE\" oldos)"
   "(princ)"
   ")"
 )
      )
    )
  )
)
(princ)

(command "undefine" "qleader")
(defun c:qleader ()
  (if (tblsearch "layer" "dimension")
    (setvar "clayer" "dimension")
    (layrchek "dimension" "green" "")
  )
  (command "_.acad_dim.qleader")
  (princ)
)

(princ "\n Dimdef Loaded.")

0 Me gusta
Responder
937 Vistas
10 Respuestas
Respuestas (10)

Anonymous
No aplicable

Hi. This lisp looks so bad that it hurts when I look at it :cara_con_una_leve_sonrisa:

 

use this:

;--start--

(if (not (tblsearch "layer" "DIMENSION"))
(progn
(entmake
(list
'(0 . "LAYER")
'(100 . "AcDbSymbolTableRecord")
'(100 . "AcDbLayerTableRecord")
(cons 2 "DIMENSION")
'(70 . 0)
(cons 62 3)
)
)
) ;_progn
) ;_if

(if (not acdb:reactor)
(setq acdb:reactor
(vlr-AcDb-Reactor
nil
'((:vlr-objectappended . a+objcreated))
)
)
)
(defun a+objcreated (Reac Args / entl)
(setq entl (entget (cadr Args)))
(if (and entl
(member (cdr (assoc 0 entl)) (list "DIMENSION" "LEADER"))
(/= (cdr (assoc 8 entl)) "DIMENSION")
)
(progn
(setq entl (subst (cons 8 "DIMENSION") (assoc 8 entl) entl))
(entmod entl)
)
)
)

(princ "\n Dimdef Loaded for more go to www.cadaplus.com :)")
(princ)

 

 

;--end--

 

works much faster and it will not replace original dimenisons commands

best regards

Jedrzej Cytawa

APLUS SA

www.cadaplus.com

 

0 Me gusta

Anonymous
No aplicable

Hey, thanks!  It worked great except for one thing, the text for a leader remains in the "0" layer.  Is there a way to incorporate that to take the "DIMENSION" layer as well?  I tried playing around with it, but all I was able to do was make it not work at all....

 

Thanks again for figuring out the original lisp, its definitely a lot cleaner now!

0 Me gusta

mathewkol
Advisor
Advisor
If you start using the MLEADER command instead, that LISP could be modified to put it on the correct layer. MLEADERs contain both the text and the leader as one object so you don't have to do any weird coding.

Otherwise, a similar reactive lisp could be created to temporarily change layer when your qleader command is invoked then switched back when it's finished.
Matt Kolberg
SolidCAD Professional Services
http://www.solidcad.ca /
0 Me gusta

neaton
Advisor
Advisor

@mathewkol wrote:
If you start using the MLEADER command instead, that LISP could be modified to put it on the correct layer. MLEADERs contain both the text and the leader as one object so you don't have to do any weird coding.

Otherwise, a similar reactive lisp could be created to temporarily change layer when your qleader command is invoked then switched back when it's finished.

I tried changing the (member (cdr (assoc 0 entl)) (list "DIMENSION" "LEADER")) line to (member (cdr (assoc 0 entl)) (list "DIMENSION" "MLEADER")) and it didn't put the MLeader on the Dimension layer. What did I miss?

~Nancy

0 Me gusta

Anonymous
No aplicable
use (list "DIMENSION" "MULTILEADER" "LEADER"). text layer is possible too but i will do later ok?

neaton
Advisor
Advisor
Oops! Name of the object not the command.
Thanks!
0 Me gusta

Anonymous
No aplicable

So AutoCAD has started crashing since I loaded the lisp.  The lisp works great as intended, but seems to have some side effects.

 

Anytime I "COPY" a view port in paperspace, AutoCAD fails everytime.  I can create a new view port, but not copy one.

 

Also, about half of the time I try to create a new layout tab AutoCAD crashes.

 

I removed the lisp and these issues went away.

 

Any clue why this would be happening?  I would like to keep this lisp, but don't want my AutoCAD crashing all the time.

 

Thanks,

0 Me gusta

Anonymous
No aplicable

use this:

(if (not (tblsearch "layer" "DIMENSION"))
(progn
(entmake
(list
'(0 . "LAYER")
'(100 . "AcDbSymbolTableRecord")
'(100 . "AcDbLayerTableRecord")
(cons 2 "DIMENSION")
'(70 . 0)
(cons 62 3)
)
)
) ;_progn
) ;_if

(if (not acdb:reactor)
(setq acdb:reactor
(vlr-AcDb-Reactor
nil
'((:vlr-objectappended . a+objcreated))
)
)
)

(if (not acdb:reactor2)
(setq acdb:reactor2
(vlr-command-reactor
nil
'((:vlr-commandended . a+commandended))
)
)
)

(defun a+objcreated (Reac Args / ent)
(setq ent (cadr args))
(if (and
(null (member ent objcreated))
)
(progn
(setq objcreated (cons ent objcreated))
)
)
)

(defun a+commandended (Reac Args / ent entl vla)
(foreach ent objcreated

(if (and
ent
(setq entl (entget ent))
(member (cdr (assoc 0 entl)) (list "DIMENSION" "LEADER"))
(/= (cdr (assoc 8 entl)) "DIMENSION")
)
(progn
(setq vla (vlax-ename->vla-object ent))
(vla-put-layer vla "DIMENSION")
(vla-update vla)
)
)
)
(setq objcreated nil)
(princ)
)

(princ "\n Dimdef Loaded for more go to www.cadaplus.com :)")
(princ)

 

now will not crash

0 Me gusta

Anonymous
No aplicable

Thanks, that seems to be working great.

0 Me gusta

Anonymous
No aplicable

AutoCAD seems to freeze for 5-10 minutes now any time I try to copy/paste from one drawing to another, or bring in a tool pallette file.  I removed the dimesion lisp and AutoCAD seems to run fine.  Any idea why this might be happening?  It seems to get stuck on "EXECUTETOOL".

 

Thanks!

0 Me gusta