Author Topic: Making layers by lisp  (Read 5911 times)

0 Members and 1 Guest are viewing this topic.

Fabricio28

  • Swamp Rat
  • Posts: 670
Making layers by lisp
« on: May 20, 2014, 09:32:00 AM »
Hi guys,
I'm trying the make layers. That code isn't working properly.
Can anybody help me out, please?

Code: [Select]
(defun c:mkl()
  (makelayer)
    (setq layername     "-AUXILIAR"
          colornum      4
          linetype      "CONTINUOUS"
    )
   (makelayer)
   (setq layername     "-CERCA"
          colornum      5
          linetype      "CERCA"
    )
    (makelayer)
    (setq layername     "-CN-MM"
          colornum     251
          linetype      "CONTINUOUS"
    ) 
    (makelayer)
    (setq layername     "-CN-5-5M"
          colornum      30
          linetype      "CONTINUOUS"
    )
   (makelayer) 
   (setq layername     "-CONFRONTANTES"
          colornum      1
          linetype      "CONTINUOUS"
    )
   (makelayer)
    (setq layername     "-CONSTRUÇÕES"
          colornum      140
          linetype      "CONTINUOUS"
    )
  (makelayer)
  (setq layername     "-COTAS"
          colornum      5
          linetype      "CONTINUOUS"
    )
  (makelayer)
  (setq layername     "-DETALHES"
          colornum      5
          linetype      "CONTINUOUS"
    )
  (makelayer)
    (setq layername     "-MARGEM"
          colornum      7
          linetype      "CONTINUOUS"
    )
  (makelayer)
  (setq layername     "-MEDIDAS"
          colornum      4
          linetype      "CONTINUOUS"
    )
  (makelayer)
  (setq layername     "-NRO-DIVISA"
          colornum      2
          linetype      "CONTINUOUS"
    )
    (makelayer)
    (setq layername     "-PASSEIO"
          colornum      3
          linetype      "PHANTOM"
    )
  (makelayer)
    (setq layername     "-TERRENO"
          colornum      180
          linetype      "CONTINUOUS"
    )
  (makelayer)
    (setq layername     "LIXO"
          colornum      7
          linetype      "CONTINUOUS"
    )
    (princ)
); mkl
(defun makelayer()
    (command "layer"
             "m"
             layername
             "c"
             colornum
             layername
             "lt"
             linetype
             layername
             "s"
              "0"
               ""
    )
)
(princ "\nStandard Layers Created...\n")
(mkl)

Thank in advance


tedg

  • Swamp Rat
  • Posts: 811
Re: Making layers by lisp
« Reply #1 on: May 20, 2014, 09:54:38 AM »
What is not working? I didn't try your code but your screen shot appears to have the layers the way you intend?
The VLisp stuff is a bit over my head, I dabble with Autolisp to create layers, I just haven't made that leap yet.
Code: [Select]

(setq la (getvar "clayer"))
 (SETQ LR1 (TBLSEARCH "LAYER" "S-DETL-0035"))
 (SETQ LR2 (TBLSEARCH "LAYER" "S-ANNO-NPLT"))
 (SETQ LR3 (TBLSEARCH "LAYER" "S-DETL-CNTR"))
  (IF (= LR1 NIL) 
  (command "layer" "make" "S-DETL-0035" "color" "3" "" "lw" "0.35" "" ""))
  (IF (= LR2 NIL)
  (command "layer" "make" "S-ANNO-NPLT" "COLOR" "140" "" "PLOT" "N" "" "lw" "0.18" "" ""))
  (IF (= LR3 NIL)
  (command "layer" "make" "S-DETL-CNTR" "COLOR" "1" "" "lw" "0.18" "" "LT" "CENTER2" "" ""))
Windows 10 Pro 64bit, AutoCAD 2023, REVIT 2023

Fabricio28

  • Swamp Rat
  • Posts: 670
Re: Making layers by lisp
« Reply #2 on: May 20, 2014, 09:58:29 AM »
Hi tedg,
Thank you for the quick replay.
The image attached is the exactly I want to, it is just an exemple of my request.

Could you help me out with my code?

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Making layers by lisp
« Reply #3 on: May 20, 2014, 10:09:15 AM »
Most likely your trying to push a linetype to a layer that does not exist in the drawing. FWIW  .. here's how I'd restructure your code.

You also might want to get away from the command call to create the layer (or just use a template). There are numerous examples here to create layers using entmakex. Clickety

