+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 16
  1. #1
    Full Member
    Using
    AutoCAD 2009
    Join Date
    Nov 2008
    Posts
    51

    Default Getting All Names Of Multiply Nested Block

    Registered forum members do not see this ad.

    Hello.

    I'm just wondering if it's possible to create a routine that can.. well, ok:

    I want to select a selection set of blocks.
    For each block in SS, find name in blocks collection.
    if the block has the property "count" (meaning it's nested)
    get all the names that are inside that block.
    If one of THOSE blocks has the property "count"
    get all the names that are inside THAT block...

    etc etc etc...

    Seems like it should be easy, but I can't get my mind around how to make it failproof. I also don't want to list more than one of the same named item. Basically I just want to know all the blocks that are inside each block.

    I've written and re-written this thing several times, and am not sure the correct way to do this. It seems like a re-cursive type deal, but I can't figure it out.

    Any help is appreciated. thanks.

  2. #2
    Forum Deity
    Using
    AutoCAD 2009
    Join Date
    Oct 2008
    Posts
    2,112

    Default

    Quote Originally Posted by Iheartpoulsbo@gmail.com View Post
    Hello.

    I'm just wondering if it's possible to create a routine that can.. well, ok:

    I want to select a selection set of blocks.
    For each block in SS, find name in blocks collection.
    if the block has the property "count" (meaning it's nested)
    get all the names that are inside that block.
    If one of THOSE blocks has the property "count"
    get all the names that are inside THAT block...

    etc etc etc...

    Seems like it should be easy, but I can't get my mind around how to make it failproof. I also don't want to list more than one of the same named item. Basically I just want to know all the blocks that are inside each block.

    I've written and re-written this thing several times, and am not sure the correct way to do this. It seems like a re-cursive type deal, but I can't figure it out.

    Any help is appreciated. thanks.


    Please post the code so we can tell what you are doing wrong.

  3. #3
    Forum Deity
    Using
    AutoCAD 2009
    Join Date
    Oct 2008
    Posts
    2,112

    Default

    Basically I just want to know all the blocks that are inside each block.
    Just want to mention, If you are trying to nest a block inside of a block and expect to get information from a nested block, Then you are wasting your time. Not sure if that is what you are doing. The problem you mention does not seem clear.

    Can you elaborate on what exactly you are trying to do?
    Or am I misinterpreting you?

    Please explain in detail.

    Thanks,
    The Buzzard

  4. #4
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,732

    Default

    I think this may work, but I reckon there are better routines out there:

    Code:
    (defun GetObj (blk / bObj lst)
      (if
        (and
          (setq lst (cons blk lst))
          (not
            (vl-catch-all-error-p
              (vl-catch-all-apply
                (function
                  (lambda ( )
                    (setq bObj
                      (vla-item
                        (vla-get-blocks
                          (vla-get-ActiveDocument
                            (vlax-get-acad-object))) blk))))))))
        (vlax-for Obj bObj
          (and (eq "AcDbBlockReference"
                 (vla-get-ObjectName Obj))
               (setq lst (cons (vla-get-Name Obj) lst))
               (getObj (vla-get-Name Obj)))))
      lst)
    
    (vl-load-com)
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  5. #5
    Forum Deity
    Using
    AutoCAD 2009
    Join Date
    Oct 2008
    Posts
    2,112

    Default

    Quote Originally Posted by Lee Mac View Post
    I think this may work, but I reckon there are better routines out there:

    Code:
    (defun GetObj (blk / bObj lst)
      (if
        (and
          (setq lst (cons blk lst))
          (not
            (vl-catch-all-error-p
              (vl-catch-all-apply
                (function
                  (lambda ( )
                    (setq bObj
                      (vla-item
                        (vla-get-blocks
                          (vla-get-ActiveDocument
                            (vlax-get-acad-object))) blk))))))))
        (vlax-for Obj bObj
          (and (eq "AcDbBlockReference"
                 (vla-get-ObjectName Obj))
               (setq lst (cons (vla-get-Name Obj) lst))
               (getObj (vla-get-Name Obj)))))
      lst)
     
    (vl-load-com)
    Lee,

    Just curious, What does that code do?

  6. #6
    Forum Deity
    Using
    AutoCAD 2009
    Join Date
    Oct 2008
    Posts
    2,112

    Default

    Quote Originally Posted by The Buzzard View Post
    Lee,

    Just curious, What does that code do?

    Is this code to pull up dxf information of a dynamic block?

  7. #7
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,732

    Default

    Quote Originally Posted by The Buzzard View Post
    Lee,

    Just curious, What does that code do?
    Hi Buzzard,

    The code needs to be provided with a block name, and if it can find that particular block in the block collection, it will iterate through the Block Object Collection and search for any Block References that make up the block (i.e, nested blocks), if it finds one, then it will get its name and recursively operate on that new name, whilst constructing a list of all the names found. Not sure if it will work or not, just a "theoretical" post.

    Just gotta watch that the stack limit isn't reached when using recursive loops. I tend to only use them for small-ish tasks, as the stack limit is not too high and can sometimes be reached quite easily.

    Some great info on recursive programming here.

    Lee
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  8. #8
    Forum Deity
    Using
    AutoCAD 2009
    Join Date
    Oct 2008
    Posts
    2,112

    Default

    Quote Originally Posted by Lee Mac View Post
    Hi Buzzard,

    The code needs to be provided with a block name, and if it can find that particular block in the block collection, it will iterate through the Block Object Collection and search for any Block References that make up the block (i.e, nested blocks), if it finds one, then it will get its name and recursively operate on that new name, whilst constructing a list of all the names found. Not sure if it will work or not, just a "theoretical" post.

    Just gotta watch that the stack limit isn't reached when using recursive loops. I tend to only use them for small-ish tasks, as the stack limit is not too high and can sometimes be reached quite easily.

    Some great info on recursive programming here.

    Lee
    That site is way over my head. But that is interesting if it can be done. Not sure where the value is in nesting. Maybe I learn something new here.

  9. #9
    Super Member David Bethel's Avatar
    Discipline
    Multi-disciplinary
    David Bethel's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Commercial Food Service
    Using
    AutoCAD pre 2000
    Join Date
    Dec 2003
    Location
    Newport News, Virginia
    Posts
    1,926

    Default

    I think I understand the request:

    Code:
    (defun c:nbc (/ tdef fe fd bn nl)
      (while (setq tdef (tblnext "BLOCK" (not tdef)))
             (setq fe (cdr (assoc -2 tdef)))
             (princ (strcat "\n" (cdr (assoc 2 tdef))))
             (while fe
                (setq fd (entget fe)
                      fe (entnext fe))
                (and (= "INSERT" (cdr (assoc 0 fd)))
                     (setq bn (cdr (assoc 2 fd)))
                     (if (not (assoc bn nl))
                         (setq nl (cons (cons bn 1) nl))
                         (setq nl (subst (cons bn (1+ (cdr (assoc bn nl))))
                                         (assoc bn nl) nl))))))
    
       (textpage)
       (prin1 nl)
       (foreach b nl
         (princ (strcat "\nBlock " (car b)
                        " Is Nested In " (rtos (cdr b) 2 0) " Block(s)")))
       (prin1))
    nl contains an associative list of dotted pair atoms
    ( block_name . number_of_nested_direct_instances_found )

    This does not count the nested depth or total number of nested occurrences in the drawing. -David
    R12 (Dos) - A2K

  10. #10
    Full Member
    Using
    AutoCAD 2009
    Join Date
    Nov 2008
    Posts
    51

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by The Buzzard View Post
    Just want to mention, If you are trying to nest a block inside of a block and expect to get information from a nested block, Then you are wasting your time. Not sure if that is what you are doing. The problem you mention does not seem clear.

    Can you elaborate on what exactly you are trying to do?
    Or am I misinterpreting you?

    Please explain in detail.

    Thanks,
    The Buzzard
    You can get the information from a nested block by using the blocks collection, which contains all blocks in the drawing, and also has information on whether blocks are 'inside' that block.

    Suppose I have a block for a part. Inside that part there are several more blocks. Some of the blocks inside those might have a block or two. So I want a routine that can, when I select that main part block, it get the name.. then finds the name in the block collection, and goes through the block collection for each name that resides somewhere inside that main block.

    It can be done, it's just not pretty.. especially if you don't know how many blocks are nested, and you want to get all of them no matter what.

Similar Threads

  1. changing a bunch of names into the same block
    By chelsea1307 in forum AutoCAD General
    Replies: 2
    Last Post: 4th Mar 2009, 06:34 pm
  2. Change Block Names?
    By comcu in forum AutoCAD Drawing Management & Output
    Replies: 3
    Last Post: 12th Oct 2007, 10:54 pm
  3. Making a block with nested blocks
    By Merthen56 in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 24th May 2006, 06:33 pm
  4. multiply symbols containing numbers that increase
    By horstknorst in forum AutoCAD General
    Replies: 1
    Last Post: 7th May 2006, 06:09 pm
  5. multiply objects along path
    By horstknorst in forum AutoCAD General
    Replies: 2
    Last Post: 7th May 2006, 10:32 am

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts