Move everything including blocks to layer 0

Discussion in 'AutoCAD' started by perriwinkle, Dec 13, 2004.

  1. perriwinkle

    perriwinkle Guest

    Yes, I know it is a bizarre and almost sickening request, but in this case it is necessary. I need to make a complete transfer of everything no questions asked with the press of one button. I've looked at fixblock, but it request input, and that is not acceptable. Working with blocks is complicated and I don't really understand it. I know that I have to step through the association set of each entity that makes up the block, but I just can't get it.

    (defun c:simplepart ()
    (command "chprop" "all" "" "layer" "0" "")
    (setq ss (ssget "x" (list (cons 0 "insert"))))
    (setq lnthss (sslength ss))
    (setq counter 0)
    (setq newlayer (cons 8 "0"))
    (while (< counter lnthss)


    This is where I get lost...

    do I

    (setq entname (tblsearch "block" (cdr(assoc 2 (entget (ssname ss counter))))))

    then

    (while entname
    (setq old (cons 2 (cdr (assoc 2 entname))))
    (setq entlist (entget entname))
    (setq entlist (subst newlayer oldlayer entlist))
    (entmake entlist)
    (nextent)
    )
    (setq counter (+1 counter))
    )

    Ok, I know that isn't what I do because it doesn't work, but what do I do??

    I've been stuck on this for days! all weekend as a matter of fact and its driving me crazy. Any help would be appreciated.
     
    perriwinkle, Dec 13, 2004
    #1
  2. If it was me, i'd modify the fixblock routine to skip the user input part
    and just select all objects instead of re-inventing (if that's the goal)

    it is necessary. I need to make a complete transfer of everything no
    questions asked with the press of one button. I've looked at fixblock, but
    it request input, and that is not acceptable. Working with blocks is
    complicated and I don't really understand it. I know that I have to step
    through the association set of each entity that makes up the block, but I
    just can't get it.
    driving me crazy. Any help would be appreciated.
     
    Casey Roberts, Dec 13, 2004
    #2
  3. perriwinkle

    T.Willey Guest

    Try this. It only changes the layer, not linetype or color.

    Tim

    (defun c:ChangeAllToLay0 (/ ss Ent Obj AttList BlkCol)

    (if (setq ss (ssget "x"))
    (progn
    (while (setq Ent (ssname ss 0))
    (setq Obj (vlax-ename->vla-object Ent))
    (vla-put-Layer Obj "0")
    (ssdel Ent ss)
    )
    )
    )
    (setq BlkCol (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-ACAD-Object))))
    (vlax-for item BlkCol
    (vlax-for item2 item
    (vla-put-Layer item2 "0")
    )
    )
    (if (setq ss (ssget "x" '((0 . "INSERT") (66 . 1))))
    (progn
    (setq Ent (ssname ss 0))
    (setq Obj (vlax-ename->vla-object Ent))
    (setq AttList
    (safearray-value
    (variant-value
    (vlax-invoke-method Obj 'GetAttributes)
    )
    )
    )
    (foreach item AttList
    (vla-put-Layer item "0")
    )
    (ssdel Ent ss)
    )
    )
    (princ)
    )
     
    T.Willey, Dec 13, 2004
    #3
  4. perriwinkle

    T.Willey Guest

    Forgot. You need to add (vl-load-com) to the begining of the routine.

    Tim
     
    T.Willey, Dec 13, 2004
    #4
  5. perriwinkle

    j buzbee Guest

    If you remember that all objects in Model Space ( and Paper space) are
    actually nested objects in the *model_space* block then you would see that
    iterating through the blocks collection would catch everything.

    (defun c:jbchangetozero( / jbThisDrawing i ii cnt)
    (vl-load-com)
    (setq cnt 0
    jbThisDrawing(vla-get-activedocument(vlax-get-acad-object)))
    (vla-put-activelayer jbThisDrawing (vla-item(vla-get-layers
    jbThisDrawing)"0"))
    (vlax-for i (vla-get-blocks jbThisDrawing)
    (princ (strcat "\nChecking Block " (vla-get-name i)))
    (vlax-for ii i
    (setq cnt(1+ cnt))
    (vla-put-layer ii "0")))
    (princ (strcat "\n" (itoa cnt) " Object(s) Changed to Layer 0 "))
    (princ)
    )

    jb
     
    j buzbee, Dec 13, 2004
    #5
  6. perriwinkle

    T.Willey Guest

    Good point jb. I'm still getting used to thinking in that way.

    Tim
     
    T.Willey, Dec 13, 2004
    #6
  7. perriwinkle

    perriwinkle Guest

    YOU ARE THE BOMB!!! Now if you get time sometime to explain what you did that it would be even better! I didn't mean to re-invent the wheel earlier, I just couldn't get it to work without asking for input... I didn't understand it well enough to modify it. I couldn't ask for a better Christmas present! THANKS!!
     
    perriwinkle, Dec 13, 2004
    #7
  8. perriwinkle

    T.Willey Guest

    Well, in the first part I searched the entire drawing data base, and change all objects to layer 0. Then I get the block collection for the current drawing open. With that I went through all blocks and changed all those objects to layer 0. Then I searched the drawing data base for all blocks that have attributes. Once got all of these, I grabbed all the attributes and stepped through each one a changed them to layer 0.

    Hope that makes it clear. Glad I could make your Christmas. Happy Holidays to all.

    Tim
     
    T.Willey, Dec 13, 2004
    #8
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.