add multiple dwg files to layout

add multiple dwg files to layout

ruben.vanveerdeghem
Contributor Contributor
1,775 Views
25 Replies
Message 1 of 26

add multiple dwg files to layout

ruben.vanveerdeghem
Contributor
Contributor

Hello,

 

AutoCAD users of my company are creating multiple dwg files for specific part number. For a new integration it would be necessary to get this multiple drawings to one drawing.

For instance:

drawing E50001 has one model (The model has multiple layers and one of them is the frame)

drawing E500A1 has one model (")

drawing E500B1 has one model (")

 

These drawings are all together in one windows folder.

 

Now the question is the following.

Is it possible to read all files in a specific folder with lisp and do the following?

 

The main drawing is the one with "01" at the end. 

Open the main drawing

copy everything except the frame to layout 1 and leave the frame on the model tab

open drawing 2 (A1) and copy everything without the frame to layout 2 of the main drawing

open drawing 3 (B1) and copy everything without the frame to layout 3 of the main drawing

and so on

save the main drawing and close everything

 

Is this possible to do with lisp?

I have lisp experience in another software, so that is not the problem. The problem is that I don't know

the AutoCAD commands.

Nobody in the company has lisp experience, so that's why I ask this here.

 

Help would be very much appreciated!

 

Thanks in advance

Ruben

0 Likes
Accepted solutions (1)
1,776 Views
25 Replies
Replies (25)
Message 2 of 26

pbejse
Mentor
Mentor

@ruben.vanveerdeghem wrote:

...

Open the main drawing

copy everything except the frame to layout 1 and leave the frame on the model tab

open drawing 2 (A1) and copy everything without the frame to layout 2 of the main drawing

open drawing 3 (B1) and copy everything without the frame to layout 3 of the main drawing

and so on

...


I think I understand most of it except the reference to "Frame"  What exactly is that  @ruben.vanveerdeghem 

0 Likes
Message 3 of 26

ruben.vanveerdeghem
Contributor
Contributor
With the frame I mean the titleblock and the A4 frame, this is how a drawing looks like before you start drawing on it.
0 Likes
Message 4 of 26

pbejse
Mentor
Mentor

And every drawing (E500A1.dwg) (E500B1.dwg) etc. .would be on on different tabs with names based on the drawing name?

Is the frame/titileblock located as the same tab as the rest of the objects?  I assume the entities are on Model tab?

 

Would it be too much to ask for sample drawing from your end? That will answer most of the questions that may or may not come your way as we go along.

 

Also, are you looking for help on writing the program or pseudo code is enough?

 

 

0 Likes
Message 5 of 26

ruben.vanveerdeghem
Contributor
Contributor

@pbejse 

 

So I think the model tab should be the titleblock/frame and the layout tabs should indeed be all the different drawings.

I've put an example in attachment. You'll see that the titleblock is always the same.

 

Pseudo code would be good, but if you can help me with real code, that would be better. I really don't know anything of AutoCAD

0 Likes
Message 6 of 26

pbejse
Mentor
Mentor

@ruben.vanveerdeghem wrote:

So I think the model tab should be the titleblock/frame and the layout tabs should indeed be all the different drawings.

I've put an example in attachment. You'll see that the titleblock is always the same.


 

Well I'm not sure about that @ruben.vanveerdeghem , the titleblocks do have different values specially for

DOC: and the revision descriptions. if anything it should be the other way around, titileblocks would be on its own tab with the correct viewport.

 

What is the purpose of combining the drawings anyway? maybe we could approach this in a different way.

 

0 Likes
Message 7 of 26

ruben.vanveerdeghem
Contributor
Contributor
It's correct what you are saying @pbejse , but that does not matter. The titleblocks should always be the same.

The real purpose is the following:
we are connecting autocad with PTC Windchill. Now the main drawing is a cad file for a part number, all the other drawings are attachments for the part number. So an attachment is easy to forget.
If all the scematics would be in one drawing it will be connected as one cad file to one part number and that is a lot easier to get the necessary data out of the database.
0 Likes
Message 8 of 26

pbejse
Mentor
Mentor

@ruben.vanveerdeghem wrote:
It's correct what you are saying @pbejse , but that does not matter. The titleblocks should always be the same.

Ok, one quick questions, Are you by any chance using AutoCAD Mac ? 

 

0 Likes
Message 9 of 26

ruben.vanveerdeghem
Contributor
Contributor
No we are using AutoCAD(2022) windows version
0 Likes
Message 10 of 26

pbejse
Mentor
Mentor
Accepted solution

Please confirm if the attached drawing  is the expected  result

 

How the program works is

  • The user opens the main file ("01" );,-- the drawing needs to end with 01
  • The program will check the number of layout tabs against  with the number of drawings
  • The rest of the drawings are on the same folder as the main drawing
  • All objects except the frame will be move to the first layout  tab: named the same as the drawing
  • The rest of the drawing files will be imported to its own layout tab on the main drawing

Let me know if that is acceptable

 

Note:

None of the drawings should be open except the "01" at the time the user invokes the import program

 

0 Likes
Message 11 of 26

maratovich
Advisor
Advisor

Maybe this will help you - AutoImportCAD 
And then you can remove the excess.
But honestly, I don't think you need to delete anything. Keep all title blocks in one drawing.

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
Message 12 of 26

ruben.vanveerdeghem
Contributor
Contributor

@pbejse 

Your result looks good and certainly acceptable. Many thanks for helping.

0 Likes
Message 13 of 26

pbejse
Mentor
Mentor

@ruben.vanveerdeghem wrote:

@pbejse 

Your result looks good and certainly acceptable. Many thanks for helping.


Hang on,  do you need help with writing the code?

 

0 Likes
Message 14 of 26

ruben.vanveerdeghem
Contributor
Contributor

@pbejse 

yes I will need help 🙂, in fact I will need to get the code I think

0 Likes
Message 15 of 26

ruben.vanveerdeghem
Contributor
Contributor

@pbejse 

I'm sorry, but I see that the layouts do not have the frame around it. Is it possible to use the model (frame) on every layout? Then the file will be perfect

0 Likes
Message 16 of 26

pbejse
Mentor
Mentor

@ruben.vanveerdeghem wrote:

@pbejse 

I'm sorry, but I see that the layouts do not have the frame around it. Is it possible to use the model (frame) on every layout? Then the file will be perfect


Exactly why i asked the question about the frame right from the start.

The model frame shows "page 1 of 4" and "E500 1601" wouldn't that be weird it is shows the same thing on all the sheets? Would it be better if you keep the original frame per imported drawing?

 

0 Likes
Message 17 of 26

ruben.vanveerdeghem
Contributor
Contributor

@pbejse 

Is it possible to put in some lisp variables as attribute? Or some other attributes?

So that the first layout has a titleblock with "page 1 of 3" and so on?

We also want to automatically update the titleblock with a few attributes, so that's why 

we don't want to put it fixed titleblocks.

 

Thx again

0 Likes
Message 18 of 26

pbejse
Mentor
Mentor

@ruben.vanveerdeghem wrote:

Is it possible to put in some lisp variables as attribute? Or some other attributes?

So that the first layout has a titleblock with "page 1 of 3" and so on?

We also want to automatically update the titleblock with a few attributes, so that's why 

we don't want to put it fixed titleblocks.

 

Thx again


The titleblock ("ELEKTROKADER") indeed has attributes that can be updated, but what of this number? 

E500 1601/14 <----  what does that represent?

 

0 Likes
Message 19 of 26

ruben.vanveerdeghem
Contributor
Contributor
@pbejse

The "/14" is the version. This can be added by using a custom attribute coming from windchill.
0 Likes
Message 20 of 26

pbejse
Mentor
Mentor

 

 

(defun c:ImportToLayout ( / aDoc layouts _MoveTo layouts ToProcess selection
			 MoveToLayout layoutlist_ fl lt ss_TB 1of ObjToMove page)
;;;		pBe Apr 2022		;;;
(defun _MoveTo (d lst lay layn)
  (vla-CopyObjects 	d
	(vlax-make-variant
	  (vlax-safearray-fill
	    (vlax-make-safearray vlax-vbObject
	      (cons 0 (1- (length lst)))) lst )
	)
	(vla-get-block (vla-item lay layn))
      )
  )
(setq aDoc    (vla-get-activedocument (setq app (vlax-get-acad-object)))
      layouts (vla-get-layouts aDoc)
)
	     
  (if
(and
    	(wcmatch (setq Dname (getvar 'dwgname)) "*01.dwg")
	(setq selection (ssget "_X" '((410 . "Model"))))
	(setq ToProcess (vl-sort (Vl-directory-files (setq fldr (getvar 'dwgprefix)) "*.dwg" 1) '<))
	      )
  	(progn
;;;		create the layout tabs		;;;
	  (cond
	    (( = (setq fl (length ToProcess))(setq lt (length (layoutlist))))
	     )
	    ((> fl lt)
	      (repeat  (setq i (- fl lt))
		(Vla-add layouts (strcat "TempName" (itoa i)))(setq i (1- i)))
		(setq layoutlist_
		       (mapcar 'cadr 
			 	(vl-sort 
				 (mapcar '(lambda (ln)
					    (list (vla-get-taborder (setq bl (vla-item  layouts ln))) bl)
						  )
						  (layoutlist)) '(lambda (a b)(< (car a)(Car b))))
				  )
		      )
	      (mapcar 'vla-put-name layoutlist_ (setq ToProcess (mapcar 'vl-filename-base ToProcess)))
	      )
	     )
;;;	Move Model objects to first layout	;;;
	     (repeat (setq i (sslength selection))
	        (setq MoveToLayout (cons (vlax-ename->vla-object (ssname selection (setq i (1- i))))
				     MoveToLayout))
	       )
	     (_MoveTo aDoc MoveToLayout layouts (Car  ToProcess))
	     (foreach O MoveToLayout (vla-delete O))
;;; 	Import drawings of the same name 	;;;
		    (foreach dwg (Cdr ToProcess)
		      (setq spc (Vla-get-block (Vla-item layouts dwg)))
		      	(setq imported (vlax-invoke spc
                                   'InsertBlock
                                   '(0.0 0.0 0.0)
                                   (strcat fldr "\\" dwg ".dwg")
                                   1 1 1 0))
		      (Vla-explode imported)
		      (vla-delete imported)
		      )
;;; 	Assing Page number and Zoom Extents	;;;
		  (if
		    (setq ss_TB (ssget "_X" '((2 . "ELEKTROKADER")(66 . 1))))
		    (progn
		      (setq 1of (sslength ss_TB))
		      (repeat 1of
			(setq ent (entget (setq e (ssname ss_TB 0))))
			(setq p (vl-position (setq lay (Cdr (assoc 410 ent))) ToProcess))
			(setvar 'Ctab lay)
			(and
			  (setq page (vl-some '(lambda (at)
						 (if (eq "PAGE" (vla-get-tagstring at)) at))
					(vlax-invoke (vlax-ename->vla-object e) 'GetAttributes)))
			     (vla-put-textstring page (strcat (itoa (1+ p)) " OF " (itoa 1of))))
			(ssdel e ss_TB)
			(vla-zoomextents (vlax-get-acad-object))
				)
			     )
			  )
	  (vla-put-ActiveLayout aDoc (Car layoutlist_))
      )
  )
  (princ)
  )

 

 

HTH

 

0 Likes