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

Diesel Expression - Part of File Name

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
alx86
1806 Views, 5 Replies

Diesel Expression - Part of File Name

Hi everyone!

 

I'm very new with Diesel Expression. Btw, my english is not perfect, so I hope I'm clear enough.

 

I've found this post http://forums.autodesk.com/t5/autocad-2013-2014-2015/diesel-expression-to-display-part-of-file-name-... wich is almost the same question but I have a different condition.

 

What I need is a partial name that will be only the characters before the 5th underscore.

 

exemples of our file name template:

FS_TAB_IFU-008 TABLE A_000_0101_LEFT.dwg

TM_FSU_PANTY UNIT_000_0101_DOUBLE SIDED.dwg

 

so, quantity of character is:

2 _ 3 _ Variable _ 3 _ 4 _ Additional Description.dwg

 

for the to exemple the result I need is:

FS_TAB_IFU-008 TABLE A_000_0101

TM_FSU_PANTY UNIT_000_0101

 

Thanks for any help.

5 REPLIES 5
Message 2 of 6
hmsilva
in reply to: alx86

Hi abonneau,
in the link you have provided, Don's solution was using autolisp to get the text string, set "USERS1" with the string, and in Diesel use the (getvar, "USERS1") to get the string...

 

If it's ok for you, try

 

(defun end-p (str ch / n)
  (if (wcmatch str (strcat "*" ch "*"))
    (setq n   (vl-string-position (ascii ch) str 0 T)
          str (substr str 1 n)
    )
  )
)

;; and to set the USERS1

(if (setq a (end-p (getvar 'DWGNAME) "_"))
  (setvar 'USERS1 a)
  )

 

Hope that helps

Henrique

EESignature

Message 3 of 6
alx86
in reply to: hmsilva

Thanks for your response, but I'm really noob with diesel expression 😕 so I'm not sure to understand where I need to paste this code. I've tryed to create a lisp in wich I've paste

 

(defun end-p (str ch / n)
  (if (wcmatch str (strcat "*" ch "*"))
    (setq n   (vl-string-position (ascii ch) str 0 T)
          str (substr str 1 n)
    )
  )
)

 

After that, I've insert a field, choose Field Category "Other" then "DieselExpression" and paste:

 

(if (setq a (end-p (getvar 'DWGNAME) "_"))
  (setvar 'USERS1 a)
  )

 

But when I click "OK" I receive this message : "Invalid Field Code"

 

I've also tryed to paste the entire code in the DieselExpression box, it didn't work, then I've also tryed to copy it in a lisp file, same result.

Message 4 of 6
hmsilva
in reply to: alx86

Hi abonneau,

 

the code i have posted, is AutoLISP/VisualLISP, not DIESEL.

 

Save the code to a .lsp lsp file, and when necessary just load the file, and the code will read the dwg name, and set the USERS1 variable with the correct name...

 

At the field, choose => Field Category 'Other' => 'DieselExpression' and paste: $(getvar, "USERS1")

 

Hope that helps

Henrique

EESignature

Message 5 of 6
alx86
in reply to: hmsilva

Works perfectly!! Thanks a lot 🙂

Message 6 of 6
hmsilva
in reply to: alx86

You're welcome, abonneau
Glad I could help

Henrique

EESignature

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

Post to forums  

Autodesk Design & Make Report

”Boost