Jump to content

Layer Lisp


awill81

Recommended Posts

I'm not too fluent with lisp so I was hoping someone could help me with creating a layer update lisp. We have old drawings that have old layers and we use them on newer projects. I want to create a lisp that can rename old layers that have the same lineweight, color, and linetype to the newer later name. And I think I'd need some if statements for if those newer layers already exist or if any of the older layers don't exist, it creates the new layer. Any help would be appreciated.

Link to comment
Share on other sites

  • Replies 45
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    18

  • N_461

    15

  • alanjt

    8

  • antistar

    2

Top Posters In This Topic

  • 1 year later...

Hi this is exactly what I've been looking for. I am new to lisp's and we are trying to get a template going. I think that lsip routines are the way to go. I sort of understand your link, but could you explain it a little? I'd be looking for just the new layer part, and i take it one would fill in the magenta type? Im a little confused on which part creates the layer and which changes the old layer to the new.

 

thanks!

Link to comment
Share on other sites

My code will just create new layers using the subfunction 'MkLay' - which takes a layer name, colour, Linetype, Lineweight, and whether the layer is plottable - it will not amend existing layers.

 

I use mapcar in the main function to iterate the subfunction through a list of layer names/colours/lineweights etc. This is an old code and could most probably be written much better however.

Link to comment
Share on other sites

  • 2 weeks later...

This works great.

 

I'm wondering about the spacing between each layer name and the respective colour code, linetype, etc.-- is there a specific number or is it good as long as they are under each other in relative columns??

I'm just using notepad to do my editing....

Link to comment
Share on other sites

  • 1 month later...

Hey Lee, I've populated the lisp to create a specific layerset. My questions:

HOW do I set ALL layer properties? I have colour, LT, LW, Plotable, but can i set the layer to be frozen/thawed, on/off, locked?

Can i input layer descriptions?

 

...thanks a tonne! Im actually learning....a bit...:?

Link to comment
Share on other sites

That's pretty old code,

 

Perhaps try this instead:

 

(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
           (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:MakeLayers ( )
 ;; © Lee Mac 2010
 (
   (lambda ( lst )
     (mapcar 'cons (car lst) (apply 'mapcar (cons 'MakeLayer lst)))
   )
  '(          
     ( "CEN"   "DIMS"   "HAT"  "HID"   "LOGO" "OBJ"  "PAPER"   "PHAN"   "TITLE" "TXT" )  ; Layer Name                       [ STR   ]
     (   6      -1        3      4       176   -2       5         6       176     7   )  ; Layer Colour (-ve for layer off) [ INT   ]
     ("CENTER"  nil      nil  "HIDDEN"   nil   nil  "PHANTOM" "PHANTOM"   nil    nil  )  ; Layer LineType                   [ STR   ]
     (  0.18   0.18      0.18   0.15    0.09   0.40    nil      0.18      nil    nil  )  ; Layer LineWeight                 [ REAL  ]
     (   T       T        T      T        T     T      nil        T        T      T   )  ; Plot? (T or nil)                 [ BOOLE ]
     (   0       1        5      0        0     3       6         0        1      0   )  ; Bit Flag (0 = None, 1=Frozen, 2=Frozen in Vp, 4=Locked) [ INT ]
     (  nil "Dimensions" nil "Hidden""For Logo" nil    nil      nil  "For Title"  nil )  ; Description (nil for none)    [ STR   ]
   )
 )
)

 

Linetypes must already be loaded, all arguments in list must be of correct type and range.

 

Success of layer creation will be displayed in resultant list.

 

Lee

Link to comment
Share on other sites

Wouldn't this be easier to deal with and edit?

 

(defun c:Foo nil
 (mapcar '(lambda (x) (apply 'MakeLayer x))
         '(("CEN" 6 "CENTER" 0.18 T 0 nil)
           ("DIMS" -1 nil 0.18 T 1 "Dimensions")
          )
 )
 (princ)
)

Link to comment
Share on other sites

seems simpler, i'll try that too

 

Both will function identically, however the layout of Alan's code is easier to manage as easier layer has its own entry in the list.

 

Lee

Link to comment
Share on other sites

How do you execute the routine? I'd need it to load on command, as Lee's did. Im sure its a simple fix, but i tried a few things and kept getting errors...

thanks!

 

 

Wouldn't this be easier to deal with and edit?

 

(defun c:Foo nil
 (mapcar '(lambda (x) (apply 'MakeLayer x))
         '(("CEN" 6 "CENTER" 0.18 T 0 nil)
           ("DIMS" -1 nil 0.18 T 1 "Dimensions")
          )
 )
 (princ)
)

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...