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

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Teaching Tracey - Creating layers
« Reply #30 on: October 10, 2006, 05:00:15 PM »
I can help, no problem.  :-)  Just let me know what needs some explaining.

I still think Luis has a good approach.  There are still things I don't understand, even though I use them.  I like having a good basic understanding, and then building from there.
Tim

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

Please think about donating if this post helped you.

LE

  • Guest
Re: Teaching Tracey - Creating layers
« Reply #31 on: October 10, 2006, 05:07:56 PM »
Yep...

(but I am not saying that what I posted is the best or the way to go)

I am more concern in trying to make the lisping readable or easy as much is possible to T.

And the same... if I can answer a question... T. let us know.

 :-)

jonesy

  • SuperMod
  • Seagull
  • Posts: 15568
Re: Teaching Tracey - Creating layers
« Reply #32 on: October 10, 2006, 05:17:41 PM »
I like the idea of starting at ground level, then building up.Hopefully there will be fewer holes in my knowledge. It'll take me longer to get there, but, hopefully I'll get fewer problems.

You guys are great.

Its late here in the UK, I'll be back with questions, probably tomorrow :-)

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

sinc

  • Guest
Re: Teaching Tracey - Creating layers
« Reply #33 on: October 10, 2006, 05:43:22 PM »
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. 


There's yet another simple solution that doesn't require any Lisp.  You can open your template drawing in Design Center and then simply drag'n'drop any missing layers into your current drawing.

daron

  • Guest
Re: Teaching Tracey - Creating layers
« Reply #34 on: October 10, 2006, 08:05:07 PM »
Great ideas (non-lispy), however, Tracey's trying to learn by asking questions. I'm sure anyone  who can write code can whip out what she's asked for or spell out 20 different ways..., but she'd like to learn by doing. I think one of the first lisps I ever did was a rectangle. Rectangle was already in existence, so why write it again? For the learning experience. One of the earliest lisps I ever wrote was very simple and I actually found myself using it today on a bunch of line connections. It was this:
Code: [Select]
(DEFUN C:L1 (/ A)
    (WHILE
(SETQ A (GETPOINT "\nFrom Point: ")
)
   (COMMAND "LINE" A PAUSE "")
    ) ;WHILE
    (PRINC)
)
Boy, what ugly code, but I learned from it. It allows you to draw multiple, dual-vertice lines. Simple, ugly, effective.

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Re: Teaching Tracey - Creating layers
« Reply #35 on: October 10, 2006, 11:20:11 PM »
Tracey,
Food for thought.

Pseudo code:
...
<snip>

CABs gets my vote for the most helpfull post in this thread.  Expand on this.
« Last Edit: October 10, 2006, 11:21:12 PM by Se7en »
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

jonesy

  • SuperMod
  • Seagull
  • Posts: 15568
Re: Teaching Tracey - Creating layers
« Reply #36 on: October 11, 2006, 02:24:50 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. 


There's yet another simple solution that doesn't require any Lisp.  You can open your template drawing in Design Center and then simply drag'n'drop any missing layers into your current drawing.

As Daron said, I'm trying to use a real world example to learn, and make me remember lisp. Also some of the templates have over 50 layers purged before they should have been, making it a laborious task to add them.

I'll be looking at all the examples over the next couple of days, asking some very basic questions in the process.

Thanks everyone... I'll be back :-)
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 #37 on: October 11, 2006, 05:31:42 AM »
Tracey, If you find yourself short of study time, Express tools has a Layer Manager which can import layer setting previously saved <exported>  from the same interface.

... It doesn't restore the Layer descriptions though .. { no big deal }

The saved file is a text format and is easily editable.

Good luck :-)
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 #38 on: October 11, 2006, 05:55:13 AM »
Thanks Kerry, time is not too much of an issue here.

The way we currently do it is OK, but I want better. So  if it takes me a few weeks/months to sort through it all, it wont matter to me. As long as I can keep coming back to this topic and asking questions I'll be OK.

I thought I'd try to learn lisp on something that I want to change here, that way I might understand it a bit better.
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 #39 on: October 11, 2006, 06:03:22 AM »
Sounds like a plan ! :-)
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 #40 on: October 11, 2006, 06:16:07 AM »
Tracey,
You may find this a useful excise, I did.
Take Tim's code & add comments. First comment what each subroutine does.
Then start with the MAIN code & break down each line or small group of lines &
comment what it does. Then move to the subroutines & do the same.
I'm sure Tim will help you with any items that are not clear to you.

Just a suggestion.
Quick question CAB, if you dont mind

