Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Active Member
pzkmf
Posts: 9
Registered: ‎08-23-2012
Message 1 of 10 (1,471 Views)
Accepted Solution

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

1471 Views, 9 Replies
08-23-2012 11:14 AM

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


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::smileyfrustrated:TARTUP and ACADDOC.LSP.

 

???

*Expert Elite*
Kent1Cooper
Posts: 5,513
Registered: ‎09-13-2004
Message 2 of 10 (1,453 Views)

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

08-23-2012 01:23 PM 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
Active Member
pzkmf
Posts: 9
Registered: ‎08-23-2012
Message 3 of 10 (1,406 Views)

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

08-24-2012 10:20 AM 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?

*Expert Elite*
Kent1Cooper
Posts: 5,513
Registered: ‎09-13-2004
Message 4 of 10 (1,392 Views)

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

08-24-2012 02:21 PM 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
Active Member
pzkmf
Posts: 9
Registered: ‎08-23-2012
Message 5 of 10 (1,359 Views)

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

08-27-2012 10:11 AM 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?

*Expert Elite*
Kent1Cooper
Posts: 5,513
Registered: ‎09-13-2004
Message 6 of 10 (1,329 Views)

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

08-28-2012 04:32 AM 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
*Expert Elite*
M_Hensley
Posts: 1,712
Registered: ‎12-11-2003
Message 7 of 10 (1,308 Views)

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

08-28-2012 11:50 AM 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))

Active Member
pzkmf
Posts: 9
Registered: ‎08-23-2012
Message 8 of 10 (1,286 Views)

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

08-29-2012 09:42 AM 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. 

*Expert Elite*
scot-65
Posts: 2,179
Registered: ‎12-11-2003
Message 9 of 10 (1,260 Views)

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

08-30-2012 04:03 PM 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::smileyfrustrated:TARTUP and ACADDOC.LSP.

 

???

Scot-65
Dyslexia is a permanent physical disability that cannot be seen.
Introverts is proof that there is indeed intelligent life on this planet.
Active Member
pzkmf
Posts: 9
Registered: ‎08-23-2012
Message 10 of 10 (1,189 Views)

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

09-16-2012 07:51 AM in reply to: scot-65

Thanks Scot..userS keys did work!!

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 or visit the Installation and Licensing Forum to get help installing your software.