Merge multiple files/folios into one file

Sebastien3489 Posted messages 14 Status Member -  
 cricri1461 -
Hello everyone,
While drawing electrical plans on third-party software, when converting all my sheets into .dwg, a file is created for each sheet.
For example, if I have 5 sheets, I end up with 5 files.

Some clients being a bit reluctant to the idea of having one file per sheet, I always group them together manually, side by side.
When there are 5 sheets, it’s manageable. When there are 30, it becomes less easy.

Our sheets always have a standard format, either A4 landscape or A3 landscape.

Is it possible to create a macro in AUTOCAD that allows the software to retrieve all the files from a selected folder and arrange them side by side in the order of the folder?

I’ve already found something on other forums, but I always encounter an error unfortunately.

Thank you.

Configuration: Windows 7 / Mozilla 11.0

5 answers

  1. Yoda
     
    Hello,

    I'm directing you to a site that seems to have already addressed this issue.

    http://cadxp.com/topic/26514-assembler-plusieurs-dwg-en-1-seul/

    Otherwise, show me what you've found that isn't working, maybe I could fix this macro.

    See you!
    0
  2. Sebastien3489 Posted messages 14 Status Member
     
    Thank you.
    I tested this solution:
    https://cadxp.com/#entry46469
    (2nd post)

    Unfortunately, I have an error:
    Duplicate definition of the EPLFRAME block ignored.
    ; error: Automation error Key not found

    Thank you.

    Sébastien D.
    0
    1. Yoda
       
      Hi,
      The message Definition of the EPLFRAME block ignored just indicates that the EPLFRAME block already exists in the current drawing, and you are trying to insert a drawing that contains a block of the same name, which will not be redefined. This is not an error, just a warning.
      I tried the lisp and it works. However, the modification proposed in the following post contains an error:

      Since your object is in vlisp, you could also do
      (vla-move ojb (vlax-3d-point '(0.0 0.0 0.0)) (vlax-3d-point next_ins))

      instead of
      (command "_.move" (entlast) "" "_none" ll "_none" next_ins)


      You need to use
      (vla-move obj (vlax-3d-point '(0.0 0.0 0.0)) (vlax-3d-point next_ins))

      Hoping to have helped you. See you later.
      0
      1. Sebastien3489 Posted messages 14 Status Member > Yoda
         
        Yoda,
        By chance, I changed the name of my files and it seems to be working.
        My files are named as follows: "=TD 2.1+01_6" with
        - =TD 2.1 being the name of the table
        - +01 the revision of the diagram
        - _6 for folio 6

        By changing the name, it works. Is it possible for it to work with this same file name, generated by my drawing software?

        Also, the folio included consists of a block, and I can't dissociate it. The client therefore cannot make modifications when they want to do their As-built. I tried to select everything and dissociate it but without success.

        I made the modification but my folios are no longer next to each other.

        Thank you very much anyway. I think I will finally find a solution to my problem.

        Sébastien
        0
      2. Yoda > Sebastien3489 Posted messages 14 Status Member
         
        Autocad does not accept block names with the character =
        Change "=TD 2.1+01_6" to "TD 2.1+01_6"

        A+
        0
  3. Sebastien3489 Posted messages 14 Status Member
     
    Thank you ;)
    Indeed, it works. I managed to extract my .dwg files named: 1.dwg, 2.dwg, ... and it is even simpler.

    However, how does Autocad choose the order of insertion for the files? Indeed, it inserts them in an illogical order...
    Is it possible to impose an order of insertion? File 1.dwg then 2.dwg, ... up to 100-200?

    Thank you
    0
    1. Yoda
       
      Hello,
      The list is created as it is returned by the system.
      To get a sorted list, you need to use a sorting function.
      Fortunately, there is a ready-made one, vl-sort.
      Here’s how to modify the program (just one line to change).

       (setq

      lst_dwg (vl-sort (vl-directory-files prefix "*.dwg" 1) '<)

      next_ins pt_ins
      delta_x 0.0
      delta_y 0.0
      last_pt nil
      )


      See you later!
      0
    2. Sebastien3489 Posted messages 14 Status Member
       
      Hi,
      Unfortunately, it's not working.
      It still injects the files in the wrong order.
      I tried renaming the file to folio 1.dwg, folio 2.dwg but to no avail...
      My lisp: https://www.wetransfer.com/downloads/33987be8e39b8c06f7f08b8f0a9aaa5920150410193705/5b46529fab6d45de6a27986dfd97c1f520150410193705/c95bbc

      Thanks ;)
      0
    3. Yoda > Sebastien3489 Posted messages 14 Status Member
       
      Did you save the modified file correctly?
      Did you reload the new lisp correctly?

      Enter this line of code in the autocad command line
      (vl-sort '("folio 2.dwg" "folio 1.dwg") '<)

      You should have seen this result, proof that it works
      ("folio 1.dwg" "folio 2.dwg")

      Make sure to reload the modified lisp. See you!
      0
    4. Sebastien3489 Posted messages 14 Status Member
       
      Yoga,
      I think I've found the error.
      For example:
      Command: (vl-sort '("folio 2.dwg" "folio 1.dwg" "folio 3.dwg" "folio 4.dwg"
      "folio 10.dwg" "folio 5.dwg") '<)
      ("folio 1.dwg" "folio 10.dwg" "folio 2.dwg" "folio 3.dwg" "folio 4.dwg" "folio
      5.dwg")
      OR, it should be folio 1-2-3-4-10...

      Thank you.
      0
    5. Yoda > Sebastien3489 Posted messages 14 Status Member
       
      For that, you need to number the folios with 3 characters
      001, 002, 010, 100...999

      or you can start the numbering at 100
      100, 101, 102....999
      0
  4. Sebastien3489 Posted messages 14 Status Member
     
    Yoda,
    I've done a series of tests and it seems to be working ;)
    I change the names of my files via a macro in Excel and AutoCAD places the files in the requested order ;).
    However, in an effort to automate even further, is it possible to launch the application and have it work like this:
    1. I open AutoCAD (OK now)
    2. I load the macro (OK now)
    3. I run the macro (OK now)
    4. I choose the insertion point + format
    5. I select the file (OK now)
    6. All the sheets are inserted (OK now)
    7. The macro selects all the sheets + launches the DECOMPOS function (I've looked for a solution but without success) (Currently, I do ctrl+a + DECOMPOS)
    8. The macro opens the save window to save the file
    9. The macro deletes all the sheets and goes back to point 5 for a second series of plans while keeping the insertion point + format

    Thank you ;)
    0
    1. Yoda
       
      Hi Sebastien3489

      I modified the Lisp to meet your expectations.
      Actually, I made two versions:
      One without a loop that goes from point 4 to point 8.
      One with a loop that goes from point 4 to point 9 and returns to point 5.

      Download the zip file
      http://cjoint.com/?EDouYkqne13

      See you!
      0
    2. Sebastien3489 Posted messages 14 Status Member
       
      Yoda,
      I tested the loop and it seems great.
      Is there a way for Autocad to remember the file path of the list of files?
      Indeed, when I save each series of folios, Autocad retains the file path, but to open the "template" file, I always have to navigate through my folders and subfolders to get there.

      Thank you.
      0
      1. Yoda > Sebastien3489 Posted messages 14 Status Member
         
        Hello

        Try modifying these lines

        (defun c:cahier_bloc ( / old_osmd prefix pt_ins pt_tmp lst_dwg n dx dy loop key pt pt_last obj ll ur lg loop init-dir);modify this line
        ;
        ;
        ;
        (setq loop "Yes")
        (setq init-dir "");add this line
        (while (= loop "Yes")

        (setq prefix (strcat (vl-filename-directory (getfiled "Select a DWG TEMOIN file" init-dir "dwg" 16)) "\\"));modify this line


        See you later
        0
    3. Sebastien3489
       
      Yoda,
      Sorry for the delay but I was traveling.
      I tested the macro and when I look for my sample file, it always redirects me to MY DOCUMENTS.

      Best regards,

      Sébastien D.
      0
      1. Yoda > Sebastien3489
         
        Hello Sebastien3489

        Indeed, I forgot to assign the directory name to init-dir
        You also need to add a line just after (setq prefix....) :

        (setq prefix (strcat (vl-filename-directory (getfiled "Select a TEMOIN DWG file" init-dir "dwg" 16)) "\\"))
        (setq init-dir prefix)


        There you go. See you!
        0
  5. Sebastien3489 Posted messages 14 Status Member
     
    Yoda,
    Unfortunately, without success.

    I uploaded my macro but I think everything is fine.

    Thank you

    https://www.wetransfer.com/downloads/3a58a186f6d54dc91bf5e62052326b1420150423181650/77e9dd0737e33a2c78b459415fc5847620150423181650/212552
    0
    1. Yoda
       
      Hi,

      You made a copy error

      (setq prefix (strcat (vl-filename-directory (getfiled "Select a DWG TEMOIN file" init-dir "dwg" 16)) "\\"))

      init-dir is a variable and not a text, so it should not be enclosed in quotes ""

      See you!
      0
    2. Sebastien3489 Posted messages 14 Status Member
       
      Yoda,
      Thank you, it works ;)
      I think we've reached the end of the process automation ;)

      Once again, a big thank you ;)
      0
      1. Yoda > Sebastien3489 Posted messages 14 Status Member
         
        No problem ;)
        Wishing you all the best.
        0
    3. cricri1461
       
      Hello sébastien3489

      I'm currently working on electrical schematics, and I'm also looking for a way to combine all the electrical schematic sheets into a single file. (One file is much more convenient for clients, especially with a small hundred pages!)

      I tried to make all the modifications in your post and several other posts, but it doesn't work! Could you share your lisp?

      Thanks
      0