Author Topic: Layer Creation with VLISP  (Read 2764 times)

0 Members and 1 Guest are viewing this topic.

stusic

  • Guest
Layer Creation with VLISP
« on: April 25, 2012, 09:10:45 AM »
I've got a lisp borrowed from Tim Spangler on the Catalyst forums that automagically creates layers from a list, but I can't get it to work (error: bad argument type: VLA-OBJECT nil). I'm not very good at vl at all, so I could just be going about it wrong; maybe someone here can help me.

Thanks a bunch!

Here is the original code:
Code: [Select]
;;; ------------ LAYER CREATION ROUINE
(defun CREATE_LAYER (Layer Descpition Linetype Thickness Color Plot / VLA-Obj)

;;; ------------ CREATE A LIST FOR ENTMAKE
(entmakex
(list
(cons 0 "LAYER")
(cons 100 "AcDbSymbolTableRecord")
(cons 100 "AcDbLayerTableRecord")
(cons 70 0)
(cons 2 Layer)
(cons 62 (atoi Color))
(cons 6 Linetype)
(cons 370 (atoi Thickness))
(cons 290 (atoi Plot))
)
)
;; Create layer description
(if (>= (atof (getvar "acadver")) 16.1)
(progn
(setq VLA-Obj (vla-Add LayersCol Layer))
(vla-Put-Description VLA-Obj Descpition)
(vlax-release-object VLA-Obj)
)
)
)

With this as the call:
Code: [Select]
(CREATE_LAYER "purlin" "description" "continuous" "thickness" "color" "plot")
Here's how I've modified it:
Code: [Select]
;;; Layer Creation Routine
(defun CreateLayers (Layer Descpition Linetype Thickness Color Plot / VLA-Obj)

;;; ------------ CREATE A LIST FOR ENTMAKE
(entmakex
(list
(cons 0 "LAYER")
(cons 100 "AcDbSymbolTableRecord")
(cons 100 "AcDbLayerTableRecord")
(cons 70 0)
(cons 2 Layer)
(cons 62 (atoi Color))
(cons 6 Linetype)
(cons 370 (atoi Thickness))
(cons 290 (atoi Plot))
)
)
;; Create layer description
(if (>= (atof (getvar "acadver")) 16.1)
(progn
(setq VLA-Obj (vla-Add LayersCol Layer))
(vla-Put-Description VLA-Obj Descpition)
(vlax-release-object VLA-Obj)
)
)
)

;;; The call:
;;; (CreateLayers "layer-name" "description" "continuous" "thickness (05=.05,-3 default)" "color" "plot (0/1)")
(CreateLayers "TAGS" "description" "continuous" "-3" "3" "1")
(CreateLayers "COPPER" "description" "continuous" "-3" "30" "1")
(CreateLayers "M-ACCY" "description" "continuous" "-3" "4" "1")
(CreateLayers "M-EQUIP" "description" "continuous" "-3" "6" "1")
(CreateLayers "M-NOTES" "description" "continuous" "-3" "1" "1")
(CreateLayers "M-PIPING" "description" "continuous" "-3" "7" "1")
(CreateLayers "M-PIPING-HG" "description" "continuous" "-3" "2" "1")
(CreateLayers "M-PIPING-HR" "description" "continuous" "-3" "4" "1")
(CreateLayers "M-PIPING-INS-1-0" "description" "TRACKS" "-3" "5" "1")
(CreateLayers "M-PIPING-INS-1-2" "description" "ZIGZAG" "-3" "7" "1")
(CreateLayers "M-PIPING-INS-3-4" "description" "continuous" "-3" "5" "1")
(CreateLayers "M-PIPING-LIQ" "description" "continuous" "-3" "7" "1")
(CreateLayers "M-PIPING-OIL" "description" "continuous" "-3" "2" "1")
(CreateLayers "M-PIPING-SUCT" "description" "continuous" "-3" "5" "1")
(CreateLayers "M-SOW" "description" "DASHED2" "-3" "15" "1")
(CreateLayers "M-SYMB" "description" "continuous" "-3" "81" "1")
(CreateLayers "M-VALVE" "description" "continuous" "-3" "3" "1")

Chris

  • Swamp Rat
  • Posts: 548
Re: Layer Creation with VLISP
« Reply #1 on: April 25, 2012, 09:18:30 AM »
perhaps the issue is this line
Code: [Select]
(setq VLA-Obj (vla-Add LayersCol Layer))
I dont see a line of code that defines LayersCol as a vla object
try adding this above
Code: [Select]
(setq LayersCol (vla-get-layers (vla-get-ActiveDocument (vlax-get-acad-object))))
Christopher T. Cowgill, P.E.
AEC Collection 2020 (C3D)
Win 10

stusic

  • Guest
Re: Layer Creation with VLISP
« Reply #2 on: April 25, 2012, 09:38:15 AM »
Oh, that's wonderful.

I knew it was that LayersCol wasn't defined, but I had no idea what I needed to do to define it.

Thanks a heap!

BlackBox

  • King Gator
  • Posts: 3770
Re: Layer Creation with VLISP
« Reply #3 on: April 25, 2012, 10:02:18 AM »
I've got a lisp borrowed from Tim Spangler on the Catalyst forums that automagically creates layers from a list, but I can't get it to work (error: bad argument type: VLA-OBJECT nil). I'm not very good at vl at all, so I could just be going about it wrong; maybe someone here can help me.

I love that one of my favorite words is gaining popularity.  :lol:

** Edit - Oh, and welcome to TheSwamp, Stusic!
« Last Edit: April 25, 2012, 10:09:41 AM by RenderMan »
"How we think determines what we do, and what we do determines what we get."

stusic

  • Guest
Re: Layer Creation with VLISP
« Reply #4 on: April 25, 2012, 10:22:38 AM »
** Edit - Oh, and welcome to TheSwamp, Stusic!

Thanks!  :mrgreen: (sorry, there's no :beer: emoticon)

BlackBox

  • King Gator
  • Posts: 3770
Re: Layer Creation with VLISP
« Reply #5 on: April 25, 2012, 10:29:12 AM »
** Edit - Oh, and welcome to TheSwamp, Stusic!

Thanks!  :mrgreen: (sorry, there's no :beer: emoticon)

No worries;


"How we think determines what we do, and what we do determines what we get."

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Layer Creation with VLISP
« Reply #6 on: April 25, 2012, 11:02:01 AM »
This is the last version I could find here:
http://www.theswamp.org/index.php?topic=37566.msg425820#msg425820

Just to be sure you have the latest version.
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.