Author Topic: adding layer descriptions while making layers in lisp  (Read 4296 times)

0 Members and 1 Guest are viewing this topic.

John_Gray

  • Guest
adding layer descriptions while making layers in lisp
« on: June 15, 2017, 07:51:09 AM »
Hello everyone, i'm using the below code to make a set of layers, however i'd also like to add a layer desc into the code.  I can't find a DXF code reference for layer descriptions however.  Any suggestions on how i can go about doing this.  Thanks everyone.


Code: [Select]
(defun CreateLayer ( name color ltype lnwt plot )
    (
        (lambda ( _function )
            (_function
                (list
                   '(0 . "LAYER")
                   '(100 . "AcDbSymbolTableRecord")
                   '(100 . "AcDbLayerTableRecord")
                   '(70 . 0)
                    (cons   2 name)
                    (cons   6 (if (tblsearch "LTYPE" ltype) ltype "Continuous"))
                    (cons  62 color)
                    (cons 290 plot)
                    (cons 370 lnwt)
                )
            )
        )
        (if (tblsearch "LAYER" name)
            (lambda ( data ) (entmod (cons (cons -1 (tblobjname "LAYER" name)) data)))
            entmakex
        )
    )
)

(defun c:bakery ( / )
    (foreach item
       '(
;layer name in quotes, layer color, linetype in quotes, lineweight X100, plottable
            ("011001fxeq" 40 "Continuous" 40 1)
            ("011001demo" 40 "Continuous" 40 1)
            ("011001xist" 40 "Continuous" 15 1)
    ("011001relo" 40 "Continuous" 40 1)
        )
        (apply 'CreateLayer item)
    )
    (princ)
)

Thanks everyone, much appreciated,
John Gray

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: adding layer descriptions while making layers in lisp
« Reply #1 on: June 15, 2017, 07:58:13 AM »
Code source

The layer description is stored in the layer xdata - refer to lines 441-490 of my Layer Director application for an example.

John_Gray

  • Guest
Re: adding layer descriptions while making layers in lisp
« Reply #2 on: June 15, 2017, 11:40:28 AM »
Thank you for the quick response.  I've looked at your code and tried replacing the beginning of mine with your suggested lines and can't get it to work.  It's telling me to many arguments.  I tried looking in your code for the area that actually made the layer so that i could use that instead of mine and didn't see anything.  I saw where you'd run a command like "line" and tell it to be on a certain layer, but not make a layer from scratch.  I may just have to live without layer descriptions.  I'll keep working on it if you have more hints for me....

Thanks Lee Mac

John Gray

ronjonp

  • Needs a day job
  • Posts: 7529
Re: adding layer descriptions while making layers in lisp
« Reply #3 on: June 15, 2017, 11:51:56 AM »
Using Lee's code as a base this should do what you want to add layer descriptions:

