Find number of objects a layer is associated to.. Help

Discussion in 'AutoCAD' started by T.Willey, Sep 23, 2004.

  1. T.Willey

    T.Willey Guest

    I always have problems purging drawings. All the layers that are not in use, or are old, don't leave. I wrote this routine to find what type of objects have a certain layer associated with it so that one can just move those objects to the new layers. It also looks through the block table for items in the block so that if need be one could redefine the block. For the most part it works, but there are still layers left beind, and my routine can't find any objects associated with them. Maybe some here knows a little more that can help me see what I'm not covering, or if there is just no way to find the objects.

    Any help is appreciated.
    Tim

    ps. here is the routine, the dialog box is used to select a layer.

    (defun c:ChaseLayer (/ laylist op1 ss ent1 etyp1 elist ltyp1 cnt1 nlist lay1)

    (setq laylist (TableList "Layer"))
    (setq laylist (vl-sort laylist '<))
    (setq op1 (load_dialog "CloseDwg.dcl"))
    (if (not (new_dialog "Cdrawings" op1))
    (exit)
    )
    (mode_tile "d-save" 1)
    (start_list "tx2" 3)
    (mapcar 'add_list laylist)
    (end_list)
    (action_tile "accept"
    "(progn
    (setq lay1 (get_tile \"tx2\"))
    (done_dialog 1)
    )"
    )
    (action_tile "cancel"
    "(progn
    (vl-exit-with-value nil)
    (done_dialog 1)
    )"
    )
    (start_dialog)
    (setq lay1 (nth (atoi lay1) laylist))
    (if (setq ss (ssget "x" (list (cons 8 lay1))))
    (progn
    (while (/= (sslength ss) 0)
    (setq ent1 (entget (ssname ss 0)))
    (setq etyp1 (value 0 ent1))
    (setq elist (cons etyp1 elist))
    (ssdel (ssname ss 0) ss)
    )
    (setq elist (vl-sort elist '>))
    (while (> (vl-list-length elist) 0)
    (setq ltyp1 (car elist))
    (setq cnt1 0)
    (while (= (car elist) ltyp1)
    (setq cnt1 (1+ cnt1))
    (setq elist (cdr elist))
    )
    (setq nlist (cons (cons ltyp1 cnt1) nlist))
    )
    (prompt (strcat "\n------ Layer - \"" lay1 "\" ------"))
    (foreach item nlist
    (prompt (strcat "\n Objects - " (car item) "\n Amount - " (rtos (cdr item) 2 0)))
    )
    (CntItemsNBlk lay1)
    (textscr)
    ); progn
    ); if
    (princ)
    )

    ;-------------------------------------------------------------

    (defun CntItemsNBlk (layname / cnt1 blocks blkname blklst bname tbl1 llist)
    ; Begining taken from Joe Burke's Countblocks routine

    (setq blocks (vla-get-blocks (vla-get-activedocument(vlax-get-acad-object))))
    (vlax-for blk blocks
    (setq blkname (strcase (vlax-get blk 'Name)))
    (if
    (and
    (not (vl-string-search "|" blkname)) ;filter blocks in xrefs
    (not (vl-string-search "*" blkname)) ;filter "*MODEL_SPACE" "*PAPER_SPACE"
    (/= -1 (vlax-get blk 'IsXRef)) ;filter xref blocks
    ) ;don't filter Paste As blocks
    (setq blklst (cons blk blklst))
    )
    ); for

    (foreach item blklst
    (setq bname (Getx item 'Name))
    (setq cnt1 0)
    (setq tbl1 (tblobjname "block" bname))
    (while (setq tbl1 (entnext tbl1))
    (if (= (value 8 (entget tbl1)) layname)
    (setq cnt1 (1+ cnt1))
    ); if
    ); while
    (if (> cnt1 0)
    (setq llist (cons (cons bname cnt1) llist))
    ); if
    ); for
    (if llist
    (progn
    (princ "\n")
    (foreach item llist
    (prompt (strcat "\n Block Name - " (car item) "\n Amount of object(s) within - " (rtos (cdr item) 2 0)))
    ); for
    )
    )
    )

    ;;====Sub-Routines.

    (defun GetX (object prop)
    (if (vlax-property-available-p object prop)
    (vlax-get object prop)
    )
    )

    (defun VALUE (num ent /)
    (cdr (assoc num ent))
    )

    (defun TableList (TblName / tbl1 vlist cnt1)

    (setq cnt1 T)
    (while (setq tbl1 (tblnext TblName cnt1))
    (setq vlist (cons (value 2 tbl1) vlist))
    (setq cnt1 nil)
    )
    vlist
    )
     
    T.Willey, Sep 23, 2004
    #1
  2. Have you checked for layers frozen in a viewport?

    --
    Autodesk Discussion Group Facilitator



    <snip>
     
    Jason Piercey, Sep 23, 2004
    #2
  3. Express Tools' Layer Merge will do what I think you're after. You may need
    to use the Type It option to designate some layer(s). It will even
    re-define blocks that use entities on the Layer(s) you want to merge into
    another one, and will purge that old Layer out of the drawing in the
    process.

    Kent Cooper, AIA

    ...
     
    Kent Cooper, AIA, Sep 23, 2004
    #3
  4. T.Willey

    T.Willey Guest

    On the current drawing I'm working on, the layer is not frozen in any viewports, and I still can't find it attached to anything, and it won't purge.

    Any other suggestions?

    Tim
     
    T.Willey, Sep 23, 2004
    #4
  5. SEQEND in an attributed insert ?
     
    Jason Piercey, Sep 23, 2004
    #5
  6. or, the ATTRIB in an insert for that matter.....
     
    Jason Piercey, Sep 23, 2004
    #6
  7. T.Willey

    Dan Allen Guest

    or mundane things like invisible objects (group code 60?), zero length
    lines, blank text, blocks with the layer defined but no entities on it,
    etc...

    Other than ERASE > ALL > unselect visible objects, LAYMRG is your best
    friend...

    Dan

    viewports, and I still can't find it attached to anything, and it won't
    purge.
     
    Dan Allen, Sep 23, 2004
    #7
  8. If you've searched the block table and didn't find anything on the subject
    layer, this may not help, but:

    With either Layer Delete or Layer Merge (with the Type It option since you
    can't pick anything), if there are any entities on the layer(s) you're
    dumping within block definitions, you'll be able to tell that that's the
    reason, because it will warn you with a message about how many block
    definitions use that layer, and asking whether you want to go ahead and
    redefine the blocks (either to eliminate those entities under Layer Delete,
    or to change them to another layer with Layer Merge). I don't recall
    whether it tells you what the block definitions are that it's redefining,
    though.

    Kent Cooper, AIA


    ...
     
    Kent Cooper, AIA, Sep 23, 2004
    #8
  9. T.Willey

    Tom Smith Guest

    The definitive way to find the layer is to do a dxfout and then study the
    dxf file. It may be tedious, but it's a lot quicker than writing a program
    sifficiently complex to accomplish the same thing. There isn't anything
    "hidden" in the dxf file. Search it for the layer name and you'll see where
    it's being used.

    If you "always have problems" with this, you'd probably benefit by actually
    seeing how and where the layers are sneaking in, so you can change your
    drawing methods or blocks to prevent it in the future.
     
    Tom Smith, Sep 24, 2004
    #9
  10. T.Willey

    T.Willey Guest

    Just for learning purposes. Is there a way to get the information of a block as what layers are in blocks with no objects?

    Tim
     
    T.Willey, Sep 24, 2004
    #10
  11. T.Willey

    T.Willey Guest

    Thanks Jason for both of those points. I thought I was checking them, but when I reread my code I was only checking the block table versions of Attrib. I did a check for what you posted, and after I changed them I was able to purge out that layer.

    Thanks.
    Tim
     
    T.Willey, Sep 24, 2004
    #11
  12. T.Willey

    T.Willey Guest

    Thanks Tom for that insight. After I read your post I tried your idea. It worked!. I could tell where that layer was, and with some other insite from Jason earlier, I was able to find that layer. The problem is that we have so many consultants, and the standards weren't being enforced before I got here, that our drawings now are a mess. Just trying to clean them up now.

    Thanks for the insight.
    Tim
     
    T.Willey, Sep 24, 2004
    #12
  13. T.Willey

    Tom Smith Guest

    No problem. When I've had something unpurgeable, I've learned that if I
    can't find it in a few seconds by rounding up the usual suspects, it's
    quicker to just go straight to the dxf than to search otherwise. Depending
    on the situation, it may be appropriate to do a "search and replace" to
    change the bad layer name to 0 in the dxf. Then open it and save back to the
    dwg name & you're done.
     
    Tom Smith, Sep 24, 2004
    #13
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.