Author Topic: List to create layer or midify exist create gives error  (Read 1381 times)

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1421
List to create layer or midify exist create gives error
« on: January 15, 2017, 01:48:55 PM »
Based on lee's code I created a lisp to create a layer if not exist and redfine if exist.
when run
Code - Auto/Visual Lisp: [Select]
  1. (lyrmk "test" 3 "Hidden" "018" t 30 "Test-Test")
the lisp work great put with mapcar and lambda gives error

The error
Code: [Select]
; error: ActiveX Server returned an error: Parameter not optional
Code - Auto/Visual Lisp: [Select]
  1. (DEFUN C:TEST ( / a b c d e f g)
  2.   (mapcar
  3.     '(lambda (a b c d e F G) (lyrmk a b c d e f g))
  4.     '("A-GRID" "A-GRID-OUT" "A-MTRL-FBRC") ; Name       [Str]
  5.     '(10 21 20 ) ; Colours      [Int]
  6.     '("CENTER2" "CENTER2" "Continuous") ; LineType      [Str]
  7.     '("015" "015" "018" ) ; LineWeight  [Str] 0.18 = "018"
  8.     '(T T T ) ; Plottable       (T or nil)
  9.     '(0 0 0 ) ; Transperency (<0 tp 90>)
  10.     '("Planning" "Planning" "Windows")
  11.     )
  12.   )
  13.  
  14. (defun lyrmk (Nme Col lTyp lWgt Plt trns dsc / lay lyrs cmd) ;lee mac
  15.   ;http://www.cadtutor.net/forum/showthread.php?36882-Check-create-layer-issue-in-Lisp&p=243520&viewfull=1#post243520
  16.   (setq cmd (getvar 'cmdecho))
  17.   (setvar 'cmdecho 0)  
  18.   (if (not (tblsearch "LTYPE" Nme))
  19.     (progn
  20.       (setq lay (vla-add lyrs Nme))
  21.       (mdfy)
  22.     )
  23.     (progn
  24.       (mdfy)
  25.     )
  26.   )
  27.   (setvar 'cmdecho cmd)
  28. )
  29.  
  30. (defun lTload (lTyp)
  31.   (or (tblsearch "LTYPE" lTyp)
  32.                 lTyp
  33.                 "acad.lin")))
  34.  
  35. (defun mdfy (/)
  36.   (setq entVL (vlax-ename->vla-object (tblobjname "LAYER" Nme)))  
  37.   (and Col (vla-put-Color entVL Col))
  38.   (and lTyp (lTload lTyp) (vla-put-Linetype entVL lTyp))
  39.   (and lWgt (vla-put-LineWeight entVL (eval (read (strcat "acLnWt" lWgt)))))
  40.   (and (not Plt) (vla-put-Plottable entVL :vlax-false))
  41.   (and (setq LyrDs (vlax-put-property entVL 'Description dsc)))
  42.   (setq rtns (vl-cmdf "_.-layer" "_TR" trns Nme ""))
  43. )

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: List to create layer or midify exist create gives error
« Reply #1 on: January 15, 2017, 02:38:18 PM »
mapcar is not the best tool for the task, foreach in concert with apply would be a more appropriate fit.

Code: [Select]
(foreach args

   '(
        ("A-GRID"      10 "CENTER2"    "015" T 0 "Planning")
        ("A-GRID-OUT"  21 "CENTER2"    "015" T 0 "Planning") 
        ("A-MTRL-FBRC" 20 "Continuous" "018" T 0 "Windows")   
    )       
   
    (apply 'lyrmk args)

)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: List to create layer or midify exist create gives error
« Reply #2 on: January 15, 2017, 03:40:13 PM »
On line 19 change:
Code: [Select]
(tblsearch "LTYPE" Nme)To:
Code: [Select]
(tblsearch "LAYER" Nme)

HasanCAD

  • Swamp Rat
  • Posts: 1421
Re: List to create layer or midify exist create gives error
« Reply #3 on: January 15, 2017, 04:55:35 PM »
Thanks MP
Thanks roy_043

the code runs one time good but gives the same error
I animated the code gives error on 42 when editing lineweight.
Code - Auto/Visual Lisp: [Select]
  1.   (and lWgt (vla-put-LineWeight entVL (eval (read (strcat "acLnWt" lWgt)))))
« Last Edit: January 15, 2017, 05:07:55 PM by HasanCAD »

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: List to create layer or midify exist create gives error
« Reply #4 on: January 16, 2017, 04:16:09 AM »
I cannot reproduce this. Maybe you have an invalid value for 'lWgt' in the latest version of your code?

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Re: List to create layer or midify exist create gives error
« Reply #5 on: January 16, 2017, 07:55:00 AM »
I created some code you may be interested in. It is very quick and makes new layers and redefines ones that are not correct. It reads all the layer information from a file and it even has a method to save drawing layer settings. [ https://www.theswamp.org/index.php?topic=23173.msg291095#msg291095 ]

It never made it past the "concept" stage but, honestly, it is more then safe to use (I just labeled it `concept' because I never got more then a few minutes at a time to work on it so I didn't get a lot of time to look for bugs and/or better methods).
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org