• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    Visual LISP, AutoLISP and General Customization

    Reply
    Active Member
    Posts: 9
    Registered: ‎08-23-2012
    Accepted Solution

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

    695 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

    Please use plain text.
    *Expert Elite*
    Kent1Cooper
    Posts: 4,085
    Registered: ‎09-13-2004

    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
    Please use plain text.
    Active Member
    Posts: 9
    Registered: ‎08-23-2012

    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?

    Please use plain text.
    *Expert Elite*
    Kent1Cooper
    Posts: 4,085
    Registered: ‎09-13-2004

    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
    Please use plain text.
    Active Member
    Posts: 9
    Registered: ‎08-23-2012

    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?

    Please use plain text.
    *Expert Elite*
    Kent1Cooper
    Posts: 4,085
    Registered: ‎09-13-2004

    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
    Please use plain text.
    *Pro
    M_Hensley
    Posts: 1,574
    Registered: ‎12-11-2003

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

    Please use plain text.
    Active Member
    Posts: 9
    Registered: ‎08-23-2012

    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. 

    Please use plain text.
    *Pro
    scot-65
    Posts: 1,928
    Registered: ‎12-11-2003

    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.

     

    ???

    Please use plain text.
    Active Member
    Posts: 9
    Registered: ‎08-23-2012

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

    Please use plain text.