Looking for a Lisp...

Discussion in 'AutoCAD' started by kusa24, Apr 27, 2004.

  1. kusa24

    kusa24 Guest

    Does anyone know of a Lisp routine or something that will change all object colors, linetypes, etc to bylayer?

    We get architectural files in all the time that we need to change to 2-3 differnt colors and lietypes, and since architects seem to like to use 257 of AutoCAD's 256 colors I was hoping to find something that would change everything much simpler than doing it manually.

    Thanks!
     
    kusa24, Apr 27, 2004
    #1
  2. kusa24

    cadtown Guest

    Why do you need a Lisp routine to do this ?
    Doesn't Object Properties dialog let you do this already ?

    http://www.cadtown.com
     
    cadtown, Apr 27, 2004
    #2
  3. kusa24

    Jeff Mishler Guest

    How does the Object Properties affect entities within blocks? Or those on
    locked layers?

    BTW, the solution was posted to another thread a few weeks ago.

    Jeff
     
    Jeff Mishler, Apr 27, 2004
    #3
  4. kusa24

    Jeff Mishler Guest

    How does the Change command affect entities within blocks? Or those on
    locked layers?

    BTW, the solution was posted to another thread a few weeks ago.

    Jeff

    differnt colors and lietypes, and since architects seem to like to use 257
    of AutoCAD's 256 colors I was hoping to find something that would change
    everything much simpler than doing it manually.
     
    Jeff Mishler, Apr 27, 2004
    #4
  5. Why do you need a Lisp routine to do this ?
    OP won't handle sub-entities of parent object (I.e. Lines that make up a
    block, etc.)


    --
    Darren J. Young
    CAD/CAM Systems Developer

    Cold Spring Granite Company
    202 South Third Avenue
    Cold Spring, Minnesota 56320

    Email:
    Phone: (320) 685-5045
    Fax: (320) 685-5052
     
    Darren J. Young, Apr 27, 2004
    #5
  6. kusa24

    Jeff Mishler Guest

    Here's the one I could've swore I posted before, but I couldn't find it in a
    search......
    It'll allow you to change just the color or linetype or both to bylayer. The
    main routine is a seperate function so you could call it from a button and
    have no user interaction if desired. To do that the button command would be
    like this for changing only the color to bylayer: ^C^C(all2bylayer t nil);

    HTH,
    Jeff

    ;;Routine to change all drawing entities color or linetype, or both,
    ;;to Bylayer.
    ;;by Jeff Mishler April 2004

    (defun c:bylayer (/ ans)
    (initget "Color Linetype Both")
    (setq ans (getkword "\nConvert ALL entity colors &/or linetypes to
    bylayer...[Color/Linetype/Both]: "))
    (cond ((= ans "Color")(all2bylayer t nil)
    (princ "\nAll objects' color now Bylayer...."))
    ((= ans "Linetype")(all2bylayer nil t)
    (princ "\nAll objects' linetypes now Bylayer...."))
    ((= ans "Both")(all2bylayer t t)
    (princ "\nAll objects' color & linetype now Bylayer...."))
    (princ "\nNo option selected, exiting.....")
    )
    (princ)
    )

    (defun all2bylayer (color linet / doc layers lokt)
    (setq doc (vla-get-activedocument(vlax-get-acad-object))
    layers (vla-get-layers doc))
    (vlax-for lay layers
    (if (= :vlax-true (vla-get-lock lay))
    (progn
    (setq lokt (cons lay lokt))
    (vla-put-lock lay :vlax-false)
    )
    )
    )
    (vlax-for blk (vla-get-blocks doc)
    (if (and (eq (vla-get-isxref blk) :vlax-false)
    (not (wcmatch (vla-get-name blk) "*|*"))
    )
    (vlax-for ent blk
    (if (and color (vlax-property-available-p ent 'color))
    (vlax-put ent 'color acbylayer))
    (if (and linet (vlax-property-available-p ent 'linetype))
    (vlax-put ent 'linetype "BYLAYER"))
    )
    )
    )
    (if lokt (mapcar '(lambda (x)
    (vla-put-lock x :vlax-true))
    lokt))
    )


    object colors, linetypes, etc to bylayer?
    differnt colors and lietypes, and since architects seem to like to use 257
    of AutoCAD's 256 colors I was hoping to find something that would change
    everything much simpler than doing it manually.
     
    Jeff Mishler, Apr 27, 2004
    #6
  7. kusa24

    Jamie Duncan Guest

    An alternative solution using lisp...

    (defun c:fixents (/ ss1 temp ent1 looper entdat bnm ctr enttyp bl_list)
    (command ".layer" "t" "0" "un" "0" "s" "0" "")
    (setq ss1 (ssadd) looper T ctr 0)
    (while looper
    (prompt "\nSelect Entities to set to Bylayer for Colour and Linetype: ")
    (setq ss1 (ssget))
    (if ss1 (setq looper nil))
    )
    (repeat (sslength ss1)
    (setq ent1 (ssname ss1 ctr) entdat (entget ent1) enttyp (cdr (assoc 0
    entdat)))
    (if (= enttyp "INSERT")
    (progn
    (setq bl_list (list (cdr (assoc 2 entdat))))
    (foreach bnm bl_list
    (jddfixablock bnm)
    )
    )
    (progn
    (setq entdat (subst (cons 62 256)(assoc 62 entdat) entdat)
    entdat (subst (cons 6 "Bylayer")(assoc 6 entdat) entdat)
    )
    (entmod entdat)(entupd ent1)
    )
    )
    (setq ctr (+ ctr 1))
    )
    (princ)
    )
    (defun jddfixablock (bname / enam1 end1)
    (setq enam1 (tblobjname "block" bname))
    (while (setq enam1 (entnext enam1))
    (setq end1 (entget enam1)
    end1 (subst (cons 62 256)(assoc 62 end1) end1))
    end1 (subst (cons 6 "Bylayer")(assoc 6 end1) end1))
    end1 (subst (cons 8 "0")(assoc 8 end1) end1))
    )
    (entmod end1)
    (if (= (cdr (assoc 0 (entget enam1))) "INSERT")
    (setq bl_list (append bl_list (list (cdr (assoc 2 (entget
    ent1)))))))
    )
    )


    HTH

    Jamie Duncan

    (I like the recursive part for nested blocks)




     
    Jamie Duncan, Apr 27, 2004
    #7
  8. kusa24

    Joe Burke Guest

    Jeff,

    Just curious. Don't you think if layer locked/unlocked status might change, resetting
    such should be done in an error handler? Similar to changing sys vars.

    Joe Burke

     
    Joe Burke, Apr 27, 2004
    #8
  9. kusa24

    Jeff Mishler Guest

    Joe,
    You are probably correct.

    You may have noticed in my other posts that I rarely use an error handler at
    all.

    This is due to:
    1. Bad coding habits
    2. I usually don't Cancel out of a known lisp command out of habit after
    using Softdesk/AdCadd/LDD all these years where your system would be left in
    complete dis-array if you did issue a cancel......
    3. When I'm relatively confident that there is no error going to be
    encountered other than an ESC while it is processing I won't bother.
    4. These are usually bits & pieces of other code I've written that I put
    together to help with a specific question. If the user wants/needs error
    handling they can add it.


    That being said, I am going to make a concerted effort to do a better job of
    including a handler in most of my posts or at least note that one may be
    desired/required.

    Thanks,
    Jeff

     
    Jeff Mishler, Apr 27, 2004
    #9
  10. Have you ever considered the CAD Standards feature?

    --
    R. Robert Bell


    Does anyone know of a Lisp routine or something that will change all object
    colors, linetypes, etc to bylayer?

    We get architectural files in all the time that we need to change to 2-3
    differnt colors and lietypes, and since architects seem to like to use 257
    of AutoCAD's 256 colors I was hoping to find something that would change
    everything much simpler than doing it manually.

    Thanks!
     
    R. Robert Bell, Apr 27, 2004
    #10
  11. kusa24

    Joe Burke Guest

    Jeff,

    As you know, nothing will reveal a potential problem faster than convincing yourself
    not much can go wrong. ;-)

    Agreed, it's sufficient to simply indicate, "minimal error checking" or something
    similar. You've been very generous helping folks here. I didn't mean to imply you
    should spend more time along these lines. Though I guess my comment sounded like
    that.

    Regards
    Joe Burke


     
    Joe Burke, Apr 28, 2004
    #11
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.