Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Distinguished Contributor
CrazyIvan
Posts: 324
Registered: ‎06-15-2007
Message 1 of 17 (852 Views)

naming a single layout tab to match the file name

852 Views, 16 Replies
08-02-2012 01:18 PM

Trying to get the files I use which are single-layout tab files to name the layout tab to match the file name, minus the .DWG extension.

 

Here is what I am trying to use, but it doesn't seem to be working.

 

Any help is appreciated.

 

(DEFUN C:RRT (/ name)
 (setq name (getvar (vl-filename-base (getvar "dwgname"))))

 (command "-layout" "rename" name "")
(princ)
)

 

THANKS.

*Expert Elite*
Kent1Cooper
Posts: 5,242
Registered: ‎09-13-2004
Message 2 of 17 (850 Views)

Re: naming a single layout tab to match the file name

08-02-2012 01:36 PM in reply to: CrazyIvan

CrazyIvan wrote:

Trying to get the files I use which are single-layout tab files to name the layout tab to match the file name, minus the .DWG extension.

....


You have an extra (getvar) function in there, and the which-layout-to-rename and what-to-rename-it entries reversed.  Try:

 

(DEFUN C:RRT (/ name)
 (setq name (vl-filename-base (getvar "dwgname")))

 (command "-layout" "rename" "" name)
 (princ)
)

 

or skip the variable, and just do this:

 

(DEFUN C:RRT ()

 (command "-layout" "rename" "" (vl-filename-base (getvar "dwgname")))
 (princ)
)

Kent Cooper
Distinguished Contributor
CrazyIvan
Posts: 324
Registered: ‎06-15-2007
Message 3 of 17 (840 Views)

Re: naming a single layout tab to match the file name

08-02-2012 03:19 PM in reply to: Kent1Cooper

Thanks!  I knew something was amiss.  It's been a few years since I've done any LISP, so forgotten skills...

 

Thanks again!

Active Member
bdcurry
Posts: 7
Registered: ‎10-03-2012
Message 4 of 17 (741 Views)

Re: naming a single layout tab to match the file name

10-09-2012 01:04 PM in reply to: Kent1Cooper

Is there a way to do this with the sheet name instead of the filename?

*Expert Elite*
Kent1Cooper
Posts: 5,242
Registered: ‎09-13-2004
Message 5 of 17 (736 Views)

Re: naming a single layout tab to match the file name

10-09-2012 01:12 PM in reply to: bdcurry

bdcurry wrote:

Is there a way to do this with the sheet name instead of the filename?


That would depend on how/where the sheet name is stored.  Attribute?  If so, in what Block name, with what Tag?  Text entity?  If so, on what Layer, and/or in what size or style or something to distinguish it from other Text?  Or ask the User to pick it?  Something else?

Kent Cooper
Active Member
bdcurry
Posts: 7
Registered: ‎10-03-2012
Message 6 of 17 (732 Views)

Re: naming a single layout tab to match the file name

10-09-2012 01:35 PM in reply to: Kent1Cooper

Any of those would work. But since just about all that could change from project to project, i think user pick would work good...

*Expert Elite*
Kent1Cooper
Posts: 5,242
Registered: ‎09-13-2004
Message 7 of 17 (724 Views)

Re: naming a single layout tab to match the file name

10-09-2012 02:33 PM in reply to: bdcurry

bdcurry wrote:

Any of those would work. But since just about all that could change from project to project, i think user pick would work good...


Something like [minimally tested]:

 

(defun C:RTT (); = Rename Tab to match Text
  (if (/= (getvar 'ctab) "Model")
    (command ; then
      "_.layout" "_rename" (getvar 'ctab)
      (cdr (assoc 1 (entget (car

        (nentsel "\nSelect Text/Mtext/Attribute to change Layout Tab name to its content: ")

      )))); cdr etc.
    ); command
    (prompt "\nCannot rename Model space tab."); else
  ); if

  (princ)
); defun

Kent Cooper
Active Member
bdcurry
Posts: 7
Registered: ‎10-03-2012
Message 8 of 17 (704 Views)

Re: naming a single layout tab to match the file name

10-10-2012 06:42 AM in reply to: Kent1Cooper

So it works on attributes but it only renames it with the one line I select. Can it do multiple lines?

And it wouldnt work for text/mtext, it selects the text but doesnt rename the layout.

 

Thanks.

*Expert Elite*
Kent1Cooper
Posts: 5,242
Registered: ‎09-13-2004
Message 9 of 17 (698 Views)

Re: naming a single layout tab to match the file name

10-10-2012 07:05 AM in reply to: bdcurry

bdcurry wrote:

So it works on attributes but it only renames it with the one line I select. Can it do multiple lines?

And it wouldnt work for text/mtext, it selects the text but doesnt rename the layout.

....


I don't have a new-enough version [back in ol' 2004] to have multiple-line Attributes, so I can't help you there.  And for me, it does work with Text and Mtext -- I suppose that difference may also be version-related.  I hope someone else can step in and figure out how to alter it, or maybe work out some entirely different approach.

Kent Cooper
*Expert Elite*
pbejse
Posts: 2,406
Registered: ‎11-24-2009
Message 10 of 17 (683 Views)

Re: naming a single layout tab to match the file name

10-10-2012 08:27 PM in reply to: Kent1Cooper

Kent1Cooper wrote:

bdcurry wrote:

So it works on attributes but it only renames it with the one line I select. Can it do multiple lines?

And it wouldnt work for text/mtext, it selects the text but doesnt rename the layout.

....


I don't have a new-enough version [back in ol' 2004] to have multiple-line Attributes, so I can't help you there.  And for me, it does work with Text and Mtext -- I suppose that difference may also be version-related.  I hope someone else can step in and figure out how to alter it, or maybe work out some entirely different approach.


For Multi line Attribute , The first DXF 1 is always "". you can however reverse  the resulting data  (it wouldnt matter for TEXT/MTEXT) 

 

(cdr (assoc 1 (reverse (entget (car
(nentsel "\nSelect Text/Mtext/Attribute to change Layout Tab name to its content: ")
)))))

 

But still you may have to deal with these invalid characters for layout name  "<>/\":;?*|,=`"  might  it be MTEXT,TEXT or ATTRIBUTES. You need to STRIP the resulting string of those characters

 

HTH

 

 

 

 

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community