Did you mean TWilley, or TimSpanglers layer creation program?

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

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Teaching Tracey - Creating layers
« Reply #41 on: October 11, 2006, 07:55:41 AM »
I was referring to Tim Willey.
Tim Spanglers code is too large for this biginner project.

You may want to comment the other lisp routines offered here as well.  :-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

jonesy

  • SuperMod
  • Seagull
  • Posts: 15568
Re: Teaching Tracey - Creating layers
« Reply #42 on: October 11, 2006, 08:03:19 AM »
Thanks CAB.

I'm on it now :-)
Thanks for explaining the word "many" to me, it means a lot.

sinc

  • Guest
Re: Teaching Tracey - Creating layers
« Reply #43 on: October 11, 2006, 08:33:30 AM »

As Daron said, I'm trying to use a real world example to learn, and make me remember lisp. Also some of the templates have over 50 layers purged before they should have been, making it a laborious task to add them.


I just tried it.  I opened a drawing that has most of its layers purged.  Then I opened the template in Design Center, selected all layers, and drag'n'dropped them into my drawing.  Problem solved.  Not laborious at all, and it took less than ten seconds.

But if your main goal is learning to program, and you can't think of any Lisp routine that would be more useful to you, then by all means carry on.  Programming skills are handy to have.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Teaching Tracey - Creating layers
« Reply #44 on: October 11, 2006, 10:21:03 AM »
I couldn't sleep last night so I coded up this framework. It's not a solution <tho it works>, more a demonstration of one way to frame up an application and some development techniques. I didn't complete the documentation but now I'm too tired. Overkill at this point in Tracey's learning journey? Probably. I ante it up anyway for what it's worth. Have a look at your leisure.

First a coloroized pdf file: MakeLayers.pdf

And now in good ol' ascii:

