Jump to content

Merge the drawings


andy_lee

Recommended Posts

Hi friends.

 

I'm engaged in machinery industry, Use Autodesk Inventor drawing Parts and assembly.Some times ,I need to batch convert idw drawings into DWG format.

 

One parts ,One drawings, So,If there are 100 parts, it has 100 drawings.

Now, My wish is to Merge 100 or more dwg into a dwg file.

 

Each drawing wide size may be different (A4,A3, etc)

Drawing frame and title bar is Attribute block.

att.png

 

Merge more drawing into a dwg file , I think need a Dcl file to enter the Rows and columns, Line spacing and the column spacing.

 

Thans for help! Thanks for all the friends in the forum.

Link to comment
Share on other sites

Dont know about idw to dwg but it would make sense to use a script open the dwg's and retrieve the size of the dwg A3 A4 etc then using this info write a script file to insert all the dwg's into the master dwg.

 

Our title block has size of sheet as a variable so could read that or just work out size of title block for size.

 

I would not worry about a dcl thats a bit extra work for little gain.

 

Re program just have a double repeat X Y I would use the A3 size for spacing then you can ignore size difference. Given the sheets would be in model space could do auto plotting etc I would consider using layouts 1 per sheet then size is not relevant either.

Link to comment
Share on other sites

You try this routine. First make a new blank drawing, load this routine, enter "IF" (name of lisp command, means "insert files") , point out the directory which contains your 100 or more dwg files (you have to export idw to dwg) and wait for the result. The inserted files are not exploded yet.

(defun c:if(/ dir files len col n x y h dy v li dy minp maxp)
 (setq dir (vl-filename-directory (getfiled "Get Directory" (getvar "dwgprefix") "dwg" 4))
files (vl-remove-if-not
      '(lambda(x) (vl-string-search "DWG" (strcase (vl-filename-extension x))))
         (vl-directory-files dir nil 1))
len (length files)
col (fix (sqrt len))
n -1
y 0
h 0
 )
 (while (< n (1- len))
   (setq x 0
  y (+ y h)
  h 0)
   (repeat col
     (setq v (nth (setq n (1+ n)) files))
     (if v
(progn
  (command "-insert" (strcat dir "/" v) '(0 0) "" "" "")
  (vla-getBoundingBox (vlax-ename->vla-object (entlast)) 'minp 'maxp)
  (setq li (mapcar 'vlax-safearray->list (list minp maxp)))

  (command "move" (entlast) "" '(0 0) (list x y))
  (if (> (setq dy (abs (- (cadadr li) (cadar li)))) h)
    (setq h dy))
  (setq x (+ x (abs (- (caadr li) (caar li)))) )
)
     )
   )
 )
)

Link to comment
Share on other sites

7o7 nice idea the sqrt for rows columns, as I suggested it would be easy also to modify your code keep first 6 lines then use "Layout" "N" to insert one part per new layout.

Link to comment
Share on other sites

You try this routine. First make a new blank drawing, load this routine, enter "IF" (name of lisp command, means "insert files") , point out the directory which contains your 100 or more dwg files (you have to export idw to dwg) and wait for the result. The inserted files are not exploded yet.

(defun c:if(/ dir files len col n x y h dy v li dy minp maxp)
 (setq dir (vl-filename-directory (getfiled "Get Directory" (getvar "dwgprefix") "dwg" 4))
files (vl-remove-if-not
      '(lambda(x) (vl-string-search "DWG" (strcase (vl-filename-extension x))))
         (vl-directory-files dir nil 1))
len (length files)
col (fix (sqrt len))
n -1
y 0
h 0
 )
 (while (< n (1- len))
   (setq x 0
  y (+ y h)
  h 0)
   (repeat col
     (setq v (nth (setq n (1+ n)) files))
     (if v
(progn
  (command "-insert" (strcat dir "/" v) '(0 0) "" "" "")
  (vla-getBoundingBox (vlax-ename->vla-object (entlast)) 'minp 'maxp)
  (setq li (mapcar 'vlax-safearray->list (list minp maxp)))

  (command "move" (entlast) "" '(0 0) (list x y))
  (if (> (setq dy (abs (- (cadadr li) (cadar li)))) h)
    (setq h dy))
  (setq x (+ x (abs (- (caadr li) (caar li)))) )
)
     )
   )
 )
)

 

 

Big Thanks ! 707

I test, But some overlap.

sshot-3.png

Edited by andy_lee
Link to comment
Share on other sites

@ 7o7

 

This is enough .

(vl-directory-files dir "*.dwg" 1)

In place of all of this .

(vl-remove-if-not
 '(lambda (x) (vl-string-search "DWG" (strcase (vl-filename-extension x))))
 (vl-directory-files dir nil 1)
)

Link to comment
Share on other sites

@Tharwat : ok thanks, yours is fine.

@andy_Lee : It's overlapped because the insertion point is not 0,0. Unless you move each drawing's lower left corner to 0,0.

That's the reason why i don't want to explode the insertion drawing.

Link to comment
Share on other sites

Can use "insert DWG Reference “ mode ?

Can use Drawing number from left to right, from top to bottom of the order arrange?

 

Drawing number: xxx-xxx-001 ,xxx-xxx-002 ......

Link to comment
Share on other sites

That's attaching an Xref file. Xref file can't be exploded.

 

I think can use "Binding xref" ,later,can exploded.

(Defun C:bd ( )                  
       (setvar "cmdecho" 0)              
       (setq oldBT (getvar "BINDTYPE"))
       (setq BT (if (not BT) oldBT BT))
       (setq BT_tmp 
               (getstring 
                       (strcat "Input binding type[binding(0)/Insert(1)]<" (itoa BT) ">: ")
               )
       )
       (if (null BT_tmp) (setq BT_tmp BT))
       (setq BT (atoi BT_tmp))
       (setvar "BINDTYPE" BT)
       (command "-xref" "Bind" "*") 
       (setvar "BINDTYPE" oldBT)
         (princ)
)

Link to comment
Share on other sites

That's attaching an Xref file. Xref file can't be exploded.

 

Hi ,Warm-hearted friends.

Can help me again?

Link to comment
Share on other sites

You shouldn't put "xattach" command in lisp, because with each drawing it open a dialog and pause the routine (although you set the cmddia to 0) , it loses your time a lot.

I think "insert" drawing is the best way to merge drawings.

Link to comment
Share on other sites

You shouldn't put "xattach" command in lisp, because with each drawing it open a dialog and pause the routine (although you set the cmddia to 0) , it loses your time a lot.

I think "insert" drawing is the best way to merge drawings.

 

Thanks , But I use your routine, Drawing confound.

I uploaded the drawings for the test.

 

I hope that arrange by drawing number.From left to right, from top to bottom

 

@707 , I hope you can help me update your routine. Thanks very much.

 

TEST.zip

Link to comment
Share on other sites

Don't know why your drawing entities change all its location when inserted!!

 

As long as you are using command calls within your Lisp that deals with coordinates , you need to switch off the OSNAP to avoid jumping to nearest objects' snaps .

Link to comment
Share on other sites

Don't know why your drawing entities change all its location when inserted!!

That's maybe why you want to use xattach?

 

I use INVENTOR TaskScheduler batch convert idw drawings into DWG format.

Link to comment
Share on other sites

Maybe this is better. But I don't know whether Chinese charaters could effect the sort list or not.

(defun c:if(/ dir files len col n x y h dy v li minp maxp)
 (defun sort(l)
   (mapcar 'cadr (vl-sort
     (mapcar '(lambda(x) (list (vl-list->string (vl-remove-if-not '(lambda(y) (<= 48 y 57))  (vl-string->list x))) x)) l)
 '(lambda(m n) (< (car m) (car n)))))
 )
 ;;; main function
 (vl-load-com)
 (setq dir (vl-filename-directory (getfiled "Get Directory" (getvar "dwgprefix") "dwg" 4))
files (sort (vl-directory-files dir "*.dwg" 1))		     
len (length files)
col (fix (sqrt len))
n -1
y 0
h 0
 )
 (while (< n (1- len))
   (setq x 0
  y (- y h)
  h 0)
   (repeat col
     (setq v (nth (setq n (1+ n)) files))
     (if v
(progn
  (vla-AttachExternalReference  (vla-get-ModelSpace (vla-get-ActiveDocument (vlax-get-acad-object)))
    (strcat dir "/" v) (strcat "XREF_IMAGE" (itoa n)) (vlax-3d-point '(0 0))  1  1  1  0  :vlax-false)
  (vla-getBoundingBox (vlax-ename->vla-object (entlast)) 'minp 'maxp)
  (setq li (mapcar 'vlax-safearray->list (list minp maxp)))

  (command "move" (entlast) "" (list (caar li) (cadadr li)) (list x y))
  (if (> (setq dy (abs (- (cadadr li) (cadar li)))) h)
    (setq h dy))
  (setq x (+ x (abs (- (caadr li) (caar li)))) )
)
     )
   )
 )
)

  • Like 1
Link to comment
Share on other sites

Maybe this is better. But I don't know whether Chinese charaters could effect the sort list or not.

 

Big Thanks! 707, It's great! I love it.

 

A few small problems.

1. How to set row spacing and the column spacing ?

2. Not sorted by Drawing No.

3. Met a wrong documents. (error: Automation Error. Description was not provided.) this document can Interrupt the running.

 

I uploaded the wrong document. Thanks again.

221.idw.dwg

 

Edited by andy_lee
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...