Jump to content

Recommended Posts

Posted

Hey i have a layer creation lisp that needs to envoke as soon as a drawing opens not load but envoke to where when the dwg is opened the layers are created does anyone know how to do this?

  • Replies 21
  • Created
  • Last Reply

Top Posters In This Topic

  • CmdrDuh

    6

  • BLOACH85

    6

  • Lee Mac

    4

  • The Buzzard

    4

Top Posters In This Topic

Posted

As I said in your other thread, make a call to the LISP in your ACADDOC.lsp file, or add it to the start-up suite with (c:lispname) in the LISP file.

Posted
Add it to the start-up suite with (c:lispname) in the LISP file.

Absolutely..

 

:P

Posted

so if its already in the startup suite all i have to do is put (c:standardlayers) in the lisp file and in the acad2009doc.lsp put the same thing?

Posted
so if its already in the startup suite all i have to do is put (c:standardlayers) in the lisp file and in the acad2009doc.lsp put the same thing?

 

I would do one or the other - not both.

 

As for modifying the acad2009doc.lsp ~ a quote from the link provided by Uddfl:

 

Warning Do not modify the reserved acad2008doc.lsp file. Autodesk provides the acad2008doc.lsp file, which contains AutoLISP-defined functions that are required by AutoCAD. This file is loaded into memory immediately before the acaddoc.lsp file is loaded.

How to create acaddoc.lsp if it does not exist...

I assume this applies to the '09 file also....

 

 

Just a heads-up

 

Lee

Posted

OK i did the other way but im coming up with an error bad function at each dwg load.

Posted

I would drop the c: in the defun, and call it with (functionname) in startup

Posted

oK it works but i have another question, If i already have the layer created its automatically overwriting it. Most of my layes are set up for the color to be changed. Most of my dwgs if i open them the layer that example was origanlly yellow(bylayer) and i changed to red automatically changes back to bylayer. anyway to stop this?

Posted

use some logic to see if the layer exists, can you post your code so we can look at it? Im thinking if you try to layer set, if it fails, then create it else skip it

Posted

Here is the code, All of my fixes just arent cutting it.

 

(defun c:standardlayers (/ *error*)
   (defun *error* (msg)
   (and Osmode# (setvar "osmode" Osmode#))
   (command "_.undo" "_e")
   (if
     (not
   (member
     msg
     '("console break" "Function cancelled" "quit / exit abort")
   ) ;_ member
     ) ;_ not
            (princ (strcat "\nError: " msg))
   ) ;_ if
 ) ;_ defun
; Layers
(command "layer" "m" "Const"   "lt"   "continuous" "" "c" "1" "" "")
(command "layer" "m" "Steel"   "lt"   "continuous" "" "c" "2" "" "") 
(command "layer" "m" "Dimension"     "lt"   "continuous" "" "c" "4" "" "")
(command "layer" "m" "Hidden"  "lt"   "Hidden" "" "c" "1" "" "")
(command "layer" "m" "Text"   "lt"   "continuous" "" "c" "7" "" "")
(command "layer" "m" "Welds"   "lt"   "continuous" "" "c" "6" "" "")
(command "layer" "m" "Ref"   "lt"   "continuous" "" "c" "8" "" "")
(command "-linetype" "load"   "hidden"  ""     "yes" "")
(princ)
);end of defun
(C:standardlayers)

 

When it comes to putting commands in the routines i just get put at a stand still.

Posted

This works, but its ugly.

(if (not (= (command "-layer" "s" "YourLayer" "") nil))
 (command "-layer" "m" "YourLayer" "c" "2" "" "")
)

 

Im not much of a lisper, vba is my thing, but the principal is the same

Posted

the next step would be to make a function you feed with values to simplfy typing. thinking out loud

(defun CheckLayer(/ LayerName LayerColor LayerLinetype)
(if (not (= (command "-layer" "s" LayerName "") nil))
 (command "-layer" "m" LayerName "c" LayerColor "" "lt" LayerLinetype "" "")
)
)

which you could call from your main routine as

(CheckLayer "Layer1Name" "Layer1Color" "L1LT")

Posted

how did you get it to work all im getting is

COMMAND: ERROR TO MANY ARGUMENTS

Posted

Give this a try,

 

 

;;;/////////////////////////////////////////////////////////////////
(defun c:standardlayers ()                                          ;Define function
 (SET_LAYER)                                                       ;Goto SET_LAYER Function
 (princ)                                                           ;Exit quietly
)                                                                   ;End of define function
;;;/////////////////////////////////////////////////////////////////
(defun SET_LAYER ()                                                 ;Define function
 (CREATE_LAYER "Const"     "1" "CONTINUOUS")                       ;Goto CREATE_Layer Function, Layer Name, Color, LineType
 (CREATE_LAYER "Steel"     "2" "CONTINUOUS")                       ;Goto CREATE_Layer Function, Layer Name, Color, LineType
 (CREATE_LAYER "Dimension" "4" "CONTINUOUS")                       ;Goto CREATE_Layer Function, Layer Name, Color, LineType
 (CREATE_LAYER "Hidden"    "1" "HIDDEN")                           ;Goto CREATE_Layer Function, Layer Name, Color, LineType
 (CREATE_LAYER "Text"      "7" "CONTINUOUS")                       ;Goto CREATE_Layer Function, Layer Name, Color, LineType
 (CREATE_LAYER "Welds"     "6" "CONTINUOUS")                       ;Goto CREATE_Layer Function, Layer Name, Color, LineType
 (CREATE_LAYER "Ref"       "8" "CONTINUOUS")                       ;Goto CREATE_Layer Function, Layer Name, Color, LineType
)                                                                   ;End define function
;;;/////////////////////////////////////////////////////////////////
(defun CREATE_LAYER (NLAY CLR LT / LAY FRZ)                         ;Define function, Declare variables and arguments
 (setq LAY  (tblsearch "layer" NLAY))                              ;Search drawing to find layer
 (if                                                               ;If the following returns true
   (not LAY)                                                       ;Layer not in drawing
   (command "_.layer" "m" NLAY "c" CLR "" "lt" LT "" "")           ;Layer command ~ make new layer with color and linetype
   (progn                                                          ;Then do the following
     (setq FRZ (cdr (assoc 70 LAY)))                               ;Variable FRZ is frozen layer
     (if (= FRZ 65)                                                ;Layer frozen from last edit
       (progn                                                      ;Then do the following
         (command "_.layer" "t" NLAY "")                           ;Thaw new layer if frozen
         (command "_.layer" "s" NLAY "")                           ;Set new layer
       )                                                           ;End progn (otherwise...) 
       (command "_.layer" "s" NLAY "")                             ;Set new layer
     )                                                             ;End if
   )                                                               ;End progn (otherwise...)
 )                                                                 ;End if
)                                                                   ;End define function
;;;/////////////////////////////////////////////////////////////////

Posted

BLOACH,

 

Sorry, Just edited the SET_LAYER function to make color corrections to match the function you posted.

 

The Buzzard

Posted
how did you get it to work all im getting is

COMMAND: ERROR TO MANY ARGUMENTS

which part did you try? The first one worked for me, the second one I was thinking out loud

Posted

after more testing, it only works if the layer already exists. I would use Lee's or Buzzard's method, as they know LISP better than I

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...