Jump to content

Layer Lisp


awill81

Recommended Posts

  • Replies 45
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    18

  • N_461

    15

  • alanjt

    8

  • antistar

    2

Top Posters In This Topic

Wouldn't this be easier to deal with and edit?

 

(defun c:Foo nil
(mapcar '(lambda (x) (apply 'MakeLayer x))
'(("CEN" 6 "CENTER" 0.18 T 0 nil)
("DIMS" -1 nil 0.18 T 1 "Dimensions")
)
)
(princ)
)

 

Alan, your routine displays this error message window in CAD2002:

Command: ap

APPLOAD FOO.LSP successfully loaded.

Command:

Command: foo

; error: no function definition: nil

Link to comment
Share on other sites

To remove the ambiguity from this thread:

 

(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
 ;; © Lee Mac 2010

[color=blue][b]  ;; Specifications:

[/b][b]   ;; 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

[/b][b]   ;; Function will return list detailing whether layer creation is successful.[/b][/color]  

 (
   (lambda ( lst )
     (mapcar 'cons (mapcar 'car lst)
       (mapcar
         (function
           (lambda ( x )
             (apply 'MakeLayer x)
           )
         )
         lst
       )
     )
   )
  '(
[color=blue][b]     ;    Name        Colour        Linetype        Lineweight        Plot?        BitFlag        Description[/b][/color]
    (    "CEN"         6           "CENTER"           0.18            T             0               nil      )
    (    "DIMS"       -1             nil              0.18            T             1           "Dimensions" )
    (    "HAT"         3             nil              0.18            T             5               nil      )
    (    "HID"         4           "HIDDEN"           0.15            T             0             "Hidden"   )
    (    "LOGO"       176            nil              0.09            T             0            "For Logo"  )
    (    "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" )
    (    "TXT"         7             nil               nil            T             0               nil      )
   )
 )
)

Edit table as necessary.

Link to comment
Share on other sites

Alan, your routine displays this error message window in CAD2002:

 

Command: ap

APPLOAD FOO.LSP successfully loaded.

Command:

Command: foo

; error: no function definition: nil

 

I wonder if you aren't allowed to put nil instead of (/), when defining the function.

What happens when you change (defun c:foo nil for (defun c:foo (/) ?

Link to comment
Share on other sites

I think it was because they were loading your function without mine -

 

Hence getting (apply 'nil x)

I thought that, but assumed they would receive an 'invalid function' error. Oh well. I still feel my contrib. is a lot easier to edit, etc.
Link to comment
Share on other sites

Oh well. I still feel my contrib. is a lot easier to edit, etc.

 

Most definitely - hence why I used that way of phrasing it when posting above. Preaching to the converted mate :)

Link to comment
Share on other sites

I changed to (defun c: foo (/) and displayed the same error.

 

Command: foo

; error: no function definition: nil

Command:

Then it's that you are missing Lee's subroutine "MakeLayer". What I posted will not create the layers, it still needs the MakeLayer sub to be loaded.

Link to comment
Share on other sites

I wonder if you aren't allowed to put nil instead of (/), when defining the function.

What happens when you change (defun c:foo nil for (defun c:foo (/) ?

 

Sidebar (nothing to do with the thread):

Why have I started to see that lately? What is making you guys replace "(/)" with "nil"?

Link to comment
Share on other sites

To remove the ambiguity from this thread:

 

(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
 ;; © Lee Mac 2010

[color=blue][b] ;; Specifications:[/b][/color]

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

[color=blue][b]  ;; Function will return list detailing whether layer creation is successful.[/b][/color]  

 (
   (lambda ( lst )
     (mapcar 'cons (mapcar 'car lst)
       (mapcar
         (function
           (lambda ( x )
             (apply 'MakeLayer x)
           )
         )
         lst
       )
     )
   )
  '(
[color=blue][b]    ;    Name        Colour        Linetype        Lineweight        Plot?        BitFlag        Description[/b][/color]
    (    "CEN"         6           "CENTER"           0.18            T             0               nil      )
    (    "DIMS"       -1             nil              0.18            T             1           "Dimensions" )
    (    "HAT"         3             nil              0.18            T             5               nil      )
    (    "HID"         4           "HIDDEN"           0.15            T             0             "Hidden"   )
    (    "LOGO"       176            nil              0.09            T             0            "For Logo"  )
    (    "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" )
    (    "TXT"         7             nil               nil            T             0               nil      )
   )
 )
)

Edit table as necessary.

 

Thanks a million guys!! You def'ly helped me out a tonne, i just have another question, on Lee's initial routine, the linetypes loaded in automatically. What do i need to change in this code to get it to do the same thing?

What i found was that as long as the lisp is in the same directory as the acad.lin and acadiso.lin files it worked. .... i also just tested to make sure, i completely purged my drawing, then ran the first lisp (old code) and presto!

Link to comment
Share on other sites

I didn't really want to modify the sub, so try this:

 

(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

 [color=purple][b];; Specifications:

 [/b][b];; 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

[/b][b] ;; Function will return list detailing whether layer creation is successful.  [/b][/color]  

 (
   (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
       )
     )
   )
  '(
   [color=purple][b] ;    Name        Colour        Linetype        Lineweight        Plot?        BitFlag        Description[/b][/color]
    (    "CEN"         6           "CENTER"           0.18            T             0               nil      )
    (    "DIMS"       -1             nil              0.18            T             1           "Dimensions" )
    (    "HAT"         3             nil              0.18            T             5               nil      )
    (    "HID"         4           "HIDDEN"           0.15            T             0             "Hidden"   )
    (    "LOGO"       176            nil              0.09            T             0            "For Logo"  )
    (    "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" )
    (    "TXT"         7             nil               nil            T             0               nil      )
   )
 )
)

Link to comment
Share on other sites

i didn't really want to modify the sub, so try this:

 

(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

 [color=purple][b];; specifications:[/b][/color]

[color=purple][b];; description        data type        remarks[/b][/color]
[b][color=purple] ;; -----------------------------------------------------------------[/color][/b]
[b][color=purple] ;; layer name          string          only standard chars allowed[/color][/b]
[b][color=purple] ;; layer colour        integer         may be nil, -ve for layer off, colour < 256[/color][/b]
[b][color=purple] ;; layer linetype      string          may be nil, if not loaded, continuous.[/color][/b]
[b][color=purple] ;; layer lineweight    real            may be nil, 0 <= x <= 2.11[/color][/b]
[b][color=purple] ;; plot?               Boolean         t = plot layer, nil otherwise[/color][/b]
[b][color=purple] ;; bit flag            integer         0=none, 1=frozen, 2=frozen in vp, 4=locked[/color][/b]
[b][color=purple] ;; description         string          may be nil for no description[/color][/b]

[color=purple][b];; function will return list detailing whether layer creation is successful.  [/b][/color]  

 (
   (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
       )
     )
   )
  '(
   [color=purple][b] ;    name        colour        linetype        lineweight        plot?        Bitflag        description[/b][/color]
    (    "cen"         6           "center"           0.18            t             0               nil      )
    (    "dims"       -1             nil              0.18            t             1           "dimensions" )
    (    "hat"         3             nil              0.18            t             5               nil      )
    (    "hid"         4           "hidden"           0.15            t             0             "hidden"   )
    (    "logo"       176            nil              0.09            t             0            "for logo"  )
    (    "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" )
    (    "txt"         7             nil               nil            t             0               nil      )
   )
 )
)

 

 

perfect, thanks lee- been a great help

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...