Guest Posted September 14, 2014 Share Posted September 14, 2014 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 Quote Link to comment Share on other sites More sharing options...
BIGAL Posted September 14, 2014 Share Posted September 14, 2014 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)) ) Quote Link to comment Share on other sites More sharing options...
Guest Posted September 14, 2014 Share Posted September 14, 2014 is it possible to select the *.dwg files and then insert them in one drawing ?? or To select the *.dwg files , then create a text file ,and insert them in one drawing Quote Link to comment Share on other sites More sharing options...
BIGAL Posted September 15, 2014 Share Posted September 15, 2014 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 Quote Link to comment Share on other sites More sharing options...
Tharwat Posted September 15, 2014 Share Posted September 15, 2014 (edited) 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 September 15, 2014 by Tharwat Quote Link to comment Share on other sites More sharing options...
Guest Posted September 15, 2014 Share Posted September 15, 2014 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 Quote Link to comment Share on other sites More sharing options...
Tharwat Posted September 15, 2014 Share Posted September 15, 2014 You want to select each file alone because they might be in different folders and locations ? Quote Link to comment Share on other sites More sharing options...
Guest Posted September 15, 2014 Share Posted September 15, 2014 yes. The files is not all the time in desktop Quote Link to comment Share on other sites More sharing options...
Guest Posted September 15, 2014 Share Posted September 15, 2014 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 Quote Link to comment Share on other sites More sharing options...
Tharwat Posted September 15, 2014 Share Posted September 15, 2014 I modified the codes above [ untested ] Quote Link to comment Share on other sites More sharing options...
Guest Posted September 15, 2014 Share Posted September 15, 2014 Thank you Tharwat but if i have 30 sections i have to do 30 click ,is not easy . Is another faster way? Quote Link to comment Share on other sites More sharing options...
asos2000 Posted September 15, 2014 Share Posted September 15, 2014 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.") Quote Link to comment Share on other sites More sharing options...
Tharwat Posted September 15, 2014 Share Posted September 15, 2014 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 . Quote Link to comment Share on other sites More sharing options...
Tharwat Posted September 15, 2014 Share Posted September 15, 2014 I forgot to mention that you can use the Design Center to drop all needed drawings by prssing Ctrl + 2 Quote Link to comment Share on other sites More sharing options...
Guest Posted September 15, 2014 Share Posted September 15, 2014 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 ? Quote Link to comment Share on other sites More sharing options...
Guest Posted September 15, 2014 Share Posted September 15, 2014 hi asos2000 ,i test your code but i have the same problem 1) array all sections in one line 2)can not understand that d10 is after d9 and not after d1 Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 15, 2014 Share Posted September 15, 2014 I believe this question has been asked & answered before: http://www.cadtutor.net/forum/showthread.php?27790-Insert-Multiple-blocks-into-drawing&p=441569&viewfull=1#post441569 Please search the forums before creating a new thread. Quote Link to comment Share on other sites More sharing options...
Guest Posted September 15, 2014 Share Posted September 15, 2014 Hi Lee Mac i try your code but nothing insert in my drawing Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 15, 2014 Share Posted September 15, 2014 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] Quote Link to comment Share on other sites More sharing options...
Guest Posted September 15, 2014 Share Posted September 15, 2014 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 ? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.