Code: [Select]
(defun c:mkl (/ makelayer)
  (defun layermake (lyrname color ltype)
    (if   (tblsearch "LAYER" lyrname)
      (command "._Layer" "_Thaw" lyrname "_On" lyrname "_UnLock" lyrname "_Set" lyrname "")
      (command "._Layer"
          "_Make"
          lyrname
          "_Color"
          (if (or (null color) (= color ""))
       "_White"
       color
          )
          lyrname
          "LT"
          (if (or (null ltype) (= ltype ""))
       "Continuous"
       ltype
          )
          lyrname
          ""
      )
    )
  )
  (foreach x '(("-AUXILIAR" 4 "CONTINUOUS")
          ("-CERCA" 5 "CERCA")
          ("-CN-MM" 251 "CONTINUOUS")
          ("-CN-5-5M" 30 "CONTINUOUS")
          ("-CONFRONTANTES" 1 "CONTINUOUS")
          ("-CONSTRUÇÕES" 140 "CONTINUOUS")
          ("-COTAS" 5 "CONTINUOUS")
          ("-DETALHES" 5 "CONTINUOUS")
          ("-MARGEM" 7 "CONTINUOUS")
          ("-MEDIDAS" 4 "CONTINUOUS")
          ("-NRO-DIVISA" 2 "CONTINUOUS")
          ("-PASSEIO" 3 "PHANTOM")
          ("-TERRENO" 180 "CONTINUOUS")
          ("LIXO" 7 "CONTINUOUS")
         )
    (layermake (car x) (cadr x) (caddr x))
  )
  (princ "\nStandard Layers Created...\n")
)
« Last Edit: May 20, 2014, 10:41:54 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Making layers by lisp
« Reply #4 on: May 20, 2014, 10:13:37 AM »
Here is my simple layer creator:
Code - Auto/Visual Lisp: [Select]
  1. (defun LayerMake(lyrname Color ltype)
  2.   (if (tblsearch "LAYER" lyrname)
  3.     (command "._Layer" "_Thaw" lyrname "_On" lyrname "_UnLock" lyrname "_Set" lyrname "")
  4.     (command "._Layer" "_Make" lyrname "_Color"
  5.              (if (or (null color)(= Color "")) "_White" Color) lyrname
  6.              "LT" (if (or (null ltype)(= ltype "")) "Continuous" ltype) lyrname "")
  7.   )
  8. )
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Fabricio28

  • Swamp Rat
  • Posts: 670
Re: Making layers by lisp
« Reply #5 on: May 20, 2014, 10:20:55 AM »
ronjonp
your code just create AUXILIAR layer. Am I doing something wrong?

CAB
I don't know how Can I create layers using your code.
Coul you help me, please?

regards

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Making layers by lisp
« Reply #6 on: May 20, 2014, 10:35:37 AM »
ronjonp
your code just create AUXILIAR layer. Am I doing something wrong?

CAB
I don't know how Can I create layers using your code.
Coul you help me, please?

regards

FABRICIO28,

I did not test your makelayer function, just provided a different way to organize the code. Use CAB's 'LayerMake' function instead of yours.


*code updated above to use Charles function.
« Last Edit: May 20, 2014, 10:41:26 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: Making layers by lisp
« Reply #7 on: May 20, 2014, 10:55:29 AM »
Looks to me like you need to move the (makelayer) call to after the setq's not before as shown, then all should work fine.

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: Making layers by lisp
« Reply #8 on: May 20, 2014, 11:02:56 AM »
Although to simplify it a bit you might do this;

Code - Auto/Visual Lisp: [Select]
  1. (foreach x '(("-AUXILIAR"  4  "CONTINUOUS")
  2.              ("-CERCA"  5  "CERCA")
  3.    )
  4.    (setq layername (car x)
  5.          colornum  (cadr x)
  6.          linetype  (caddr x))
  7.     (makelayer)
  8.  )
  9.  
« Last Edit: May 20, 2014, 11:09:00 AM by snownut2 »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Making layers by lisp
« Reply #9 on: May 20, 2014, 11:03:01 AM »
Something like this
Code - Auto/Visual Lisp: [Select]
  1.     (defun LayerMake(lyrname Color ltype)
  2.      (if (tblsearch "LAYER" lyrname)
  3.        (command "._Layer" "_Thaw" lyrname "_On" lyrname "_UnLock" lyrname "_Set" lyrname "")
  4.        (command "._Layer" "_Make" lyrname "_Color"
  5.                 (if (or (null color)(= Color "")) "_White" Color) lyrname
  6.                 "LT" (if (or (null ltype)(= ltype "")) "Continuous" ltype) lyrname "")
  7.      )
  8.     )
  9.  
  10. (layerMake  "-AUXILIAR"       4  "CONTINUOUS"      )
  11. (layerMake  "-CERCA"   5   "CERCA"                 )
  12. (layerMake  "-CN-MM"  251   "CONTINUOUS"           )
  13. (layerMake  "-CN-5-5M"   30   "CONTINUOUS"         )
  14. (layerMake  "-CONFRONTANTES"   1   "CONTINUOUS"    )
  15. (layerMake  "-CONSTRUÇÕES"   140   "CONTINUOUS"    )
  16. (layerMake  "-COTAS"   5   "CONTINUOUS"            )
  17. (layerMake  "-DETALHES"   5   "CONTINUOUS"         )
  18. (layerMake  "-MARGEM"  7  "CONTINUOUS"             )
  19. (layerMake  "-MEDIDAS"  4  "CONTINUOUS"            )
  20. (layerMake  "-NRO-DIVISA"  2  "CONTINUOUS"         )
  21. (layerMake  "-PASSEIO"  3  "PHANTOM"               )
  22. (layerMake  "-TERRENO"  180  "CONTINUOUS"          )
  23. (layerMake  "LIXO"  7  "CONTINUOUS"                )
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Fabricio28

  • Swamp Rat
  • Posts: 670
Re: Making layers by lisp
« Reply #10 on: May 20, 2014, 11:16:36 AM »
wonderful job CAB!
Thank you very much.  :-D

Thank you all of you guys!!
 :-)

GDF

  • Water Moccasin
  • Posts: 2081
Re: Making layers by lisp
« Reply #11 on: May 20, 2014, 11:23:07 AM »
or you could use:

vla-Put-TrueColor
vla-Put-Linetype
vla-Put-Lineweight
vla-Put-Description
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Making layers by lisp
« Reply #12 on: May 20, 2014, 05:30:06 PM »
This post may also be helpful.