Author Topic: Make layer (Lee Mac)  (Read 3647 times)

0 Members and 1 Guest are viewing this topic.

Sam

  • Bull Frog
  • Posts: 201
Make layer (Lee Mac)
« on: February 24, 2011, 12:48:24 AM »
Dear All
it's possible add GROUP function at this lisp
Code: [Select]
(defun MakeLayer ( name colour linetype lineweight willplot bitflag description )
  ;; © Lee Mac 2010
  (or (tblsearch "LAYER" name)
    (entmake
      (append
        (list
          (cons 0 "LAYER")
          (cons 100 "AcDbSymbolTableRecord")
          (cons 100 "AcDbLayerTableRecord")
          (cons 2  name)
          (cons 70 bitflag)
          (cons 290 (if willplot 1 0))
          (cons 6
            (if (and linetype (tblsearch "LTYPE" linetype))
              linetype "CONTINUOUS"
            )
          )
          (cons 62 (if (and colour (< 0 (abs colour) 256)) colour 7))
          (cons 370
            (fix
              (* 100
                (if (and lineweight (<= 0.0 lineweight 2.11)) lineweight 0.0)
              )
            )
          )
        )
        (if description
          (list
            (list -3
              (list "AcAecLayerStandard" (cons 1000 "") (cons 1000 description))
            )
          )
        )
      )
    )
  )
)

(defun c:MakeLayers nil (vl-load-com)
  ;; © Lee Mac 2010

  ;; Specifications:

  ;; Description        Data Type        Remarks
  ;; -----------------------------------------------------------------
  ;; Layer Name          STRING          Only standard chars allowed
  ;; Layer Colour        INTEGER         may be nil, -ve for Layer Off, Colour < 256
  ;; Layer Linetype      STRING          may be nil, If not loaded, CONTINUOUS.
  ;; Layer Lineweight    REAL            may be nil, 0 <= x <= 2.11
  ;; Plot?               BOOLEAN         T = Plot Layer, nil otherwise
  ;; Bit Flag            INTEGER         0=None, 1=Frozen, 2=Frozen in VP, 4=Locked
  ;; Description         STRING          may be nil for no description

  ;; Function will return list detailing whether layer creation is successful.   

  (
    (lambda ( lst / lts ) (setq lts (vla-get-Linetypes (vla-get-ActiveDocument (vlax-get-acad-object))))
      (mapcar 'cons (mapcar 'car lst)
        (mapcar
          (function
            (lambda ( x )
              (and (caddr x)
                (or (tblsearch "LTYPE" (caddr x))
                  (vl-catch-all-apply 'vla-load (list lts (caddr x) "acad.lin"))
                )
              )
              (apply 'MakeLayer x)
            )
          )
          lst
        )
      )
    )
   '(
     ;    Name        Colour        Linetype        Lineweight        Plot?        BitFlag        Description
     (    "Cen"         6           "CENTER"           0.18            T             0             "Center"   )
     (    "Dim"         8             nil              0.20            T             1           "Dimensions" )
     (    "Ht"         3             nil              0.18            T             5               nil      )
     (    "Hid"         4           "HIDDEN"           0.15            T             0             "Hidden"   )
     (    "Sheet"       176            nil              0.09            T             0            "Sheet"  )
     (    "OBJ"        -2             nil              0.40            T             3               nil      )
     (    "PAPER"       5           "PHANTOM"           nil           nil            6               nil      )
     (    "PHAN"        6           "PHANTOM"          0.18            T             0               nil      )
     (    "TITLE"      176            nil               nil            T             1            "For Title" )
     (    "TX"         7             nil               nil            T             0               "text"     )
    )
  )
)
Every time we waste electricity, we put our planet's future in the dark. Let's turn around our attiude and start saving power and our planet, before it's too late
http://www.theswamp.org/donate.html

Lee Mac

  • Seagull
  • Posts: 12919
  • London, England
Re: Make layer (Lee Mac)
« Reply #1 on: February 26, 2011, 01:13:36 PM »
FYI, I updated that code here - but I'm not sure how to add layer groups  :oops:

MvdP

  • Guest
Re: Make layer (Lee Mac)
« Reply #2 on: May 04, 2011, 02:53:00 AM »
In updated version Layer Description is not added.

Question.

Is it possible to append one ore more list when variables are set.?
Example.
Code: [Select]
(if (= Milayer 1)
(progn
do >list a
))

(if (= stlayer 1)
(progn
do >list a+b
))

(if (= allayer 1)
(progn
do > list a+b+c
))
Code: [Select]
list a
 ( "Cen1" 6 "CENTER"  0.18   T 0 "Center1"   )
 ( "Cen2" 6 "CENTER"  0.25   T 0 "Center2"   )
 ( "Cen3" 6 "CENTER"  0.35   T 0 "Center3"   )

list b
 ( "Dim1" 8  "CENTER" 0.18  T 1 "Dimensions1" )
 ( "Dim2" 8  "CENTER" 0.25  T 1 "Dimensions2" )
 ( "Dim2" 8  "CENTER" 0.35  T 1 "Dimensions3" )

list c
 ( "TXT1"  7 "CENTER"  "CENTER" 0.18  T 1 "text1")
 ( "TXT2"  7 "CENTER"  "CENTER" 0.25  T 1 "text2")
 ( "TXT3"  7 "CENTER"  "CENTER" 0.35  T 1 "tex3t")
« Last Edit: May 04, 2011, 12:05:16 PM by MvdP »

Lee Mac

  • Seagull
  • Posts: 12919
  • London, England
Re: Make layer (Lee Mac)
« Reply #3 on: May 04, 2011, 12:14:18 PM »
Hi,

That code was just an example, not a full program - you'd probably be better to write a program specific to your needs.

Lee