Layer Creater

Discussion in 'AutoCAD' started by jb4pres, Jul 7, 2004.

  1. jb4pres

    jb4pres Guest

    I have code that someone else wrote (thank you to that person) that I want to alter. The code creates a layer based on an existing layer.

    type cl <enter> click a line <enter> type the suffix <enter> type the color <enter> ... done

    can the code be altered to add those steps into it and create 2 lines based on the existing line. And also to be able to click the line before the code.

    The suffixes and colors are:

    - cen (yellow)
    - edg (red)

    ;Layer maker ***** CL

    (defun c:cl ( / a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 b1 b2 c1)

    (princ "\nPick Layer to copy:") ; this prompts you for something
    (setq a1 (entsel)) ; you select the entity
    (setq a2 (car a1)) ; the name of that entity
    (setq a3 (entget a2)) ; gets data about that entity
    (setq a4 (assoc 8 a3))
    (setq a5 (cdr a4)) ; name of layer you picked
    (setq a6 (tblsearch "LAYER" a5)) ; gets data about that layer
    (setq a7 (assoc 62 a6))
    (setq a8 (cdr a7)) ; color, in case you want it to be the same
    (setq a9 (assoc 6 a6))
    (setq a10 (cdr a9)) ; linetype

    (princ "\nType suffix for layer:")
    (setq b1 (getstring T)) ; the T allows spaces in your typed string
    (setq b2 (strcat a5 b1)) ; concatenates (joins) the name + suffix

    (princ "\nType color for new layer:")
    (setq c1 (getstring T))

    (command "LAYER" "M" b2 "c" c1 b2 "lt" a10 b2 "") ; makes the layer
    (princ)
    )
     
    jb4pres, Jul 7, 2004
    #1
  2. Those variable names should be burned (shudder).

    I'm not sure we understand how you want it to really work. (And this is a
    fine example of how to give someone a fish, and the effects thereof!)

    --
    R. Robert Bell


    I have code that someone else wrote (thank you to that person) that I want
    to alter. The code creates a layer based on an existing layer.

    type cl <enter> click a line <enter> type the suffix <enter> type the color
    <enter> ... done

    can the code be altered to add those steps into it and create 2 lines based
    on the existing line. And also to be able to click the line before the
    code.

    The suffixes and colors are:

    - cen (yellow)
    - edg (red)

    ;Layer maker ***** CL

    (defun c:cl ( / a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 b1 b2 c1)

    (princ "\nPick Layer to copy:") ; this prompts you for something
    (setq a1 (entsel)) ; you select the entity
    (setq a2 (car a1)) ; the name of that entity
    (setq a3 (entget a2)) ; gets data about that entity
    (setq a4 (assoc 8 a3))
    (setq a5 (cdr a4)) ; name of layer you picked
    (setq a6 (tblsearch "LAYER" a5)) ; gets data about that layer
    (setq a7 (assoc 62 a6))
    (setq a8 (cdr a7)) ; color, in case you want it to be the same
    (setq a9 (assoc 6 a6))
    (setq a10 (cdr a9)) ; linetype

    (princ "\nType suffix for layer:")
    (setq b1 (getstring T)) ; the T allows spaces in your typed string
    (setq b2 (strcat a5 b1)) ; concatenates (joins) the name + suffix

    (princ "\nType color for new layer:")
    (setq c1 (getstring T))

    (command "LAYER" "M" b2 "c" c1 b2 "lt" a10 b2 "") ; makes the layer
    (princ)
    )
     
    R. Robert Bell, Jul 8, 2004
    #2
  3. jb4pres

    Doug Barr Guest

    I resemble that remark!

    Okeydoke RRB...
    a) burn the names for what reason? They're unique,
    they aren't reserved names, and they group certain
    'expanding variables' for ease of understanding.
    b) there WAS a bit of fishing-teaching in there... I've seen
    people provide fish, and that ain't fish.

    jb4pres had indicated a smattering of lisp knowledge,
    thus I sent him in a functional direction with room for
    improvement and some elements spelled out.

    Sorry to have assisted; had I known I would run up against
    a 'more qualified' teacher with a penchant for hand-slapping
    and down-putting, I'd have kept my mouth shut like everyone
    else did that day.
    -doug

    btw, it's really pretty clear to me how he'd like the thing
    to work; just read it with an open mind.
     
    Doug Barr, Jul 8, 2004
    #3
  4. jb4pres

    Rudy Tovar Guest

    If it ain't broke, don't fix it...

    I dig up old code all the time and splatter it on the newsgroup, only to get
    rebuked by some TT and philosophical point of view.

    As the bible says, "...in leiu of the time we teach the elementary of
    things, because solid food belongs to adults, while milk for children."

    There's nothing wrong with someone posting (milk)code...

    We all can learn a good lesson, by accepting the good and the bad.

    I humble myself...
     
    Rudy Tovar, Jul 8, 2004
    #4
  5. Sorry Doug if I stepped on your toes! I didn't mean to do so.

    I made that statement from the perspective of code maintenance and
    readability. "Was A3 the entity name or the entity data?" Those sorts of
    questions will be asked later in time, as the program grows or the variable
    is used in several places in the code.

    Also, I failed to comment on the clear nature of the comments, sorry. Those
    comments are clear enough that someone will be able to follow the nature of
    the code. My comment re: fish was that although the code is clearly
    commented, obviously jb doesn't seem to understand it. Would (s)he have
    understood it better if (s)he had to work on the code bit-by-bit until (s)he
    got it working the way (s)he wanted it to work? Granted, it would have taken
    more time, but it might have helped them.

    Now, I am missing some context here, as I didn't see this as a continuation
    of another thread. So I may be reading too much fish into the picture. I
    apologize for making you feel hand-slapped and put-down, as that was *not*
    my intention.

    P.S. I assumed jb wanted to draw offset lines from the centerline, but (s)he
    didn't indicate if that was the case. "Create two lines" where?

    --
    R. Robert Bell


    I resemble that remark!

    Okeydoke RRB...
    a) burn the names for what reason? They're unique,
    they aren't reserved names, and they group certain
    'expanding variables' for ease of understanding.
    b) there WAS a bit of fishing-teaching in there... I've seen
    people provide fish, and that ain't fish.

    jb4pres had indicated a smattering of lisp knowledge,
    thus I sent him in a functional direction with room for
    improvement and some elements spelled out.

    Sorry to have assisted; had I known I would run up against
    a 'more qualified' teacher with a penchant for hand-slapping
    and down-putting, I'd have kept my mouth shut like everyone
    else did that day.
    -doug

    btw, it's really pretty clear to me how he'd like the thing
    to work; just read it with an open mind.
     
    R. Robert Bell, Jul 8, 2004
    #5
  6. jb4pres

    Joe Burke Guest

    Robert,

    Forgive me for being contrary... but I suspect you did mean to step on Doug's toes.
    For good reason, IMO.

    If the issue is eat fish or learn how to catch... then it seems to me example code
    should demonstrate good coding practices. Doug's code fails in that sense for the
    reasons you mentioned.

    I guess I also don't understand Doug's reaction. When someone like you criticizes
    something I posted, I take it as welcome advice.

    No offense intended, Doug.

    Regards
    Joe Burke
     
    Joe Burke, Jul 8, 2004
    #6
  7. jb4pres

    Doug Barr Guest

    ok... movin on.
     
    Doug Barr, Jul 8, 2004
    #7
  8. jb4pres

    jb4pres Guest

    Wow ... that was exciting ... I posted this little thing and suddenly everybody is a critic. I do not know how to write code. Id like to learn, but I am swamped here at work and don't have the time I'd like to learn it. I will at some point. I asked for help simply to make life easier. I know if someone had a question about how to build a Jeep from the dead carcass of Jeep. (I rebuilt mine by hand.) I would be more than happy to help and would probably just jump in and get dirty without bringing out the point that he is not as well schooled in the task at hand.

    I applaud all of you for your extensive knowledge! I would love to have more time to learn this but time is of the essence so to speak and I have to finish this project on time. Learning will have to wait.

    Thank you for your time!!
    Eric
     
    jb4pres, Jul 8, 2004
    #8
  9. jb4pres

    Doug Barr Guest

    <disclaimer>
    Being an expert in o so few things, I
    may be wrong in what I'm about to say.
    </disclaimer>

    I've always seen this group as both

    a) a place where users may request assistance
    with a task that deserves customization

    and

    b) a classroom for aspiring customizers

    Your needs clearly fall into category (a).

    If you want to expand the capabilities of
    the routine that I so poorly wrote for you
    (though, oddly, it did the job), I'll gladly
    do it via email. Please send your unmunged
    address to me and I'll be glad to assist.




    everybody is a critic. I do not know how to write code. Id like to learn, but
    I am swamped here at work and don't have the time I'd like to learn it. I will
    at some point. I asked for help simply to make life easier. I know if someone
    had a question about how to build a Jeep from the dead carcass of Jeep. (I
    rebuilt mine by hand.) I would be more than happy to help and would probably
    just jump in and get dirty without bringing out the point that he is not as well
    schooled in the task at hand.
    time to learn this but time is of the essence so to speak and I have to finish
    this project on time. Learning will have to wait.
     
    Doug Barr, Jul 8, 2004
    #9
  10. jb4pres

    jb4pres Guest

    Doug,

    Your routine works wonderfully! I have used it a couple hundred times a day since you wrote it. I thank you for that! As I am under the gun I am looking for more ways to speed this up... My deadline is fast approaching. As of right now my dwg has 2473 layers and It will have over 3000 when I am done. With your help you have saved me considerable time, but time is running out for me.

    Thanks,
    Eric
     
    jb4pres, Jul 8, 2004
    #10
  11. I wasn't pointing out that you weren't "well-schooled". I only pointed out
    the code will be difficult to maintain in the long run due to those variable
    names.

    I asked for clarification on what you want the routine to do, as the bit
    about the "two lines" isn't well explained. I guess that point got missed in
    the 'critic-storm'.

    Now, you can certainly take this off-line with Doug, but then no one else
    that lurks here will benefit from the solution. That choice is yours.

    --
    R. Robert Bell


    Wow ... that was exciting ... I posted this little thing and suddenly
    everybody is a critic. I do not know how to write code. Id like to learn,
    but I am swamped here at work and don't have the time I'd like to learn it.
    I will at some point. I asked for help simply to make life easier. I know
    if someone had a question about how to build a Jeep from the dead carcass of
    Jeep. (I rebuilt mine by hand.) I would be more than happy to help and would
    probably just jump in and get dirty without bringing out the point that he
    is not as well schooled in the task at hand.

    I applaud all of you for your extensive knowledge! I would love to have
    more time to learn this but time is of the essence so to speak and I have to
    finish this project on time. Learning will have to wait.

    Thank you for your time!!
    Eric
     
    R. Robert Bell, Jul 8, 2004
    #11
  12. jb4pres

    jb4pres Guest

    When I said lines I meant layers... sorry for the confusion.

    I want to create 2 layers based on an existing layer.
     
    jb4pres, Jul 8, 2004
    #12
  13. jb4pres

    Doug Barr Guest

    I'll keep it going in here...

    I eliminated the layer-suffix prompts, since Eric needs only those two, and with
    those specific colors. I matched the linetype to that of the picked line. It
    'M'akes the new layers, though it could have as easily made 'N'ew layers, and
    have done it in one command.

    I simplified everything for people who like to see things simpler, tho I doubt
    Eric will be able to see the step by step progression of entsels and entgets and
    cdrs etc. But heck, if I'm going to provide fish, why not cook it as well.

    As always... PLEASE make improvements as you see them.
    -doug

    (defun c:cpl ( / layername layerlinetype l-cen l-edg)
    (princ "\nPick Line on Layer to copy:")
    (setq linepick (entget (car (entsel)))
    layername (cdr (assoc 8 linepick))
    layerlinetype (cdr (assoc 6 (tblsearch "LAYER" layername)))
    l-cen (strcat layername " - CEN")
    l-edg (strcat layername " - EDG"))
    (command "LAYER" "M" l-cen "c" "2" l-cen "lt" layerlinetype l-cen "")
    (command "LAYER" "M" l-edg "c" "1" l-edg "lt" layerlinetype l-edg "")
    (princ)
    )
     
    Doug Barr, Jul 8, 2004
    #13
  14. jb4pres

    jb4pres Guest

    Wow ... now that is a time saver!! remind me to buy drinks!!
     
    jb4pres, Jul 8, 2004
    #14
  15. jb4pres

    jb4pres Guest

    Now all I need is a command to do all my work and I could go work on my Jeep!!!
     
    jb4pres, Jul 8, 2004
    #15
  16. jb4pres

    Doug Barr Guest

    Wait a few years... build a company... hire employees.
    My 59yrold boss has all the time in the world for his projects.

    currently:
    - replacing the manual gearbox with an auto in his 35 Chevy
    hotrod so he can 'drive his daughter down the aisle' at her
    October wedding without it popping out of 2nd
    - changing the rear end on his Chevelle drag racer since it
    tends to roll when he gets it under 11.5 seconds
    - waxing his '64 Stingray
    - sandblasting the body of a 57 Nomad he's restoring
    - converting a fwd Cadillac Seville to a rwd 500cu.in dragracer
    - modfiying the gear ratios electronically in his Silverado truck
    - changing the oil on his '03 Corvette Z06

    And we don't even get rides!
    -doug

    Jeep!!!
     
    Doug Barr, Jul 8, 2004
    #16
  17. jb4pres

    Doug Broad Guest

    Eric,
    Just curious. How does having 3000 or more
    layers in a single drawing improve your productivity?

    I find it is very easy to create more layers than I need.

    Regards,
    Doug


    under the gun I am looking for more ways to speed this up... My deadline is fast approaching. As of right now my dwg has 2473
    layers and It will have over 3000 when I am done. With your help you have saved me considerable time, but time is running out for
    me.
     
    Doug Broad, Jul 8, 2004
    #17
  18. jb4pres

    jb4pres Guest

    ok last time I will ask something of this code...

    Is there something we can change so that I can select a line prior to running the copy command?
     
    jb4pres, Jul 8, 2004
    #18
  19. jb4pres

    Doug Barr Guest

    I always use pickfirst set to 0, so it didn't even occur to me.
    I can see that it doesn't work 'in reverse'.

    Sounds like a job for Visual Lisp... Robert?


    the copy command?
     
    Doug Barr, Jul 8, 2004
    #19
  20. I posted that yesterday morning. Check up the thread a bit! ;^)

    --
    R. Robert Bell


    I always use pickfirst set to 0, so it didn't even occur to me.
    I can see that it doesn't work 'in reverse'.

    Sounds like a job for Visual Lisp... Robert?


    running
    the copy command?
     
    R. Robert Bell, Jul 9, 2004
    #20
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.