Code - Auto/Visual Lisp: [Select]
  1. (defun _layer4 (name colour linetype lineweight plot description)
  2.   (if (null (tblsearch "LAYER" name))
  3.     (progn (regapp "AcAecLayerStandard")
  4.            (entmake (list '(0 . "LAYER")
  5.                           '(100 . "AcDbSymbolTableRecord")
  6.                           '(100 . "AcDbLayerTableRecord")
  7.                           '(70 . 0)
  8.                           (cons 2 name)
  9.                           (cons 6
  10.                                 (if (tblsearch "LTYPE" linetype)
  11.                                   linetype
  12.                                   "Continuous"
  13.                                 )
  14.                           )
  15.                           (cons 62 colour)
  16.                           (cons 290 plot)
  17.                           (cons 370 lineweight)
  18.                           (list -3 (list "AcAecLayerStandard" '(1000 . "") (cons 1000 description)))
  19.                     )
  20.            )
  21.     )
  22.   )
  23. )
  24. (_layer4 "TestLayer" 5 "Continuous" 100 1 "My test layer 2")
« Last Edit: June 15, 2017, 11:55:35 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: adding layer descriptions while making layers in lisp
« Reply #4 on: June 15, 2017, 12:31:38 PM »
I've looked at your code and tried replacing the beginning of mine with your suggested lines and can't get it to work.  It's telling me to many arguments.

You'll find that programming tends to be a bit more involved than copying & pasting - you'll need to dissect the code to understand what's going on first, before then applying the knowledge you've gained to your own code.

Vaidas

  • Newt
  • Posts: 66
Re: adding layer descriptions while making layers in lisp
« Reply #5 on: June 15, 2017, 01:19:53 PM »
(vla-Put-Description layer-object "Description")
(mapcar 'chr '(107 105 116 111 120 46 99 111 109))

John_Gray

  • Guest
Re: adding layer descriptions while making layers in lisp
« Reply #6 on: June 15, 2017, 04:00:05 PM »
Though this does work it will no longer overwrite the layers if they are already existing.  The original would overwrite the layers if they existed already changing their setting to what was specified in the lisp routine.  I really need to work that back in somehow....



Using Lee's code as a base this should do what you want to add layer descriptions:

Code - Auto/Visual Lisp: [Select]
  1. (defun _layer4 (name colour linetype lineweight plot description)
  2.   (if (null (tblsearch "LAYER" name))
  3.     (progn (regapp "AcAecLayerStandard")
  4.            (entmake (list '(0 . "LAYER")
  5.                           '(100 . "AcDbSymbolTableRecord")
  6.                           '(100 . "AcDbLayerTableRecord")
  7.                           '(70 . 0)
  8.                           (cons 2 name)
  9.                           (cons 6
  10.                                 (if (tblsearch "LTYPE" linetype)
  11.                                   linetype
  12.                                   "Continuous"
  13.                                 )
  14.                           )
  15.                           (cons 62 colour)
  16.                           (cons 290 plot)
  17.                           (cons 370 lineweight)
  18.                           (list -3 (list "AcAecLayerStandard" '(1000 . "") (cons 1000 description)))
  19.                     )
  20.            )
  21.     )
  22.   )
  23. )
  24. (_layer4 "TestLayer" 5 "Continuous" 100 1 "My test layer 2")


ronjonp

  • Needs a day job
  • Posts: 7529
Re: adding layer descriptions while making layers in lisp
« Reply #7 on: June 15, 2017, 05:07:16 PM »
Though this does work it will no longer overwrite the layers if they are already existing.  The original would overwrite the layers if they existed already changing their setting to what was specified in the lisp routine.  I really need to work that back in somehow....



Using Lee's code as a base this should do what you want to add layer descriptions:

Code - Auto/Visual Lisp: [Select]
  1. (defun _layer4 (name colour linetype lineweight plot description)
  2.   (if (null (tblsearch "LAYER" name))
  3.     (progn (regapp "AcAecLayerStandard")
  4.       (entmake (list '(0 . "LAYER")
  5.            '(100 . "AcDbSymbolTableRecord")
  6.            '(100 . "AcDbLayerTableRecord")
  7.            '(70 . 0)
  8.            (cons 2 name)
  9.            (cons   6
  10.             (if (tblsearch "LTYPE" linetype)
  11.               linetype
  12.               "Continuous"
  13.             )
  14.            )
  15.            (cons 62 colour)
  16.            (cons 290 plot)
  17.            (cons 370 lineweight)
  18.            (list -3 (list "AcAecLayerStandard" '(1000 . "") (cons 1000 description)))
  19.           )
  20.       )
  21.     )
  22.   )
  23. )
  24. (_layer4 "TestLayer" 5 "Continuous" 100 1 "My test layer 2")
You have all the pieces to make it work.
« Last Edit: June 15, 2017, 05:12:55 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

John_Gray

  • Guest
Re: adding layer descriptions while making layers in lisp
« Reply #8 on: June 16, 2017, 02:08:06 PM »
PERFECTO!!!!  thank all for your help it is greatly appreciated. :-D

ahsattarian

  • Newt
  • Posts: 112
Re: adding layer descriptions while making layers in lisp
« Reply #9 on: November 06, 2021, 09:18:46 AM »
This also does the job  :


(setq layerobj (vla-add (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) la))
(vla-put-description layerobj desc)