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.
Solved! Go to Solution.
Solved by hmsilva. Go to Solution.
Solved by hmsilva. Go to Solution.
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
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.
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