Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Linking CAD File Names into Title block, but only using some of the name

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
pzkmf
2939 Views, 9 Replies

Linking CAD File Names into Title block, but only using some of the name

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

9 REPLIES 9
Message 2 of 10
Kent1Cooper
in reply to: pzkmf


@pzkmf wrote:

....

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?

....


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

 

If you put things like "split string" and/or "delimiter" into the Search window, you'll find a lot more threads about that.

Kent Cooper, AIA
Message 3 of 10
pzkmf
in reply to: Kent1Cooper

I am new to LISP commands..can you explain how do I get around getting a particular set of strings from the dwgname?

Message 4 of 10
Kent1Cooper
in reply to: pzkmf


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

Kent Cooper, AIA
Message 5 of 10
pzkmf
in reply to: Kent1Cooper

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?

Message 6 of 10
Kent1Cooper
in reply to: pzkmf


@pzkmf 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.]

Kent Cooper, AIA
Message 7 of 10
M_Hensley
in reply to: pzkmf

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

Message 8 of 10
pzkmf
in reply to: pzkmf

Hi, since the filename needs to be split apart I cannot use diesle expression, so the LISP routine sdtol needs to be used. 

Message 9 of 10
scot-65
in reply to: pzkmf


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


Message 10 of 10
pzkmf
in reply to: scot-65

Thanks Scot..userS keys did work!!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost