Hi,
I am facing a small issue when I try linking the filename to the attribute field within the title block.
The file name would follow this sequence
XXXXXXX_AAA_YYY_BBB.dwg
where the string length of XXXXXXX & YYY may vary across drawings, but strings AAA & BBB is of a fixed width.
The "_" symbol signifies where the filename ends(or the string length).
So how can I extract XXXXXXX, AAA, YYY, BBB out of the filename?
Thanks
Solved! Go to Solution.
Solved by scot-65. Go to Solution.
@Anonymous wrote:....
The file name would follow this sequence
XXXXXXX_AAA_YYY_BBB.dwgwhere the string length of XXXXXXX & YYY may vary across drawings, but strings AAA & BBB is of a fixed width.
The "_" symbol signifies where the filename ends(or the string length).
So how can I extract XXXXXXX, AAA, YYY, BBB out of the filename?
....
The subject of splitting a text string into substrings around a delimiting character [your "_" in this case] has come up a number of times here, most recently in this thread:
http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Extract-a-folder-name-within-dwgprefix/m-p/3585710#U3585710
If you put things like "split string" and/or "delimiter" into the Search window, you'll find a lot more threads about that.
I am new to LISP commands..can you explain how do I get around getting a particular set of strings from the dwgname?
@Anonymous wrote:I am new to LISP commands..can you explain how do I get around getting a particular set of strings from the dwgname?
One way:
Put the attached file [from that other thread I posted a link to -- there are other string-splitter routines on this Discussion Group] in some folder/directory in your Support File Search Path list. Then:
(load "StringDelToList")
installs the function, or type APPLOAD [or just AP] and navigate to it and load it. Then run the function defined in it, with the overall string and the delimiting character(s) as arguments:
(sdtol (substr (getvar 'dwgname) 1 (- (strlen (getvar 'dwgname)) 4)) "_")
returns a list of pieces of the drawing name [minus the ".dwg" at the end], split into separate text strings around the underscore delimiter, something like this:
("ABCDE" "FGH" "JKLMNO" "PQR")
You can use functions like (car), (cadr), (caddr), (cadddr), (nth), and (last) [see the AutoLISP Reference] to get the pieces you want out of that list.
Hi,
The LISP routine provided by you works fine. Now am able to extract the filename in pieces.
Can the expression
(sdtol (substr (getvar 'dwgname) 1 (- (strlen (getvar 'dwgname)) 4)) "_")
be added on-to a field?
@Anonymous wrote:....
Can the expression
(sdtol (substr (getvar 'dwgname) 1 (- (strlen (getvar 'dwgname)) 4)) "_")
be added on-to a field?
[Someone else will need to help you with that -- my version of AutoCAD is too old to have fields.]
You can put a diesel expression in a field. I could not get your exact expression to work because sdtol is an unknown function, but the rest of it would look like this in diesel.
$(substr, $(getvar, dwgname), 1, $(-, $(strlen, $(getvar, dwgname)), 4))
Hi, since the filename needs to be split apart I cannot use diesle expression, so the LISP routine sdtol needs to be used.
@Anonymous wrote:Hi, since the filename needs to be split apart I cannot use diesle expression, so the LISP routine sdtol needs to be used.
Sure you can!
Use the LISP to format your desired string.
Next, assign one of the userS keys: (setvar "USERS1" "with your answer").
Finally, in the field expression, enter: $(getvar, USERS1)
This was the original intention of the User keys.
Because userS keys are not saved in the file, you will have to generate this
when the drawing file is opened. Look into S::STARTUP and ACADDOC.LSP.
???
Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.
Can't find what you're looking for? Ask the community or share your knowledge.