gmmdinesh Posted November 13, 2016 Posted November 13, 2016 Hi all.. I want a lisp file to save multiple number of dwg file with different name in same path. name of the dwg to save like this 123456-001.dwg,123456-002.dwg,123456-003.dwg. In my project to be create more than 20 layouts...and...We need to create a separate dwg file for each layout. Thanks in advance Regards Dinesh P Quote
rkmcswain Posted November 13, 2016 Posted November 13, 2016 Something like this should get you started in the right direction... (defun c:foo ( / cnt path) (setq cnt 1) (setq path (getvar "dwgprefix")) (repeat 20 (vl-cmdf ".save" (strcat path "123456-00" (itoa cnt))) (setq cnt (1+ cnt)) ) (princ) ) Quote
Grrr Posted November 13, 2016 Posted November 13, 2016 This will save file for each layout tab with names of: DwgName_LayoutName (defun C:test ( / nm str ) (setq nm (getvar 'dwgname)) (foreach x (layoutlist) (and (snvalid (setq str (strcat nm "_" x ))) (vla-SaveAs (vla-get-ActiveDocument (vlax-get-acad-object)) str ac2013_dwg) ) ) (princ) ) (vl-load-com) (princ) Quote
gmmdinesh Posted November 14, 2016 Author Posted November 14, 2016 (edited) Hi. Thanks For your code rkmcswain and Grrr These code are working fine.... its automatically save 20 copies... but number of layouts differs in each project so,i want enter the number of copies to save the dwg file. and the file to save same name of the dwg file with-001,-002.... ( for example file name is 2598752 only, but copies saved with -001.dwg, -002.dwg.... like that). Is it possible? Thanks again friends. Regards Dinesh P Edited November 14, 2016 by gmmdinesh Quote
Grrr Posted November 14, 2016 Posted November 14, 2016 This will create copy of the dwg for every layout with the name of the dwg with suffix -001... 002... etc.. (defun C:test ( / cnt str ) (repeat (setq cnt (length (layoutlist))) (setq str (strcat (vl-string-right-trim ".dwg" (getvar 'dwgname)) "-" (vl-string-left-trim "`." (vl-string-left-trim "0" (rtos (/ cnt 1000.)))))) (vla-SaveAs (vla-get-ActiveDocument (vlax-get-acad-object)) str ac2013_dwg) (setq cnt (1- cnt)) ) (princ) ) (vl-load-com) (princ) The only problem I couldn't solve are the 10's 20's 30's ... etc: "Drawing1-001" "Drawing1-002" "Drawing1-003" "Drawing1-004" "Drawing1-005" "Drawing1-006" "Drawing1-007" "Drawing1-008" "Drawing1-009" [color="red"]"Drawing1-01" [/color] "Drawing1-011" "Drawing1-012" "Drawing1-013" "Drawing1-014" "Drawing1-015" "Drawing1-016" "Drawing1-017" "Drawing1-018" "Drawing1-019" [color="red"]"Drawing1-02" [/color] "Drawing1-021" "Drawing1-022" "Drawing1-023" "Drawing1-024" "Drawing1-025" "Drawing1-026" "Drawing1-027" "Drawing1-028" "Drawing1-029" [color="red"]"Drawing1-03"[/color] Quote
Lee Mac Posted November 14, 2016 Posted November 14, 2016 (defun C:test ( / cnt str ) (repeat (setq cnt (length (layoutlist))) (setq str (strcat (vl-string-right-trim ".dwg" (getvar 'dwgname)) "-" (vl-string-left-trim "`." (vl-string-left-trim "0" (rtos (/ cnt 1000.)))))) (vla-SaveAs (vla-get-ActiveDocument (vlax-get-acad-object)) str ac2013_dwg) (setq cnt (1- cnt)) ) (princ) ) (vl-load-com) (princ) Be careful with the vl-string-trim* functions: _$ (vl-string-right-trim ".dwg" "ohmygawd.dwg") "ohmyga" I would suggest perhaps: (defun c:test ( / cnt doc dwg str ) (setq doc (vla-get-activedocument (vlax-get-acad-object)) dwg (strcat (getvar 'dwgprefix) (vl-filename-base (getvar 'dwgname))) ) (repeat (setq cnt (length (layoutlist))) (setq str (strcat "00" (itoa cnt)) cnt (1- cnt) ) (vla-saveas doc (strcat dwg "-" (substr str (- (strlen str) 2)))) ) (princ) ) (vl-load-com) (princ) Quote
gmmdinesh Posted November 15, 2016 Author Posted November 15, 2016 Hi. Lee Mac and Grrr.. Thanks for your codes.... This code works fine..but this lisp save only one copy of *.dwg. so Every time I have to do for each copy. I need manually enter number of files to be saved. ( like--> *-001.dwg, *-002.dwg,....) Thanks again Regards Dinesh P Quote
gmmdinesh Posted November 15, 2016 Author Posted November 15, 2016 Hi all... Some One help me.... Quote
Grrr Posted November 15, 2016 Posted November 15, 2016 Be careful with the vl-string-trim* functions:_$ (vl-string-right-trim ".dwg" "ohmygawd.dwg") "ohmyga" Thanks Lee, I missed that: _$ (vl-string-right-trim "`." (vl-string-right-trim "dwg" "ohmygawd.dwg")) "ohmygawd" _$ I also thought about substr, but with using the vl-* functions seems kinda easier This code works fine..but this lisp save only one copy of *.dwg. so Every time I have to do for each copy. I need manually enter number of files to be saved. ( like--> *-001.dwg, *-002.dwg,....) Your first question sounds like ObjectDBX task, the second one is easily achievable, but I don't understand the logic didn't you wanted separate copy(save as) for each layout from a .dwg file x? Quote
gmmdinesh Posted November 15, 2016 Author Posted November 15, 2016 Hi...Grrr. My project is networking based project and it has lot of layouts to placed continuously. when i placed the layouts continuously some text overlapped or cut by viewports. as per standard no one text overlapped in layouts. so i have used separate dwg for each layouts. that why i moved the necessary text inside the layout. Quote
Grrr Posted November 15, 2016 Posted November 15, 2016 I think about something like this: (defun c:test ( / ) (if (and LM:ODBX (not (initget (+ 1 2 4))) (setq cnt (getint "\nSpecify number of copies: ")) ) (LM:ODBX (function (lambda ( doc / nm cnt str ) (setq nm (vla-get-Name doc)) (repeat cnt (setq str (strcat "00" (itoa cnt))) (setq cnt (1- cnt)) (vla-SaveAs doc (strcat (vl-string-right-trim "`." (vl-string-right-trim "dwg" nm ) ) "-" (substr str (- (strlen str) 2)) ) ) ) ) ) nil nil ) ) (princ) ) (vl-load-com) (princ) But I have no experience with ODBX so no idea why it won't work. Sorry you'll have to wait for someone else to respond, as this is beyond my skill. EDIT: This seems to work, but there are 2 disadvantages: (defun c:test ( / ) (LM:ODBX (function (lambda ( doc / nm cnt str ) (setq nm (vla-get-Name doc)) (setq cnt 30) ; number of copies (repeat cnt (setq str (strcat "00" (itoa cnt))) (setq cnt (1- cnt)) (vla-SaveAs doc (strcat (vl-string-right-trim "`." (vl-string-right-trim "dwg" nm ) ) "-" (substr str (- (strlen str) 2)) ) ) ) ) ) nil nil ) (princ) ) (vl-load-com) (princ) -You have to fill manually in the code for the number of copies. -The copies will be saved as "file" (no dwg extension). It seems that ODBX won't support the Filetype input option. Quote
Lee Mac Posted November 15, 2016 Posted November 15, 2016 Thanks Lee, I missed that: _$ (vl-string-right-trim "`." (vl-string-right-trim "dwg" "ohmygawd.dwg")) "ohmygawd"_$ I also thought about substr, but with using the vl-* functions seems kinda easier Some alternatives: (vl-filename-base (getvar 'dwgname)) (cadr (fnsplitl (getvar 'dwgname))) Quote
Grrr Posted November 15, 2016 Posted November 15, 2016 Thanks Lee, I've never seen this fnsplitl function. I like alternatives. Quote
gmmdinesh Posted November 16, 2016 Author Posted November 16, 2016 Thanks Lee and Grrr.. This lisp not working for me. When i try to run the lisp, error shown as below "Command: TEST ; error: no function definition: LM:ODBX" I'm not expert in lisp codes so i can't find the error. Quote
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.