Jump to content

LISP for quick work with layers and styles


georgi9909

Recommended Posts

Hi peoples,

For a long time I'm searching for way to improve my work speed in Autocad.All functions I've use like line,circle,trim,extend and etc. are with key combination. Things also I want to do are:

1. Loading company layers with key combination

2. Quickly switch to another layer with key combination

3. Quickly change layer of selected object with key combination

4. Quickly switch to another text, dimension and multileader style

 

Can you help me with these things.

 

Thank you in advance!

 

Georgi

Link to comment
Share on other sites

Shouldn't company layers already be included in your template file?

 

Re: key combinations. Why do these have to be done using lisp? Why not use keyboard shortcuts?

Link to comment
Share on other sites

I'm sure if you look hard enough you'll find someone has already written a lisp that accomplishes the task. You would only have to modify it for your specific layers. What will you do with all the time saved?

 

There are any number of websites that have custom lisp routines available. The Swamp, Cadalyst magazine, Lee Mac's, DoftSoft, ManuSoft, and AfraLISP just to name a few.

Link to comment
Share on other sites

Is it possible to make some lisp which when type:

set - to chose what option you want to change Layer/Dim Style/Text Style/Multileader Style/

in Layer will be company layers

in Dim Style will be styles you make and etc.

Link to comment
Share on other sites

Have a look at a script all you need to do is write down what your doing manually make new layers change text styles etc very simple just do in notepad.

 

-layer n layer1 c layer1 45
n layer211 c layer211 30 Lt dashed

textstyle standard

 

The other thing to look at is a custom menu or toolbar that has your company stuff in it, click a button text style set, layer set.

Link to comment
Share on other sites

This is the lisp what I'm using for creating the layers.

(defun MakeLayer ( name colour linetype lineweight willplot bitflag description )
 ;; © Lee Mac 2010
 (or (tblsearch "LAYER" name)
   (entmake
     (append
       (list
         (cons 0 "LAYER")
         (cons 100 "AcDbSymbolTableRecord")
         (cons 100 "AcDbLayerTableRecord")
         (cons 2  name)
         (cons 70 bitflag)
         (cons 290 (if willplot 1 0))
         (cons 6
           (if (and linetype (tblsearch "LTYPE" linetype))
             linetype "CONTINUOUS"
           )
         )
         (cons 62 (if (and colour (< 0 (abs colour) 256)) colour 7))
         (cons 370
           (if (minusp lineweight) -3
             (fix
               (* 100
                 (if (and lineweight (<= 0.0 lineweight 2.11)) lineweight 0.0)
               )
             )
           )
         )
       )
       (if description
         (list
           (list -3
             (list "AcAecLayerStandard" (cons 1000 "") (cons 1000 description))
           )
         )
       )
     )
   )
 )
)

(defun c:XT nil (vl-load-com)

 ;; © Lee Mac 2010
 ;; Specifications:
 ;; Description        Data Type        Remarks
 ;; -----------------------------------------------------------------
 ;; Layer Name          STRING          Only standard chars allowed
 ;; Layer Colour        INTEGER         may be nil, -ve for Layer Off, Colour < 256
 ;; Layer Linetype      STRING          may be nil, If not loaded, CONTINUOUS.
 ;; Layer Lineweight    REAL            may be nil, negative=Default, otherwise 0 <= x <= 2.11
 ;; Plot?               BOOLEAN         T = Plot Layer, nil otherwise
 ;; Bit Flag            INTEGER         0=None, 1=Frozen, 2=Frozen in VP, 4=Locked
 ;; Description         STRING          may be nil for no description
 ;; Function will return list detailing whether layer creation is successful.    
 (
   (lambda ( lst / lts ) (setq lts (vla-get-Linetypes (vla-get-ActiveDocument (vlax-get-acad-object))))
     (mapcar 'cons (mapcar 'car lst)
       (mapcar
         (function
           (lambda ( x )
             (and (caddr x)
               (or (tblsearch "LTYPE" (caddr x))
                 (vl-catch-all-apply 'vla-load (list lts (caddr x) "acad.lin"))
               )
             )
             (apply 'MakeLayer x)
           )
         )
         lst
       )
     )
   )
  '(
   ;  Name             Colour       Linetype               Lineweight     Plot?  Bitflag       Description 
   ( "Layer1"         5          "CONTINUOUS"            0.50             T      0              nil )
   ( "Layer2"         6          "ACAD_ISO04W100"     0.18             T      0              nil )
   ( "Layer3"         7          "CONTINUOUS"            0.35             T      0              nil )
   ( "Layer4"         40         "CONTINUOUS"           0.35             T      0              nil )
   ( "Layer5"         4          "DASHEDx2"                0.18             T      0              nil )
   ( "Layer6"         3          "CONTINUOUS"            0.15             T      0              nil )
   ( "Layer7"         11         "CONTINUOUS"           0.15             T      0              nil )
   ( "Layer8"         2          "CONTINUOUS"            0.35             T      0              nil )
   ( "Layer9"         1          "CONTINUOUS"            0.20             T      0              nil )
   )
 )
)

and this is to changing the layers

(defun _SetCLayer (layerName)
 (if (tblsearch "layer" layerName)
   (setvar 'clayer layerName)
   (prompt
     (strcat "\n** Layer \"" layerName "\" not found ** ")
   )
 )
 (princ)
)

(defun c:1 () (_SetCLayer "Layer1"))
(defun c:2 () (_SetCLayer "Layer2"))
(defun c:3 () (_SetCLayer "Layer3"))
(defun c:4 () (_SetCLayer "Layer4"))
(defun c:5 () (_SetCLayer "Layer5"))
(defun c:6 () (_SetCLayer "Layer6"))
(defun c:7 () (_SetCLayer "Layer7"))
(defun c:8 () (_SetCLayer "Layer8"))
(defun c:9 () (_SetCLayer "Layer9"))

Link to comment
Share on other sites

How can make similar code for changing layers but I want when select a object to pres 1 or 2 or 3 etc. and selected object to change in this layer.

Link to comment
Share on other sites

Simplest way is to still do defuns 1 for a single 1M or 1m for multiples 1 example shown

 

(defun c:1 ( / obj ) 
(setq obj (entsel "\nPick object"))
(command "CHPROP" obj "" "LA" "1" "")
)

Link to comment
Share on other sites

This is not working for me because I use 1,2,3,4,5,6,7,8 and 9 for switching between layers. Can it be modify to work when is selected object (step 1 select obcject; step 2 press 1,2,3,4,5,6,7,8 and 9 and press enter to change object layer)

Link to comment
Share on other sites

There is a nice lisp that pick object it sets to layer and invokes the object as a command so pick a line and it asks for you to create a line. I will try to find it. We don't do repeat stuff or else would use all the time.

 

I still think using a menu or toolbars would be easier.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...