tive29 Posted January 18, 2017 Share Posted January 18, 2017 Is there any lisps to add the layout name (the 1st one) to a drawing file name like a Prefix? drawing file name is 1st floor plan 1st layout name is Part A therefore run lisp drawing file name will become Part A-1st floor plan (with a "-" to separate them) got a couple hundred drawings to do. 1 Quote Link to comment Share on other sites More sharing options...
Grrr Posted January 18, 2017 Share Posted January 18, 2017 One way might be: (defun C:test ( / ) (vla-SaveAs (vla-get-ActiveDocument (vlax-get-acad-object)) (strcat (car (layoutlist)) "-" (getvar 'dwgname)) ) (princ) )(vl-load-com) (princ) Quote Link to comment Share on other sites More sharing options...
tive29 Posted January 19, 2017 Author Share Posted January 19, 2017 Hello Mr Grrr. First off i wanna say thanks. It makes a copy of the file with the layout name as a prefix in the document folder. Can this be done without opening each individual files as i have close to a few hundreds. thanks Quote Link to comment Share on other sites More sharing options...
BIGAL Posted January 19, 2017 Share Posted January 19, 2017 You will need to do this as a script which can open each dwg and find the layout name. ; save the lisp as say layoutdwg.lsp open dwg1 (load "layoutdwg") close open dwg2 (load "layoutdwg") close ; save the lisp as say layoutdwg.lsp (vl-load-com) (vla-SaveAs (vla-get-ActiveDocument (vlax-get-acad-object)) (strcat (car (layoutlist)) "-" (getvar 'dwgname)) ) (princ) Lastly there are various ways to make the script file, check out www.lee-mac.com he has one. Quote Link to comment Share on other sites More sharing options...
Grrr Posted January 19, 2017 Share Posted January 19, 2017 Never had to such thing so just sharing what I think: I remember there was a thread with similair request where I replied link. I think the options are either using LM's ObjectDBX Wrapper or LM's ScriptWriter that BIGAL mentioned. Another way would be by opening N drawings, and iterate thru the documents collection. (remembering that there was a thread with similar task about this - but can't seem to find it). Quote Link to comment Share on other sites More sharing options...
Tharwat Posted January 19, 2017 Share Posted January 19, 2017 The first tab of the function layoutlist would not reorder the tabs if for instance the first layout is relocated by the user. Quote Link to comment Share on other sites More sharing options...
tive29 Posted January 20, 2017 Author Share Posted January 20, 2017 You will need to do this as a script which can open each dwg and find the layout name. ; save the lisp as say layoutdwg.lsp open dwg1 (load "layoutdwg") close open dwg2 (load "layoutdwg") close ; save the lisp as say layoutdwg.lsp (vl-load-com) (vla-SaveAs (vla-get-ActiveDocument (vlax-get-acad-object)) (strcat (car (layoutlist)) "-" (getvar 'dwgname)) ) (princ) Lastly there are various ways to make the script file, check out www.lee-mac.com he has one. Thanks Mr BIGAL for the suggestion. I guess that would mean I need to copy the hundreds of file names to create this script. Not to diminish it but I do need something that can be done in a moments notice. Quote Link to comment Share on other sites More sharing options...
tive29 Posted January 20, 2017 Author Share Posted January 20, 2017 Never had to such thing so just sharing what I think: I remember there was a thread with similair request where I replied link. I think the options are either using LM's ObjectDBX Wrapper or LM's ScriptWriter that BIGAL mentioned. Another way would be by opening N drawings, and iterate thru the documents collection. (remembering that there was a thread with similar task about this - but can't seem to find it). I would tryout the link. Thanks. ALo if you remember the N dwg method do let me know. Thanks Quote Link to comment Share on other sites More sharing options...
tive29 Posted January 20, 2017 Author Share Posted January 20, 2017 The first tab of the function layoutlist would not reorder the tabs if for instance the first layout is relocated by the user. Base on the drawing setup, the 1st layout name will always be the one. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted January 20, 2017 Share Posted January 20, 2017 Base on the drawing setup, the 1st layout name will always be the one. Have a look: Quote Link to comment Share on other sites More sharing options...
Grrr Posted January 20, 2017 Share Posted January 20, 2017 (edited) Ok, after Tharwat's remark you could use this: (defun SortedLayoutsList ( / L ) (vlax-map-collection (vla-get-Layouts (vla-get-ActiveDocument (vlax-get-acad-object))) (function (lambda (x) (setq L (cons (list (vla-get-TabOrder x) (vla-get-Name x)) L)))) ) (mapcar 'cadr (cdr (vl-sort L '(lambda (a b) (< (car a) (car b)))))) ); defun SortedLayoutsList (SortedLayoutsList) instead of (layoutlist) EDIT: Or just straight obtaining the first tab (for this specific task) : ; (GetFirstLayoutTab) (defun GetFirstLayoutTab ( / Lcoll ) (setq Lcoll (vla-get-Layouts (vla-get-ActiveDocument (vlax-get-acad-object))) ) (vl-some '(lambda (x) (if (= 1 (vla-get-TabOrder x)) (vla-get-Name x))) (mapcar '(lambda (x) (vla-item Lcoll x)) (layoutlist)) ) ) Edited January 20, 2017 by Grrr Quote Link to comment Share on other sites More sharing options...
tive29 Posted February 9, 2017 Author Share Posted February 9, 2017 Hi Grr How to combine this ; (GetFirstLayoutTab) (defun GetFirstLayoutTab ( / Lcoll ) (setq Lcoll (vla-get-Layouts (vla-get-ActiveDocument (vlax-get-acad-object))) ) (vl-some '(lambda (x) (if (= 1 (vla-get-TabOrder x)) (vla-get-Name x))) (mapcar '(lambda (x) (vla-item Lcoll x)) (layoutlist)) ) ) into your eariler code? (defun C:test ( / ) (vla-SaveAs (vla-get-ActiveDocument (vlax-get-acad-object)) (strcat (car (layoutlist)) "-" (getvar 'dwgname)) ) (princ) )(vl-load-com) (princ) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted February 9, 2017 Share Posted February 9, 2017 (edited) post removed trying to find something I did. I think this is it. (vlax-for lay (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object))) (if (= 1 (vla-get-taborder lay)) ; 0 is "Model" 1 is 1st (setvar "ctab" (vla-get-name lay)) ) ) Edited February 9, 2017 by BIGAL Quote Link to comment Share on other sites More sharing options...
Grrr Posted February 9, 2017 Share Posted February 9, 2017 Hi Grr How to combine this ; (GetFirstLayoutTab) (defun GetFirstLayoutTab ( / Lcoll ) (setq Lcoll (vla-get-Layouts (vla-get-ActiveDocument (vlax-get-acad-object))) ) (vl-some '(lambda (x) (if (= 1 (vla-get-TabOrder x)) (vla-get-Name x))) (mapcar '(lambda (x) (vla-item Lcoll x)) (layoutlist)) ) ) into your eariler code? (defun C:test ( / ) (vla-SaveAs (vla-get-ActiveDocument (vlax-get-acad-object)) (strcat (car (layoutlist)) "-" (getvar 'dwgname)) ) (princ) )(vl-load-com) (princ) Like this: (defun C:test ( / GetFirstLayoutTab ) (defun GetFirstLayoutTab ( / Lcoll ) (setq Lcoll (vla-get-Layouts (vla-get-ActiveDocument (vlax-get-acad-object))) ) (vl-some '(lambda (x) (if (= 1 (vla-get-TabOrder x)) (vla-get-Name x))) (mapcar '(lambda (x) (vla-item Lcoll x)) (layoutlist)) ) ) (vla-SaveAs (vla-get-ActiveDocument (vlax-get-acad-object)) (strcat (GetFirstLayoutTab) "-" (getvar 'dwgname)) ) (princ) )(vl-load-com) (princ) Quote Link to comment Share on other sites More sharing options...
tive29 Posted February 11, 2017 Author Share Posted February 11, 2017 Thanks Grrr. If I am not mistaken I observed that the newly created file(with the prefix) will be saved to the last saved location. This posses an issue I encountered whereby last saved location was for Project A & the file renaming was for Project B but got saved into Project A. If possible, can you relocated it to the document folder instead? Like this: (defun C:test ( / GetFirstLayoutTab ) (defun GetFirstLayoutTab ( / Lcoll ) (setq Lcoll (vla-get-Layouts (vla-get-ActiveDocument (vlax-get-acad-object))) ) (vl-some '(lambda (x) (if (= 1 (vla-get-TabOrder x)) (vla-get-Name x))) (mapcar '(lambda (x) (vla-item Lcoll x)) (layoutlist)) ) ) (vla-SaveAs (vla-get-ActiveDocument (vlax-get-acad-object)) (strcat (GetFirstLayoutTab) "-" (getvar 'dwgname)) ) (princ) )(vl-load-com) (princ) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted February 11, 2017 Share Posted February 11, 2017 Maybe add the (getvar "dwgprefix") in the code this is the path to the dwg. Alter as required if you know your company directory structure. 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.