+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 15
  1. #1
    Junior Member
    Using
    AutoCAD 2012
    Join Date
    Aug 2012
    Posts
    12

    Default Explode nested blocks only

    Registered forum members do not see this ad.

    Hi all,

    Is there a way to explode nested blocks within a block without exploding the original block that is shown in my drawing?

    Any help would be greatly appreciated.

  2. #2
    Forum Deity MSasu's Avatar
    Discipline
    Construction
    MSasu's Discipline Details
    Occupation
    engineer
    Discipline
    Construction
    Details
    AutoLISP programmer
    Using
    AutoCAD 2013
    Join Date
    Mar 2009
    Location
    Brasov, Romania
    Posts
    3,951

    Default

    If is about only one block, then call BEDIT command and next use QSELECT or FILTER to find all nested blocks and explode them. Save the changes to said block definition.
    Regards,
    Mircea

    AutoCAD's happy user equation: FILEDIA + PICKADD² + PICKFIRST = 3

  3. #3
    Junior Member
    Using
    AutoCAD 2012
    Join Date
    Aug 2012
    Posts
    12

    Default

    Thanks for the reply MSasu,

    Unfortunately there are many different blocks, most of them only occur once or twice within my drawing. I was hoping to select all the blocks and explode all of the nested blocks so that they retain their block definition but only on one level rather than the several levels that they are currently on.

  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
    16,866

    Default

    Try something like this:

    Code:
    (defun c:exnest ( )
        (vlax-for blk (vla-get-blocks (LM:acdoc))
            (if (and
                    (= :vlax-false (vla-get-isxref blk))
                    (= :vlax-false (vla-get-islayout blk))
                )
                (vlax-for obj blk
                    (if (and
                            (= "AcDbBlockReference" (vla-get-objectname obj))
                            (null (vl-catch-all-error-p (vl-catch-all-apply 'vla-explode (list obj))))
                        )
                        (vl-catch-all-apply 'vla-delete (list obj))
                    )
                )
            )
        )
        (command "_.-purge" "_B" "*" "_N")
        (vla-regen (LM:acdoc) acallviewports)
        (princ)
    )
    
    ;; Active Document  -  Lee Mac
    ;; Returns the VLA Active Document Object
    
    (defun LM:acdoc nil
        (eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object))))
        (LM:acdoc)
    )
    Last edited by Lee Mac; 4th Sep 2012 at 01:00 pm.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

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

  5. #5
    Forum Deity Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draftsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electrical.
    Using
    AutoCAD 2014
    Join Date
    Oct 2009
    Location
    Great Syria , Lives in Abu Dhabi
    Posts
    3,948

    Default

    I have written almost the same code but the problem is that the nested blocks would be exploded but a copy of the same block would be kept inside .

    Could any of the Sys. vars take affects on this ?

    Thanks
    - When aim is being settled in my mind , I have to reach it and get it in hand whatever it costs and wherever it is and will never give up . Tharwat said

  6. #6
    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
    16,866

    Default

    Quote Originally Posted by Tharwat View Post
    I have written almost the same code but the problem is that the nested blocks would be exploded but a copy of the same block would be kept inside .
    Good point Tharwat, I had overlooked the fact that the Explode method creates an exploded copy of the object - I have now updated my code above and have also included a block purge.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

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

  7. #7
    Junior Member
    Using
    AutoCAD 2012
    Join Date
    Aug 2012
    Posts
    12

    Default

    Hi Lee Mac,

    Thanks for the reply. I tried to use your code above but I got the response "No unreferenced blocks found." and when I enter the block editor to see if it has removed the nested block the nested block is still there. Is this code trying to purge out unreferenced blocks?

    I was looking for something that would allow you to select the blocks (with a window), that would then enter the block editor and explode everything but have the original block remain as a block. At the moment I have to enter the block editor for each block and explode the nested blocks myself but this is very time consuming as there are so many different types of blocks (with nested blocks inside of them).

  8. #8
    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
    16,866

    Default

    Quote Originally Posted by Cazza View Post
    I tried to use your code above but I got the response "No unreferenced blocks found." and when I enter the block editor to see if it has removed the nested block the nested block is still there. Is this code trying to purge out unreferenced blocks?
    My program will iterate over all block definitions within the block collection, and, if a block definition contains a nested block, the nested block is exploded. Finally, the program will purge the block collection to remove any unreferenced block definitions.

    The code seems to work fine in my tests, even with blocks for which the 'Allow exploding' option is unticked.

    Are you able to attach an example drawing?
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

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

  9. #9
    Junior Member
    Using
    AutoCAD 2012
    Join Date
    Aug 2012
    Posts
    12

    Default

    Hi Lee Mac,

    I had another go using your code and it works great, I must have been doing something wrong the first time round.

    Thank you again for your posts.

  10. #10
    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
    16,866

    Default

    Registered forum members do not see this ad.

    You're very welcome Cazza, happy to help
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

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

Similar Threads

  1. Updating dynamic blocks in nested blocks.
    By TGB in forum AutoCAD Beginners' Area
    Replies: 4
    Last Post: 29th Jul 2010, 08:17 pm
  2. help with lisp nested blocks
    By johny4901 in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 16th Jun 2010, 07:29 pm
  3. Find nested blocks
    By JoeC in forum AutoLISP, Visual LISP & DCL
    Replies: 11
    Last Post: 3rd Jun 2010, 03:32 pm
  4. Nested Blocks?
    By cadmatic in forum AutoCAD Beginners' Area
    Replies: 8
    Last Post: 21st Dec 2009, 01:30 pm
  5. Nested Blocks, or .... how?
    By fostertom in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 8
    Last Post: 30th Aug 2008, 11:21 pm

Tags for this Thread

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