Good Morning, I was wondering if anyone may have a diesel code which will always show the n'th letter of a file name AFTER a specific part of text
Drawing_Plan_Rev_A.dwg
I currently have this diesel code which always shows a specific charater n'th, but it requires me to create a variant for each type of file name length, as well as a code which shows the n'th last character
$(substr,$(getvar,"dwgname"),17,$(-,$(strlen,$(getvar,"dwgname")),20))
$(substr,$(getvar,dwgname),$(-,$(strlen,$(getvar,dwgname)),4),1)
If possible however, would it be possible for someone to create and explain a diesel code to show the character after the characters "Rev_", where the "_" is indicated with a 'space' within a file name.
If anyone can help with this it would be much appreciated.
Kind Regards,
Does not seem possible to modify your current diesel expressions to improve them.
Where is your diesel function currently residing? I.E. Are you showing it in a Text object? MText? Title Block?
Give more context of what/where you're trying to show your current Rev.
Best,
~DD
Find your answer using LISP (loop using VL-STRING-SEARCH).
Set the built-in variable USERS1 to the answer.
Use DIESEL to display the answer $(getvar,users1)
Place this LISP inside acaddoc.lsp or S::STARTUP.
users(1-5), userr(1-5), and useri(1-5) are designed for such a purpose.
Custom fields will also work but can be buggy when refreshing/displaying.
Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.
Using Ldata can be more reliable than the User function and it is saved in the dwg. Any code can overwrite the User functions. You make the data name up so can be very obscure.
(if (vlax-ldata-list "AlanH")
(princ)
(progn (alert " Something is wrong \n \n the data associated with the rectangs is not available \n \n Will now exit")(exit))
)
(vlax-ldata-put "AlanH" "Ahscale" sc)
(setq ahsc (vlax-ldata-get "AlanH" "Ahscale"))
@kieran.leadbetter wrote:
... show the n'th letter of a file name AFTER a specific part of text
Drawing_Plan_Rev_A.dwg
.... would it be possible for someone to create and explain a diesel code to show the character after the characters "Rev_", where the "_" is indicated with a 'space' within a file name.
....
If you can use AutoLisp instead of Diesel, the (vl-string-position) function can search a string from the end, and locate the last instance of any specified character [by its ASCII number], whether your _ or a space or anything else, regardless of the overall length of the string. It can then use that position to extract everything after that character. If it needs to be specifically after "Rev_", not merely the last underscore [or space], then (vl-string-search) is what you want, as already suggested. It can't search from the end, but unless "Rev_" might occur more than once in the string, that wouldn't matter.
The only way I see to improve it is to use $(eq, val1, val2)
if 17-20 = Rev, then return 22 else if 18-21 = Rev, then return 23 else if 19-22 = Rev, then ...
That way, you can create a single formula for a few positions...
It is very cumbersome... the list of DIESEL functions is very short: HERE
Maybe this in a autoload lisp. Then look at each item.
; thanks to Lee-mac for this defun
(defun csv->lst ( str / pos )
(if (setq pos (vl-string-position 95 str))
(cons (substr str 1 pos) (csv->lst (substr str (+ pos 2))))
(list str)
)
)
(setq str "Drawing_Plan_Rev_A.dwg")
(setq lst (csv->lst str))
("Drawing" "Plan" "Rev" "A.dwg")
hey,
n'th letter of a file name AFTER a specific part of text to show where?
Can't find what you're looking for? Ask the community or share your knowledge.