+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 17
  1. #1
    Full Member
    Using
    AutoCAD 2004
    Join Date
    Aug 2007
    Posts
    39

    Default automate flattening all entities residing inside blocks

    Registered forum members do not see this ad.

    I am looking for ways to automate flattening all entities residing inside blocks. I have searched all over the internet but haven't found one, maybe because my search term is not correct, or something. Here is what I am looking for:-

    Open a file (this can be manually or automate through batch file)
    Run a script / routine which does all things below all by itself:-
    -- edit a block by opening it in block editor
    -- runs flatten command or any other method to set all lines, arcs, etc to Z=0 coordinate
    -- save block and exit block editor
    -- open next block and repeat above steps
    -- stops only when all block in the drawing are redefined as above

    Is it possible?

    Note: using AutoCAD 2012. Lines are not imported from 3D content, just a result of careless drafting.

  2. #2
    Super Moderator SLW210's Avatar
    Computer Details
    SLW210's Computer Details
    Operating System:
    Windows 7 PRO 64-bit
    Computer:
    IBM Lenovo
    Motherboard:
    ACPI x64
    CPU:
    Pentium(R) i5 4570 @ 3.2GHz
    RAM:
    8 GB RAM
    Graphics:
    Nvidia Quadro 600 1GB
    Primary Storage:
    300 GB
    Secondary Storage:
    650GB
    Monitor:
    2x ThinkVision 24"
    Discipline
    Multi-disciplinary
    SLW210's Discipline Details
    Occupation
    Design Draftsman
    Discipline
    Multi-disciplinary
    Details
    Mostly do drafting related to manufacturing. From doing site layouts with proposed updates, additions and renovations to be budgeted and submitted for bid, to updating and changing existing drawings to reflect maintenance and repair/revision work done on site.
    Using
    AutoCAD 2011
    Join Date
    May 2007
    Location
    South Florida, USA
    Posts
    11,498

    Default

    I moved your thread to the AutoLISP, Visual LISP & DCL since you are not using AutoCAD LT.
    “A narrow mind and a fat head invariably come on the same person” Zig Zigler



  3. #3
    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
    19,130

    Default

    Here is a very simple program to flatten all objects in all blocks & layouts:
    Code:
    (defun c:allflat ( / d )
        (vlax-for b (vla-get-blocks (setq d (vla-get-activedocument (vlax-get-acad-object))))
            (if (= :vlax-false (vla-get-isxref b))
                (vlax-for o b
                    (if (vlax-write-enabled-p o)
                        (foreach e '(1e99 -1e99)
                            (vlax-invoke o 'move '(0.0 0.0 0.0) (list 0.0 0.0 e))
                        )
                    )
                )
            )
        )
        (vla-regen d acallviewports)
        (princ)
    )
    (vl-load-com) (princ)
    You can very easily run the above program on multiple drawings using a batch processing program, such as my Script Writer program.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

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

  4. #4
    Full Member
    Using
    AutoCAD 2004
    Join Date
    Aug 2007
    Posts
    39

    Default

    Quote Originally Posted by Lee Mac View Post
    Here is a very simple program to flatten all objects in all blocks & layouts:

    You can very easily run the above program on multiple drawings using a batch processing program, such as my Script Writer program.
    Thanks a lot Lee Mac. Works like a charm. On a simple file it finished so fast I first thought it did not do anything!

    I did a little test to test how your insertion points behave.



    Block 01:- Rectangle at z=0, block defined and base point selected at z=0. Rectangle moved to z=50 in block editor. Block inserted on line lying at z=0. Block rectangle still comes on z=0. Good.

    Block 02:- lines at various z coordinate. Block defined and base point selected at z=50 (intersection of two green lines).
    Instance 1:-Insert at Z=0
    Instance 2:- insert at Z=50 (on RHS)

    Run "Allflat" script and voila! everything is at z=0. What amazes me most is that second instance of block 02 is also now lying flat on z 0. My own conclusion is that base point definition does not have z value.

    Can't wait to try it out on all those big messy drawings come Monday.

    PS: I am somehow unable to upload image to CADTutor. Moderators please edit as required.

  5. #5
    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
    19,130

    Default

    Quote Originally Posted by Guite View Post
    Thanks a lot Lee Mac. Works like a charm. On a simple file it finished so fast I first thought it did not do anything!
    You're most welcome!

    Quote Originally Posted by Guite View Post
    What amazes me most is that second instance of block 02 is also now lying flat on z 0. My own conclusion is that base point definition does not have z value.
    This is because the base point of a block reference is merely the position of the block definition geometry relative to the origin of the block definition (very rarely is the origin of the block definition not at 0,0,0).

    Hence, when running the program, since the objects within the block definition are also 'flattened', the base point is automatically repositioned accordingly.

    Quote Originally Posted by Guite View Post
    PS: I am somehow unable to upload image to CADTutor. Moderators please edit as required.
    The images appeared fine for me
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

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

  6. #6
    Super Moderator SLW210's Avatar
    Computer Details
    SLW210's Computer Details
    Operating System:
    Windows 7 PRO 64-bit
    Computer:
    IBM Lenovo
    Motherboard:
    ACPI x64
    CPU:
    Pentium(R) i5 4570 @ 3.2GHz
    RAM:
    8 GB RAM
    Graphics:
    Nvidia Quadro 600 1GB
    Primary Storage:
    300 GB
    Secondary Storage:
    650GB
    Monitor:
    2x ThinkVision 24"
    Discipline
    Multi-disciplinary
    SLW210's Discipline Details
    Occupation
    Design Draftsman
    Discipline
    Multi-disciplinary
    Details
    Mostly do drafting related to manufacturing. From doing site layouts with proposed updates, additions and renovations to be budgeted and submitted for bid, to updating and changing existing drawings to reflect maintenance and repair/revision work done on site.
    Using
    AutoCAD 2011
    Join Date
    May 2007
    Location
    South Florida, USA
    Posts
    11,498

    Default

    Quote Originally Posted by Guite View Post
    PS: I am somehow unable to upload image to CADTutor. Moderators please edit as required.
    I do not see them at work which filters images from third party sites. Is the image hosted at a third party site? If you just post them to CADTutor, they should show up.
    “A narrow mind and a fat head invariably come on the same person” Zig Zigler



  7. #7
    Full Member
    Using
    AutoCAD 2004
    Join Date
    Aug 2007
    Posts
    39

    Default

    The image is hosted on third party site. I could not upload to CADTutor for some reason. It just never finishes uploading

  8. #8
    Super Moderator SLW210's Avatar
    Computer Details
    SLW210's Computer Details
    Operating System:
    Windows 7 PRO 64-bit
    Computer:
    IBM Lenovo
    Motherboard:
    ACPI x64
    CPU:
    Pentium(R) i5 4570 @ 3.2GHz
    RAM:
    8 GB RAM
    Graphics:
    Nvidia Quadro 600 1GB
    Primary Storage:
    300 GB
    Secondary Storage:
    650GB
    Monitor:
    2x ThinkVision 24"
    Discipline
    Multi-disciplinary
    SLW210's Discipline Details
    Occupation
    Design Draftsman
    Discipline
    Multi-disciplinary
    Details
    Mostly do drafting related to manufacturing. From doing site layouts with proposed updates, additions and renovations to be budgeted and submitted for bid, to updating and changing existing drawings to reflect maintenance and repair/revision work done on site.
    Using
    AutoCAD 2011
    Join Date
    May 2007
    Location
    South Florida, USA
    Posts
    11,498

    Default

    Quote Originally Posted by Guite View Post
    The image is hosted on third party site. I could not upload to CADTutor for some reason. It just never finishes uploading
    What is the size of the file? Images load just fine here for me.
    “A narrow mind and a fat head invariably come on the same person” Zig Zigler



  9. #9
    Full Member
    Using
    AutoCAD 2004
    Join Date
    Aug 2007
    Posts
    39

    Default

    Dear Lee Mac,

    I am encountering weird behaviors after running Allflat. This is not to say that it does not work at all. Infact it runs pretty well in most files. It handled dynamic blocks pretty well.

    - Some blocks behave strangely (files attached). The blocks were carelessly defined to start with. Re-defining them will be too time consuming.
    - Hatches disappear in one drawing, may have moved to very far coordinate. X-ref moves away in same file. E-transmit file attached.
    - Entities get scattered. Please refer Cutouts before and after.

    I have also tried native flatten command on some of the files. While there is less or no scattering, block insertion Z do not move every time to 0.

    I am attaching these files incase you would like to troubleshoot and develop the script further. If you don't feel like, I am okay with it. I have restored my backups and will just as well live with it.

    Cheers,
    Guite
    Attached Files

  10. #10
    Full Member
    Using
    AutoCAD 2004
    Join Date
    Aug 2007
    Posts
    39

    Default

    Registered forum members do not see this ad.

    Dear Lee Mac,

    Update: Allflat seems to have problem with handling blocks rotated other than 90 degrees to UCS axes. File attached for reference: run Allflat on this file and all angled parking blocks will scatter away.

    Cheers,
    Guite
    Attached Files

Similar Threads

  1. Replace LINETYPE with another one in dwg and all blocks inside.
    By ibach in forum AutoLISP, Visual LISP & DCL
    Replies: 16
    Last Post: 26th Dec 2012, 05:13 pm
  2. select last "n" entities drawn inside a lisp
    By flopo in forum AutoLISP, Visual LISP & DCL
    Replies: 5
    Last Post: 16th May 2011, 04:23 pm
  3. Find command for BLOCKS / ENTITIES
    By sadhu in forum AutoCAD Beginners' Area
    Replies: 11
    Last Post: 13th Oct 2010, 02:46 pm
  4. Fields inside blocks
    By Grigs in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 29th May 2009, 06:13 pm
  5. Attributes inside Dynamic Blocks!! Help!!
    By Adrian in forum AutoCAD Drawing Management & Output
    Replies: 15
    Last Post: 8th Feb 2008, 03:30 pm

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