That was an old code, with the skills I've gained from this forum I managed to write this:
- (defun C:test ( / MyLayerList )(setq MyLayerList '( ("Layername1" "RGB" nil 40 120 160 "Continuous" 50 1) ("Layername2" "RGB" nil 40 120 160 "Continuous" 50 1) ("Layername3" "RGB" nil 40 120 160 "Continuous" 50 1) ("Layername4" "TableCol" 150 nil nil nil "Continuous" 50 0) ("Layername5" "TableCol" 150 nil nil nil "Continuous" 50 0) ("Layername6" "TableCol" 150 nil nil nil "Continuous" 50 0) )); vl-catch-all-apply(foreach L MyLayerList (VLA:CreateLayer (nth 0 L) (nth 1 L) (nth 2 L) (nth 3 L) (nth 4 L) (nth 5 L) (nth 6 L) (nth 7 L) (nth 8 L) ))(princ)); Subfunction to create new layer using VLA method; Example1: (VLA:CreateLayer "Layername1" "RGB" nil 40 120 160 "Continuous" 50 1); Example1: (VLA:CreateLayer "Layername1" "TableCol" 150 nil nil nil "Continuous" 50 0)(defun VLA:CreateLayer ( LAYNAME1 ColMethod TableCol R G B LinT LinW Plt / )(vl-load-com)(setq acadobj (vlax-get-Acad-Object))(setq activedoc (vla-get-activedocument acadobj));(setq extdic (vla-GetExtensionDictionary))(setq LayerTable (vla-get-layers activedoc))(setq WILDCARD-VLD "VLD_") ;WILDCARD for the layer(setq LAYNM1-WILDCARD (strcat WILDCARD-VLD LAYNAME1)) ;Total name (with wildcard)(if (not (tblsearch "LAYER" LAYNM1-WILDCARD)) (progn (setq aNewLayer (vla-add LayerTable LAYNM1-WILDCARD)) (cond ( (= ColMethod "RGB") (setq color (vlax-create-object "AutoCAD.AcCmColor.20")) ; for truecolor RGB (vla-SetRGB color R G B) ; for truecolor RGB (vla-put-TrueColor aNewLayer color) ; for truecolor RGB ; put semicoma here ) ( (= ColMethod "TableCol") (vla-put-color aNewLayer TableCol) ; for table color ; or put semicoma here ) ) (vla-put-linetype aNewLayer LinT) (vla-put-LineWeight aNewLayer LinW) (cond ( (= plt 1) (vla-put-plottable aNewLayer :vlax-true) ) ( (= plt 0) (vla-put-plottable aNewLayer :vlax-false) ) ) (princ (strcat "\nCreated layer named " LAYNM1-WILDCARD " !")) ) (princ (strcat "\n " LAYNM1-WILDCARD " layer already exists!" )));if)
But still my question remains - how to avoid this Automation Error. Key not found ?
Is it possible to get it in my 2nd consideration (code) ?
EDIT:
Hi Tharwat, I just saw your post
I think that might be the problem - I'm trying to load some ACAD_ISO03W100 linetypes that are not loaded in the drawing. Thanks! |