Author Topic: Teaching Tracey - Creating layers  (Read 30680 times)

0 Members and 1 Guest are viewing this topic.

jonesy

  • SuperMod
  • Seagull
  • Posts: 15568
Teaching Tracey - Creating layers
« on: October 10, 2006, 05:11:39 AM »
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
Thanks for explaining the word "many" to me, it means a lot.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Teaching Tracey - Creating layers
« Reply #1 on: October 10, 2006, 05:43:48 AM »
Tracey, Have you tried inserting your template drawing (exploded) into the target drawing ??


// kwb
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

jonesy

  • SuperMod
  • Seagull
  • Posts: 15568
Re: Teaching Tracey - Creating layers
« Reply #2 on: October 10, 2006, 06:10:30 AM »
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.

Thanks for explaining the word "many" to me, it means a lot.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Teaching Tracey - Creating layers
« Reply #3 on: October 10, 2006, 06:15:28 AM »
OK, Try this ..
you'll just need to modify the Layer definitions ..
Code: [Select]
;; // 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)

edit : *error* routine modified <
« Last Edit: October 10, 2006, 06:24:59 AM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Teaching Tracey - Creating layers
« Reply #4 on: October 10, 2006, 06:16:51 AM »
 ... each of these defines a layer ..
Code: [Select]
           (LIST "ST90"                                          ;LayerName
                 "CONTINUOUS"                                    ;LineType
                 "Outlines 0.90mm"                               ;Description
                 ACBLUE                                          ;Color
           )
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

jonesy

  • SuperMod
  • Seagull
  • Posts: 15568
Re: Teaching Tracey - Creating layers
« Reply #5 on: October 10, 2006, 07:18:12 AM »
Thanks Kerry...

I'll look at that this afternoon
Thanks for explaining the word "many" to me, it means a lot.

LE

  • Guest
Re: Teaching Tracey - Creating layers
« Reply #6 on: October 10, 2006, 09:36:24 AM »
Hola Tracey;

This is what I use, super basic:

Code: [Select]
(acad-push-dbmod)

;; basic layers
(setvar "cmdecho" 0)
(setq layer (getvar "clayer"))

(if (not (tblsearch "layer" "1"))
  (command "_.layer" "_m" "1" "_c" "1" "" ""))

(if (not (tblsearch "layer" "2"))
  (command "_.layer" "_m" "2" "_c" "2" "" ""))

(if (not (tblsearch "layer" "3"))
  (command "_.layer" "_m" "3" "_c" "3" "" ""))

(if (not (tblsearch "layer" "4"))
  (command "_.layer" "_m" "4" "_c" "4" "" ""))

(if (not (tblsearch "layer" "5"))
  (command "_.layer" "_m" "5" "_c" "5" "" ""))

(if (not (tblsearch "layer" "6"))
  (command "_.layer" "_m" "6" "_c" "6" "" ""))

(if (not (tblsearch "layer" "7"))
  (command "_.layer" "_m" "7" "_c" "7" "" ""))

(if (not (tblsearch "layer" "11"))
  (command "_.layer" "_m" "11" "_c" "11" "" ""))

(if (not (tblsearch "layer" "A-DIM"))
  (command "_.layer" "_m" "A-DIM" "_c" "4" "" ""))

(if (not (tblsearch "layer" "A-TEXT"))
  (command "_.layer" "_m" "A-TEXT" "_c" "4" "" ""))

(if (not (tblsearch "layer" "CENTER"))
  (command "_.layer" "_m" "CENTER" "_c" "5" "" "_l" "CENTER" "" ""))

(if (not (tblsearch "layer" "HIDDEN"))
  (command "_.layer" "_m" "HIDDEN" "_c" "5" "" "_l" "HIDDEN" "" ""))

(if (not (tblsearch "layer" "XR_BASE"))
  (command "_.layer" "_m" "XR_BASE" "_c" "7" "" ""))

(if (not (tblsearch "layer" "XR_TITLEBLOCK"))
  (command "_.layer" "_m" "XR_TITLEBLOCK" "_c" "7" "" ""))

(if (not (tblsearch "layer" "VIEWPORT"))
  (command "_.layer" "_m" "VIEWPORT" "_c" "1" "" "_p" "_n" "" ""))

(if layer
  (setvar "clayer" layer))
(setq layer nil)
(setvar "cmdecho" 1)

(acad-pop-dbmod)
(princ)

jonesy

  • SuperMod
  • Seagull
  • Posts: 15568
