Code Red > AutoLISP (Vanilla / Visual)

Teaching Tracey - Creating layers

(1/12) > >>

jonesy:
The colours, layers and linetypes dictated by our clients are currently set up in template files that we use to start new drawings.  Some of our users purge their drawings before they are complete, therefore losing all of the unused layer, colour and linetype settings.

I would like to write a lisp routine to set all of this up and reload the layers that have been purged. 

Is there anyone out there who would be willing to help me with this project, by guiding me?

I have very little knowledge in lisp, but am more than willing to learn.

Thanks in advance

Tracey

Kerry:
Tracey, Have you tried inserting your template drawing (exploded) into the target drawing ??


// kwb

jonesy:
Thanks for your reply Kerry

We have used this method for the past year, sometimes successfully, othertimes not.

Sometimes other users then forget to take the tick out of the "explode" box and many more blocks get inserted already exploded. Sometimes I dont catch these until I audit the drawings.

I was hoping to find an alternative.

Kerry:
OK, Try this ..
you'll just need to modify the Layer definitions ..

--- Code: ---;; // TRACEY_Layers.lsp
;; // last edit kwb : 20061010

;; (c:Tracey_LAYERS)

;;;=====================================================================


(DEFUN c:tracey_layers (/            lintypefile  layerdata
                        onewlayer    ltname
                        ;;
                        *error*      _assertitem
                       )
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;;
  (DEFUN *error* (msg /)
    ;;----- Cancel any Active Commands ----------------------------- 
    (WHILE (< 0 (GETVAR "cmdactive")) (COMMAND))
    ;;-----
    (VLA-SETVARIABLE kg:iacaddocument "menuecho" 1)
    (VLA-ENDUNDOMARK kg:iacaddocument)
    ;;----- Display error message if applicable _-------------------
    (COND
      ((NOT msg))                                                ; no error, do nothing
      ((VL-POSITION
         (STRCASE msg T)                                         ; cancel
         '("console break" "function cancelled" "quit / exit abort")
       )
      )
      ((PRINC (STRCAT "\nApplication Error: "
                      (ITOA (GETVAR "errno"))   ;; <-- edited kwb
                      " :- "
                      msg
              )
       )
       (VL-BT)
      )
    )
    (PRINC)
  );;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;;
  (DEFUN _assertitem (collection item / returnvalue)
    (IF (NOT (VL-CATCH-ALL-ERROR-P
               (SETQ
                 returnvalue (VL-CATCH-ALL-APPLY 'VLA-ITEM
                                                 (LIST collection item)
                             )
               )
             )
        )
      returnvalue
    )
  )
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;;
  (SETQ kg:iacadapplication (VLAX-GET-ACAD-OBJECT)
        kg:iacaddocument    (VLA-GET-ACTIVEDOCUMENT kg:iacadapplication)
        kg:iacadlayers      (VLA-GET-LAYERS kg:iacaddocument)
        kg:iacadlinetypes   (VLA-GET-LINETYPES kg:iacaddocument)
  )
  (VLA-ENDUNDOMARK kg:iacaddocument)                             ; end any open undo group
  (VLA-STARTUNDOMARK kg:iacaddocument)                           ; start new group
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;;
  (SETQ g:layerslist
         (LIST
           (LIST "ST90"                                          ;LayerName
                 "CONTINUOUS"                                    ;LineType
                 "Outlines 0.90mm"                               ;Description
                 ACBLUE                                          ;Color
           )
           (LIST "ST70"
                 "CONTINUOUS"
                 "Outlines 0.70mm"
                 ACGREEN
           )
           (LIST "ST50"
                 "CONTINUOUS"
                 "Outlines 0.50mm"
                 ACMAGENTA
           )
           (LIST "ST35"
                 "CONTINUOUS"
                 "Outlines 0.35mm"
                 ACYELLOW
           )
           (LIST "ST25" "CONTINUOUS" "Outlines 0.25mm" ACRED)
           (LIST "ST18" "CONTINUOUS" "Outlines 0.18mm" ACCYAN)
           (LIST "ST00" "CONTINUOUS" "Outlines Mixed" 8)
           (LIST "STC18"
                 "CENTER2"
                 "Center Lines Short 0.18mm"
                 ACCYAN
           )
           (LIST "STC20"
                 "CENTER"
                 "Center Lines Medium 0.25mm"
                 ACRED
           )
           (LIST "STC25"
                 "CENTERX2"
                 "Center Lines Long 0.25mm"
                 ACRED
           )
           (LIST "STH18"
                 "HIDDEN2"
                 "Hidden Lines Short 0.18mm"
                 ACCYAN
           )
           (LIST "STH20"
                 "HIDDEN"
                 "Hidden Lines Medium 0.25mm"
                 ACRED
           )
           (LIST "STH25"
                 "HIDDENX2"
                 "Hidden Lines Long 0.25mm"
                 ACRED
           )
           (LIST "STH30"
                 "DASHEDX2"
                 "Dashed Lines Long 0.25mm"
                 ACRED
           )
           ;; text layers
           (LIST "STT90" "CONTINUOUS" "Text 0.90mm" ACBLUE)
           (LIST "STT70" "CONTINUOUS" "Text 0.70mm" ACGREEN)
           (LIST "STT50" "CONTINUOUS" "Text 0.50mm" ACMAGENTA)
           (LIST "STT35" "CONTINUOUS" "Text 0.35mm" ACYELLOW)
           (LIST "STT25" "CONTINUOUS" "Text 0.25mm" ACRED)
           (LIST "STT18" "CONTINUOUS" "Text 0.18mm" ACCYAN)
         )
  )
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;;
  (SETQ lintypefile (IF (= 1 (GETVAR "Measurement"))
                      (FINDFILE "acadiso.lin")
                      (FINDFILE "acad.lin")
                    )
  )
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;;
  ;; (setq layerdata (car g:layerslist))
  (FOREACH layerdata g:layerslist
    (SETQ onewlayer (VLA-ADD kg:iacadlayers (CAR layerdata))
          ltname    (CADR layerdata)
    )
    (IF (NOT (_assertitem kg:iacadlinetypes ltname))
      (VLA-LOAD kg:iacadlinetypes ltname lintypefile)
    )
    (VLA-PUT-LINETYPE onewlayer ltname)
    (VLA-PUT-DESCRIPTION onewlayer (CADDR layerdata))
    (VLA-PUT-COLOR onewlayer (LAST layerdata))
  )
  (PRINC)
)
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;;
 
  (PRINC)
--- End code ---

edit : *error* routine modified <

Kerry:
 ... each of these defines a layer ..

--- Code: ---           (LIST "ST90"                                          ;LayerName
                 "CONTINUOUS"                                    ;LineType
                 "Outlines 0.90mm"                               ;Description
                 ACBLUE                                          ;Color
           )
--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version