Jump to content

Add layout name as a Prefix to drawing file name?


Recommended Posts

Posted

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.

  • Like 1
Posted

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)

Posted

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

Posted

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.

Posted

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

Posted

The first tab of the function layoutlist would not reorder the tabs if for instance the first layout is relocated by the user.

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

Posted
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

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

Posted
:?

Base on the drawing setup, the 1st layout name will always be the one.

 

Have a look:

Layoutlist.gif

Posted (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 by Grrr
  • 3 weeks later...
Posted

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)

Posted (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 by BIGAL
Posted
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)

Posted

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)

Posted

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.

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