Re: Teaching Tracey - Creating layers
« Reply #7 on: October 10, 2006, 09:50:40 AM »
Thanks LE.

I'll look at that one too.


Can I ask a quick question?

What is (acad-push-dbmod) and (acad-pop-dbmod)

Thanks
Tracey
Thanks for explaining the word "many" to me, it means a lot.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Teaching Tracey - Creating layers
« Reply #8 on: October 10, 2006, 10:01:35 AM »
Since the standard has already been defined in a template drawing why not use object dbx to read said drawing's layer structure then (intelligently) recreate it n the current document?

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

LE

  • Guest
Re: Teaching Tracey - Creating layers
« Reply #9 on: October 10, 2006, 10:02:31 AM »
Those two functions can be use to make a modifications to a drawing and then restored to the original status.

Go to the autocad help and type DBMOD system variable - or type the function's name on the search tab.

For example, I load the lisp code into a new drawing (started from scratch or any other existing one), the lisp does some modifications... but then I make a decision to simple close the drawing.... Those previous modifications will be ignored and it won't show the dialog message of asking to saved changes....

HTH.

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: Teaching Tracey - Creating layers
« Reply #10 on: October 10, 2006, 10:02:50 AM »
Another approach:

Create a block that has line segments, circles, or other simple object for each (and on that) layer.  Insert it into the drawing and use the following to make the block reference invisible:

Code: [Select]
(defun c:jbPutInvisible  (/ ent)
  (setq ent (entsel))
  (if ent
    (vla-put-Visible (vlax-ename->vla-object (car ent)) :vlax-false)))

(defun c:jbPutAllVisible  (/)
  (vlax-for b (vla-get-blocks(vla-get-ActiveDocument(vlax-get-acad-object)))
    (vlax-for x b
    (if (vlax-property-available-p x 'visible T)
    (vla-put-Visible x :vlax-true)))))

Now the block reference can't be erased so the block,  and included layers, can't be purged.  Include any other object table data in the same way: other blocks, textstyles, dimstyles, etc.

Just a thought,

jb
James Buzbee
Windows 8

jonesy

  • SuperMod
  • Seagull
  • Posts: 15568
Re: Teaching Tracey - Creating layers
« Reply #11 on: October 10, 2006, 10:05:13 AM »
Since the standard has already been defined in a template drawing why not use object dbx to read said drawing's layer structure then (intelligently) recreate it n the current document?

:)
Would that be very difficult (for a newbie like me to be able to follow and learn from)
Thanks for explaining the word "many" to me, it means a lot.

LE

  • Guest
Re: Teaching Tracey - Creating layers
« Reply #12 on: October 10, 2006, 10:11:00 AM »
Would that be very difficult (for a newbie like me to be able to follow and learn from)

That's why I am posting something that uses the command approach, so you can start by implementing something simple... Then in the future, you can do complex coding if necessary.

Code: [Select]
(if (not (tblsearch "layer" "1")) ;; see if the layer name exist.
  (command "_.layer" "_m" "1" "_c" "1" "" "")) ;; is not there - make it.

Code: [Select]
(command "_.layer" "_m" "1" "_c" "1" "" "") ;; even you can use just this.

Again, became comfortable with the lisp coding... and add new code lines... as you need them...

<edit> fixed code tags  Mav
« Last Edit: October 10, 2006, 10:14:53 AM by Maverick® »

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Teaching Tracey - Creating layers
« Reply #13 on: October 10, 2006, 10:29:00 AM »
Since the standard has already been defined in a template drawing why not use object dbx to read said drawing's layer structure then (intelligently) recreate it n the current document?

:)
Would that be very difficult (for a newbie like me to be able to follow and learn from)

While I totally think you could handle it (assuming the info were presented logically, methodically etc.) maybe smaller more bite sized pieces would be better right now; sorry.


:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Teaching Tracey - Creating layers
« Reply #14 on: October 10, 2006, 11:21:09 AM »
Since the standard has already been defined in a template drawing why not use object dbx to read said drawing's layer structure then (intelligently) recreate it n the current document?

:)
Would that be very difficult (for a newbie like me to be able to follow and learn from)

While I totally think you could handle it (assuming the info were presented logically, methodically etc.) maybe smaller more bite sized pieces would be better right now; sorry.


:)
When ready I have one I can post.  Not very pretty, but I can clean it up pretty quickly, I think.  I would start with the other ways mentioned here.

Another way that hasn't been mentioned, is to use 'entmake' to make the layers.  I have never done this, but I know others have, and could show a better example.  Just giving more options.  :-D
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.