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.
@Anonymous 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)
)
Thanks! I knew something was amiss. It's been a few years since I've done any LISP, so forgotten skills...
Thanks again!
@Anonymous 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?
Any of those would work. But since just about all that could change from project to project, i think user pick would work good...
@Anonymous 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
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.
@Anonymous 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.
@Kent1Cooper wrote:
@Anonymous 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
@Anonymous wrote:I am unable to get it to work, probably because im pretty new to Autolisp. Can i get more direction?
Thanks
If you can tell us whats happening when you say unable to get it work. and it wouldnt work for text/mtext.
whats the error message if any?
As i explained from the previous post, there are strings that are considered invalid characters "<>/\":;?*|,=`" for layout name
Mtext usually have the "\\P" , code for new line. you probably didnt notice the error message after you click on a text/mtext with invalid characters. it would say at the command prompt
The following characters are not valid in layout names: <>/\":;?*|,=`
Is that whats happening on your case? If not the, post a sample drawing and we'll figure out together
Help us help you......
A quick mod [not tested]
(defun C:RTT (/ str) ; = Rename Tab to match Text (if (and (/= (getvar 'ctab) "Model") (setq str (cdr (assoc 1 (reverse (entget (car (nentsel "\nSelect Text/Mtext/Attribute to change Layout Tab name to its content: " )))))))) (progn (foreach kk '("\\P" "<" ">" "/" "\\" ":" ";" "?" "`*" "|" "," "=" "``") (while (vl-string-search kk str) (setq str (vl-string-subst (if (eq kk "\\P") " " "") kk str)) )) (command "_.layout" "_rename" (getvar 'ctab) str) ) (prompt "\nCannot rename Model space tab.") ) (princ) )
Ok the problem is that my Attributed block has multiple lines and it only renames the layout with one line..
Example..."Chilled Beam Cooling Water Diagram" is the full title
Each part of the title is didvided like this in the block...
Sheet title 1 = Chilled Beam
Sheet title 2 = Cooling Water
Sheet Tile 3 = Diagram
When i select the block it only renames the layout with "Chilled Beam"
or if i click "Cooling Water" it will rename the layout "Cooling Water" and so on...it will only read one line of the block.
I need it to read all three lines of the block and rename accordingly. Is there a way to have it rename it by the Tag or Prompt within the block? (fyi most on my blocks will have 5-7 lines of info)
i just tested the text/mtext title and it is working with the new lisp you sent above. Thanks!
I have atttached an example for the block.
@Anonymous wrote:Ok the problem is that my Attributed block has multiple lines and it only renames the layout with one line..
Example..."Chilled Beam Cooling Water Diagram" is the full title
Each part of the title is didvided like this in the block...
Sheet title 1 = Chilled Beam
Sheet title 2 = Cooling Water
Sheet Tile 3 = Diagram
When i select the block it only renames the layout with "Chilled Beam"
or if i click "Cooling Water" it will rename the layout "Cooling Water" and so on...it will only read one line of the block.
I need it to read all three lines of the block and rename accordingly. Is there a way to have it rename it by the Tag or Prompt within the block? (fyi most on my blocks will have 5-7 lines of info)
i just tested the text/mtext title and it is working with the new lisp you sent above. Thanks!
Kudos to Kent Cooper, It was really his idea. 🙂
As for your request, i can think of a couple ways to do that. easiest way is to use TAG names but it would be specific to a particular block. perhaps a prompt would be better .. we'll see, but it will have to wait till tomorrow .
Cheers
I thought about this and made some test codes. I believe the best way to deal with attributes is to use a listbox. That way you can select the strings you want to use as layout name. But only if you select an attribute.
The TAG reference is a good idea,but i would prefer to make the code generic .
usage:
command: RTT
If selected entity is an attribute this will appear
HTH
how do I apply this in cad
(DEFUN C:RRT ()
(command "-layout" "rename" "" (vl-filename-base (getvar "dwgname")))
(princ)
)
@Anonymous wrote:
how do I apply this in cad
....
Welcome to these Forums!
Open up a plain-text editor like Notepad, paste the code into it, and Save it to a file with a .LSP filetype ending.
In a drawing, APPLOAD [or its command alias AP], navigate to where you put that file, and Load it.
Type the command name that follows the C: [in this case, RRT] at the Command: prompt.
You might want to add a line in that file, either before or after that command definition, just in case the (vl...) functions are not already loaded up by something else:
(vl-load-com)
There are ways to have it automatically made available in every drawing you open, if you want to do that, to avoid needing to APPLOAD it yourself when you want to use it.
Can't find what you're looking for? Ask the community or share your knowledge.