Code: [Select]
(defun c:MakeLayers


    ;;  Written by M.Puckett for T. Jones. Not a solution per
    ;;  se but examples of some techniques one can use during
    ;;  development, particularly when there are some unknowns.


    (   /

        *error*
        *debug*
        _BreadCrumb
        _GetActiveClient
        _GetLayerDefinitions
        _LoadLinetypes
        _CleanClientLayerDefinition
        _AddLayers
        _Main
    )



    (defun *error* ( msg )

        ;;  A verbose error handler that will ante up some
        ;;  debugging info if we bomb somewhere.

        (vl-bt)

    )



    (defun _BreadCrumb ( location )

        ;;  We'll use this to flag where we are in program
        ;;  execution. If we're debugging it will echo our
        ;;  location, otherwise it will be quiet.

        (if *debug*
            (mapcar 'princ
                (list "===== Location <" location "> =====\n")
            )
        )

        (princ)

    )



    (defun _GetActiveClient ( )

        (_BreadCrumb "_GetActiveClient [not done]")

        ;;  At this point we don't know how we will get or
        ;;  determine the client's name as it's not been
        ;;  defined (all we know is that our layer system
        ;;  is client centric). Until we know how the client
        ;;  is determined let's return a typical value
        ;;  so the solution can be developed.
        ;;
        ;;  This technique is sometimes called "stubbing",
        ;;  see http://en.wikipedia.org/wiki/Method_stub

        "CLIENT 1"
    )


    (defun _GetLayerDefinitions ( )

        (_BreadCrumb "_GetLayerDefinitions [not done]")

        ;;  At this point we don't know if we are going to
        ;;  get the layer definitions, be it by reading a
        ;;  template file via objectdbx, by reading a simple
        ;;  text file, hard coded values ... whatever. What
        ;;  we do know is the format we intend to use, so
        ;;  let's return sample data formatted accordingly
        ;;  for now (noting the capitalized client names is
        ;;  part of the format we need to honour).
        ;;
        ;;  Also, we've include some data that, while in the
        ;;  proper format, is in error so we can test the
        ;;  solutions's ability to deal with typical errant
        ;;  data.

       '(   (   "DEFAULT"
                ("Layer1" 001 "Continuous")
                ("Layer2" 002 "Continuous")
                ("Layer3" 003 "Continuous")
            )
            (   "INVALID"
                ("|*Ackk" 011 "Hidden") ;; invalid name
                ("Layer2" 999 "Hidden") ;; invalid color
                ("Layer3" 013 "Bogus!") ;; invalid linetype
            )
            (   "CLIENT 1"
                ("Layer1" 011 "Center")
                ("Layer2" 012 "Center")
                ("Layer3" 013 "Center")
            )
            (   "CLIENT 2"
                ("Layer1" 101 "Dashed")
                ("Layer2" 102 "Dashed")
                ("Layer3" 103 "Dashed")
            )
        )

    )


    (defun _LoadLinetypes ( activeDocument clientName / linefile result )

        (_BreadCrumb "_LoadLinetypes [not done]")

        ;;  At this point we don't know if we'll use custom
        ;;  linetypes associated with a client (a frequent
        ;;  norm) or not. Let's assume that's something we
        ;;  need to incorporate (i.e. require the function to
        ;;  take the client name as an argument, but ignore it
        ;;  for now. In the interim let's have it attempt to
        ;;  load the standard AutoCAD linetypes, returning the
        ;;  load status to the caller.

        (if
            (setq linefile
                (findfile
                    (if (zerop (getvar "measurement"))
                        "acad.lin"
                        "acadiso.lin"
                    )
                )
            )
            (vl-catch-all-apply
               '(lambda ( )
                    (vla-load
                        (vla-get-linetypes activeDocument)
                        "*"
                        linefile
                    )
                    ;;  we'll only get here on
                    ;;  a successfull load
                    (setq result t)
                )
            )
        )

        result

    )


    (defun _CleanClientLayerDefinition

        (   clientLayerData
            lineTypeCollection
            /
            loadedLinetypes
        )

        (_BreadCrumb "_CleanClientLayerDefinition [done]")

        ;;  Our intent is to ensure layer data is clean --
        ;;  layernames pass a snvalid test, colors are in
        ;;  the range 1 - 255, and linetypes are available
        ;;  in the drawing. In the case of the latter two
        ;;  properties invalid entries will be replaced with
        ;;  default values of 7 and "Continuous" respectively.
        ;;  In the case of an invalid layer name the entry
        ;;  will be removed in it's entirety. As we go inform
        ;;  the user of any problems so they might be able to
        ;;  fix them.
        ;;
        ;;  Recall the format of the data for a given client
        ;;  is expected to be --
        ;;
        ;;      (   ("Layer1" 001 "Continuous")
        ;;          ("Layer2" 002 "Continuous")
        ;;          ("Layer3" 003 "Continuous")
        ;;          ...
        ;;      )

        ;;  Remove any entries that are not in the
        ;;  proper format.

        (setq clientLayerData
            (vl-remove-if-not
               '(lambda ( lst / result )
                    (if
                        (not
                            (setq result
                                (equal '(str int str)
                                    (mapcar 'type lst)
                                )
                            )
                        )
                        (princ
                            (strcat
                                "Removing invalid entry: "
                                (vl-prin1-to-string lst)
                                " <incorrect format>.\n"
                            )
                        )
                    )
                    result
                )
                clientLayerData
            )
        )

        ;;  Remove any entries with invalid layer names.

        (setq clientLayerData
            (vl-remove-if-not
               '(lambda ( lst / result )
                    (if (setq result (snvalid (car lst)))
                        result
                        (progn
                            (princ
                                (strcat
                                    "Removing invalid entry: "
                                    (vl-prin1-to-string lst)
                                    " <invalid name>.\n"
                                )
                            )
                            result
                        )
                    )
                )
                clientLayerData
            )
        )

        ;;  Let's get all the linetypes loaded in
        ;;  this document, force to uppercase.

        (vlax-for lineTypeObject lineTypeCollection
            (setq loadedLinetypes
                (cons
                    (strcase (vla-get-name lineTypeObject))
                    loadedLinetypes
                )
            )
        )

        ;;  Now lets check the color and lintype
        ;;  on the layer definitions that remain
        ;;  and return to the caller.

        (mapcar
           '(lambda ( lst / name color linetype )
                (mapcar 'set '(name color linetype) lst)
                (if (null (< 0 color 256))
                    (progn
                        (princ
                            (strcat
                                "Invalid color in "
                                (vl-prin1-to-string lst)
                                " forcing value of 7.\n"
                            )
                        )
                        (setq color 7)
                    )
                )
                (if (null (member (strcase linetype) loadedLinetypes))
                    (progn
                        (princ
                            (strcat
                                "Invalid linetype in "
                                (vl-prin1-to-string lst)
                                " forcing value of \"Continuous\".\n"
                            )
                        )
                        (setq linetype "Continuous")
                    )
                )
                (list name color linetype)
            )
            clientLayerData
        )
    )


    (defun _AddLayers

        (
            layersCollection
            layerDefinitions
            /
            layerObject
            name
            color
            linetype
        )

        (_BreadCrumb "_AddLayers [done]")

        ;;  LayerDefinitions is expected to be valid data
        ;;  (proper name, color and linetype) in the form --
        ;;
        ;;  (   (LayerName Color Linetype)
        ;;      (LayerName Color Linetype)
        ;;      ...
        ;;  )
        ;;
        ;;  Example --
        ;;
        ;;  (   ("Layer1" 001 "Continuous")
        ;;      ("Layer2" 002 "Continuous")
        ;;      ...
        ;;  )

        (foreach layerDefinition layerDefinitions

            ;;  Pull out the individual properties.

            (mapcar 'set
               '(name color linetype)
                layerDefinition
            )

            ;;  Get the existing layer if posible.

            (if
                (vl-catch-all-error-p
                    (vl-catch-all-apply
                       '(lambda ( )
                            (setq layerObject
                                (vla-item
                                    layersCollection
                                    name
                                )
                            )
                        )
                    )
                )

                ;;  Layer didn't exist, let's add it
                ;;  to the layer collection.

                (setq layerObject
                    (vla-add
                        layersCollection
                        name
                    )
                )
            )

            ;;  Set the color and linetype. Remember, we've
            ;;  cleaned the layerDefinition so there should
            ;;  be no need to trap for invalid colors and
            ;;  linetypes in this function -- it is expected
            ;;  to be passed proper data.

            (vla-put-color layerObject color)

            (vla-put-linetype layerObject linetype)
        )
    )


    (defun _Main

        (   activeDocument
            /
            clientName
            layerDefinitions
            clientLayerDefinitions
        )

        (_BreadCrumb "_Main [not done because of dependencies]")

        ;;  This function wraps up all functionality
        ;;  that defines the MakeLayers solution.

        ;;  We don't know how _GetActiveClient determines the
        ;;  active client's name, all we know is it returns said
        ;;  data as a string (or nil).

        (setq clientName (_GetActiveClient))

        ;;  If an active client name was not found force the active
        ;;  client name to "Default". This will indicate in-house
        ;;  works.

        (if (null clientName)
            (setq clientName "Default")
        )

        ;;  We don't know how _GetLayerDefinitions gets the layer
        ;;  definitions, all we know is that it returns data as a
        ;;  list in the form --
        ;;
        ;;  (   (   "CLIENTNAME"
        ;;          ("LayerName" Color "LineType")
        ;;          ("LayerName" Color "LineType")
        ;;          ...
        ;;      )
        ;;      (   "CLIENTNAME"
        ;;          ("LayerName" Color "LineType")
        ;;          ("LayerName" Color "LineType")
        ;;          ...
        ;;      )
        ;;      ...
        ;;  )
        ;;
        ;;  noting that the client name is always uppercase.

        (setq layerDefinitions (_GetLayerDefinitions))

        ;;  Get the layer definitions associated with the
        ;;  client name.

        (setq clientLayerDefinitions
            (cdr
                (assoc
                    (strcase clientName)
                    layerDefinitions
                )
            )
        )

        ;;  Proceded if we actually have layer definitions
        ;;  for the active client.

        (cond

            (   clientLayerDefinitions

                ;;  Load up the linetypes.

                (_LoadLinetypes activeDocument clientName)

                ;;  Clean the client layer definitions (remember
                ;;  to do this *after* the linetype have been loaded.

                (setq clientLayerDefinitions
                    (_CleanClientLayerDefinition
                        clientLayerDefinitions
                        (vla-get-linetypes activeDocument)
                    )
                )

                ;;  It's possible no linetype remained after cleanup,
                ;;  deal with that possibility.

                (cond
                    (   clientLayerDefinitions
                        (strcat
                            "Adding layers for client <"
                            clientName
                            ">.\n"
                        )
                        (_AddLayers
                            (vla-get-layers activeDocument)
                            clientLayerDefinitions
                        )
                    )
                    (   (strcat
                            "All entries for clinet <"
                            clientName
                            "> were invalid.\n"
                        )
                    )
                )
            )

            ;;  No clients layer definitions but we did get a client
            ;;  name, inform the user.

            (   clientName

                (princ
                    (strcat
                        "No (clean) layer definitions found for client <"
                        clientName
                        ">.\n"
                    )
                )

            )

            ;;  Active client name could not be determined, inform
            ;;  the user.

            (   t

                (princ "Active client could not be determined.\n")

            )

        )

        (princ)

    )

    ;;  Turn on debug mode by setting *debug* to any non
    ;;  nil value, turn off debug mode by setting *debug*
    ;;  to nil.

    (setq *debug* t)

    ;;  Call _Main passing the active document.

    (_Main (vla-get-activedocument (vlax-get-acad-object)))

)

To see how the program deals with errant data edit the _GetActiveClient function and have it return "INVALID".

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