Author Topic: What is wrong with this code, it is driving me nuts  (Read 2068 times)

0 Members and 1 Guest are viewing this topic.

cadman6735

  • Guest
What is wrong with this code, it is driving me nuts
« on: January 13, 2016, 09:34:28 AM »
I can't figure out why this won't work,


Code: [Select]
(defun mlay (Lname Lcolor Ltype Lweight / )

  (entmake (list (cons 0 "LAYER") ; Entitiy Name
(cons 100 "AcDbSymbolTableRecord") ; Class
(cons 100 "AcDbLayerTableRecord") ; SubClass
(cons 2 Lname) ; Layer Name
(cons 62 Lcolor) ; Color
(cons 6 Ltype) ; Line Type
(cons 370 Lweight) ; Line Weight
   )
  ) 

(princ)
)

(defun c:test ( / )

  (mLay "trash" 4 "Continous" "0.18")

(princ)
)

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: What is wrong with this code, it is driving me nuts
« Reply #1 on: January 13, 2016, 09:39:40 AM »
Gc 370 requires an integer value. Use 18 instead of "0.18".

cadman6735

  • Guest
Re: What is wrong with this code, it is driving me nuts
« Reply #2 on: January 13, 2016, 09:47:08 AM »
Hi Roy

I have tried that and no layer is created, no errors either, just does nothing

Code: [Select]
[/(defun mlay (Lname Lcolor Ltype Lweight / )

  (entmake (list (cons 0 "LAYER") ; Entitiy Name
(cons 100 "AcDbSymbolTableRecord") ; Class
(cons 100 "AcDbLayerTableRecord") ; SubClass
(cons 2 Lname) ; Layer Name
(cons 62 Lcolor) ; Color
(cons 6 Ltype) ; Line Type
(cons 370 Lweight) ; Line Weight, (Omit for Default)
   )
  ) 

(princ)
)

(defun c:test ( / )

  (mLay "trash" 4 "Continuous" 18)

(princ)
)code]


---edit---

I caught my misspelling for "Continuous" and still nothing
« Last Edit: January 13, 2016, 09:50:47 AM by cadman6735 »

cgeorg13

  • Guest
Re: What is wrong with this code, it is driving me nuts
« Reply #3 on: January 13, 2016, 09:55:24 AM »
https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/layer-creation-with-entmake/td-p/2648118


Looks like from this forum the DXF 70 is required
just tested and this works.
Code: [Select]
(defun mlay (Lname Lcolor Ltype Lweight / )

  (entmake (list (cons 0 "LAYER") ; Entitiy Name
(cons 100 "AcDbSymbolTableRecord") ; Class
(cons 100 "AcDbLayerTableRecord") ; SubClass
(cons 2 Lname) ; Layer Name
(cons 62 Lcolor) ; Color
(cons 6 Ltype) ; Line Type
(cons 370 Lweight) ; Line Weight
(cons 70 0)
   )
  ) 

(princ)
)
(defun c:test ( / )

  (mLay "trash" 4 "Continuous" 18)

(princ)
)

cgeorg13

  • Guest
Re: What is wrong with this code, it is driving me nuts
« Reply #4 on: January 13, 2016, 10:01:57 AM »
you can find a description of the layer DXF codes http://www.autodesk.com/techpubs/autocad/acad2000/dxf/layer_dxf_04.htm

cadman6735

  • Guest
Re: What is wrong with this code, it is driving me nuts
« Reply #5 on: January 13, 2016, 10:10:32 AM »
Thanks, I deleted that from my template, I have now noted it as needed

cgeorg, thanks for the link, this now saved

cgeorg13

  • Guest
Re: What is wrong with this code, it is driving me nuts
« Reply #6 on: January 13, 2016, 10:13:03 AM »
No problem, Glad I could help!

Best Wishes,
Caleb

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: What is wrong with this code, it is driving me nuts
« Reply #7 on: January 13, 2016, 10:41:14 AM »
This post may help: Creating Layers using entmake

HasanCAD

  • Swamp Rat
  • Posts: 1421
Re: What is wrong with this code, it is driving me nuts
« Reply #8 on: January 13, 2016, 10:41:40 AM »
First it is better to add this part of code
Code - Auto/Visual Lisp: [Select]
  1. (regapp "AcAecLayerStandard")

2nd
give this a try
Code - Auto/Visual Lisp: [Select]
  1. (defun MakeLayer ( name colour linetype lineweight willplot bitflag description )
  2.   (regapp "AcAecLayerStandard")
  3.     ;; (MakeLayer name colour linetype lineweight willplot bitflag description )
  4.     ;; Specifications:
  5.     ;; Description        Data Type        Remarks
  6.     ;; -----------------------------------------------------------------
  7.     ;; Layer Name          STRING          Only standard chars allowed
  8.     ;; Layer Colour        INTEGER         may be nil, -ve for Layer Off, Colour < 256
  9.     ;; Layer Linetype      STRING          may be nil, If not loaded, CONTINUOUS.
  10.     ;; Layer Lineweight    REAL            may be nil, 0 <= x <= 2.11
  11.     ;; Plot?               BOOLEAN         T = Plot Layer, nil otherwise
  12.     ;; Bit Flag            INTEGER         0=None, 1=Frozen, 2=Frozen in VP, 4=Locked
  13.     ;; Description         STRING          may be nil for no description
  14.     ;; Function will return list detailing whether layer creation is successful.
  15.  
  16.     ;; © Lee Mac 2010
  17.   (or (tblsearch "LAYER" name)
  18.     (entmake
  19.       (append
  20.         (list
  21.           (cons 0       "LAYER")
  22.           (cons 100     "AcDbSymbolTableRecord")
  23.           (cons 100     "AcDbLayerTableRecord")
  24.           (cons 2       name)
  25.           (cons 70      bitflag)
  26.           (cons 290     (if willplot 1 0))
  27.           (cons 6       (if (and linetype (tblsearch "LTYPE" linetype)) linetype "CONTINUOUS"))
  28.           (cons 62      (if (and colour (< 0 (abs colour) 256)) colour 7))
  29.           (cons 370     (fix (* 100 (if (and lineweight (<= 0.0 lineweight 2.11)) lineweight 0.0))))
  30.           )
  31.         (if description (list (list -3 (list "AcAecLayerStandard" (cons 1000 "") (cons 1000 description)))))
  32.         ))))

cadman6735

  • Guest
Re: What is wrong with this code, it is driving me nuts
« Reply #9 on: January 13, 2016, 10:59:18 AM »
Thanks Lee and Hasan

Lee very informative post, I have saved it to my "LeeMac" folder, I hope that doesn't sound creepy.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: What is wrong with this code, it is driving me nuts
« Reply #10 on: January 13, 2016, 12:22:42 PM »
Lee very informative post, I have saved it to my "LeeMac" folder, I hope that doesn't sound creepy.

Not at all  :-P

You're most welcome cadman, glad it helps!