Jump to content

insert multiple files in one drawing


Guest

Recommended Posts

Is it possible to insert multiple files in one drawing using lisp ?

 

For example. I have some files with cross sections (one cross section per file)

I want to array (5 x 3 or 7 x 3, colums x lines )them in one file .I want to have the choice to give the number of colums and lines . for example look the attach file

 

Eatch single section have a name d1,d2,d3,d4,d5,d6,d7,d8,d9 etc

I want to array the files by the file name like the attach file

 

thanks

testd.dwg

Link to comment
Share on other sites

  • Replies 31
  • Created
  • Last Reply

Top Posters In This Topic

  • Tharwat

    6

  • BIGAL

    4

  • Lee Mac

    2

  • asos2000

    1

I would just use excel to make a script that inserts block at a grid spacing, else if you want a lisp you can do a (repeat Y (repeat X a double loop just make a list of file names and retrieve each one as required.

 

;example code as a start - missing code
(setq X (getint "\nEnter columns))
(setq y (getint "\nEnter rows"))
(setq XY (getpoint "pick lower left")) ; get X Y values and make a new XY pt
(setq lst (list a b c d e f g)) ;maybe read a text file here 
(setq xoff 100)
(setq yoff 100)
(repeat x
(repeat Y
(command "insert" a XY 1 0)
(setq yoff (+ yoff 100))
)
(setq xoff (+ xoff 100))
)

Link to comment
Share on other sites

You should be able to use FINDFILE and make a list of the dwgs to be inserted. Need to do a search for some example of making file list. Will google and search here to see whats out there

Link to comment
Share on other sites

Try this routine and let me know .

 

(defun c:Test (/ l d path fls ch pts bx by xy lst srt pt p i o)
 ;;	Tharwat . Date: 15.Sep.2014		;;
 (setq l (entlast)
       d (getvar 'DWGPREFIX)
 )
 (while (setq path (getfiled "Select drawing to add :" d "dwg;dxf" 16))
   (setq fls (cons path fls)
         d   (vl-filename-directory path)
   )
 )
 (if fls
   (progn (setq ch (getvar 'CMDECHO))
          (setvar 'CMDECHO 0)
          (foreach dwg fls
            (command "_.-insert" dwg '(0. 0. 0.) "" "" "")
            (if (not (eq l (setq o (entlast))))
              (setq lst (cons o lst)
                    l   o
              )
            )
          )
          (mapcar '(lambda (x)
                     (vla-getboundingbox (vlax-ename->vla-object x) 'a 'b)
                     (setq pts (mapcar 'vlax-safearray->list (list a b))
                           bx  (cons (distance (car pts) (list (car (cadr pts)) (cadr (car pts)))) bx)
                           by  (cons (distance (car pts) (list (car (car pts)) (cadr (cadr pts)))) by)
                     )
                   )
                  lst
          )
          (setq xy  (mapcar '(lambda (x) (apply 'max x)) (list bx by))
                srt (vl-sort lst '(lambda (j k) (< (cdr (assoc 2 (entget j))) (cdr (assoc 2 (entget k))))))
                pt  '(0. 0. 0.)
                p   pt
                i   0
          )
          (foreach e srt
            (vlax-invoke (vlax-ename->vla-object e) 'move (cdr (assoc 10 (entget e))) pt)
            (if (= (setq i (1+ i)) 3)
              (setq i  0
                    pt (polar p (* pi 1.5) (cadr xy))
                    p  pt
              )
              (setq pt (polar pt 0. (car xy)))
            )
          )
          (setvar 'CMDECHO ch)
   )
   (princ "\n No Dwg files found in that folder !")
 )
 (princ)
)(vl-load-com)


Edited by Tharwat
Link to comment
Share on other sites

Hi Tharwat nice job, but i need some changes if it possible.

 

1) To have a choise open files (because the directory of the files is not all the time the same)---> then select the files -->insert the files with the turn that they selected

2) To have an option for the lines and the colums because now we have standard 3 colums

 

I attach some files to help you understand what i mean

 

I load 11 files in test2.dwg and is not correct insert

 

Thank you ...

d1.dwg

d2.dwg

d3.dwg

d4.dwg

d5.dwg

d6.dwg

d7.dwg

d8.dwg

d9.dwg

d10.dwg

d11.dwg

test2.dwg

Link to comment
Share on other sites

You should be able to use FINDFILE and make a list of the dwgs to be inserted. Need to do a search for some example of making file list. Will google and search here to see whats out there

this is a good idea but i can not find samething in google !!! If i have a list of the files i can manage the name of the files , and the possition of eatch section because now i have possition preblemslike

 

d1 , d10, d11

d2, d3 , d4

d5 , d6 , d7

d8, d9

 

the correct is

 

d1 , d2 , d3

d4 , d5 , d6

d7 , d8 , d9

d10, d11

Link to comment
Share on other sites

Give this a try

;;  Block Import Lisp  08/12/2008
;;  CAB at TheSwamp.org

 ;;  Get user selection of folder
 ;;  Get all DWG files in folder
 ;;  INSERT dwg as block @ 0,0
 ;;  get Bounding Box of block
 ;;  Move Insert to right w/ gap between blocks
 ;;  Next Insert

(defun c:BI (/ path LastDist gap space err newblk bname obj ll lr ur
              InsPt dist GetFolder)
 (vl-load-com)
 (defun GetFolder ( / DirPat msg)
  (setq msg "Open a folder and click on SAVE")
  (and
   (setq DirPat (getfiled "Browse for folder" msg " " 1))
   (setq DirPat (substr DirPat 1 (- (strlen DirPat) (strlen msg))))
  )
  DirPat
 )
 

 (defun activespace (doc)
   (if (or (= acmodelspace (vla-get-activespace doc))
           (= :vlax-true (vla-get-mspace doc)))
       (vla-get-modelspace doc)
       (vla-get-paperspace doc)
   )
 )

 (setq gap 5) ; this is the gap between blocks
 (setq LastDist 0.0) ; this is the cumulative distance
 
 (if (setq Path (GetFolder))
   (progn
     (setq space (activespace (vla-get-activeDocument (vlax-get-acad-object))))
     (prompt "\n***  Working, Please wait ......\n")
     (foreach bname (vl-directory-files Path "*.dwg" 1)
       ;;  OK, try & insert the Block
       (if (vl-catch-all-error-p
             (setq err (vl-catch-all-apply
               '(lambda () (setq newblk (vla-insertBlock space 
                               (vlax-3d-point '(0.0 0.0 0.0)) (strcat path bname) 1.0 1.0 1.0 0.0))
                  ))))
         ;;  Display the error message and block/file name
         (prompt (strcat "\n" bname " " (vl-catch-all-error-message err)))
         ;;  ELSE
         (progn ; INSERT was sucessful, move the block
           ;;  get bounding box
           (if (vl-catch-all-error-p
                 (setq err (vl-catch-all-apply 'vla-getboundingbox (list newblk 'll 'ur))))
              (prompt (strcat "\nBB Error - could not move " bname "\n  " (vl-catch-all-error-message err)))
              (progn
                (setq ll (vlax-safearray->list ll)
                      ur (vlax-safearray->list ur)
                      lr (list (car ur) (cadr ll))
                      dist (distance ll lr)
                      )
                ;;  MOVE the block
                (setq ;InsPt  (vla-get-insertionpoint Newblk)
                      NewPt (polar '(0. 0. 0.) 0.0 (+ LastDist Gap (* dist 0.5)))
                      LastDist (+ LastDist Gap dist)
                      )
                (vlax-put Newblk 'insertionpoint NewPt)
              )
           )
         )
        )
     )
   )
 )
 (princ)      
)
(princ)
(prompt "\nBlock Import Loadd, Enter Bi to run.")

Link to comment
Share on other sites

Thank you Tharwat but if i have 30 sections i have to do 30 click ,is not easy . Is another faster way?

 

Drop all your drawings into your target drawing then after that we can adjust them in counted columns 3 , 4 , or 5 and as best as you looking for .

Link to comment
Share on other sites

Tharwat I can not understand this !!!

 

I forgot to mention that you can use the Design Center to drop all needed drawings by prssing Ctrl + 2

 

Is it possible to add GetFolder in your code ?

 

Is any way to understand that d10 is after d9 and not after d1 ?

Link to comment
Share on other sites

Hi Lee Mac i try your code but nothing insert in my drawing

 

Did you change the file extension parameter as indicated in the code?

([color=BLUE]setq[/color] extn [color=MAROON]"dxf"[/color]) [color=GREEN];; Extension of files to Insert e.g "dwg"[/color]

Link to comment
Share on other sites

I change it now but insert all in one colum and can not understand that d10 is after d9 and not after d1

 

Tharwat is near to what i need but need same changes

 

1) to add GetFolder in your code ?

2)Is any way to understand that d10 is after d9 and not after d1 ?

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...