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

Diesel to show nth last letter

10 REPLIES 10
Reply
Message 1 of 11
kieran.leadbetter
448 Views, 10 Replies

Diesel to show nth last letter

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,

Tags (2)
Labels (2)
10 REPLIES 10
Message 2 of 11

@kieran.leadbetter ,

 

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

~DD
Senior CAD Tech & AI Specialist
Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace
Message 3 of 11
scot-65
in reply to: kieran.leadbetter

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.


Message 4 of 11

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"))
Message 5 of 11


@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.

Kent Cooper, AIA
Message 6 of 11

Hello sorry for the late reply, been a busy couple days,

What is LData, this is a new term to me and I can't find an explanation of it anywhere.

I am also trying to imbed this within a Block so that no lisps will be required, it would just become an automatic thing which updates on all drawings as not everyone at my workplace understands how to use lisps yet
Message 7 of 11

My diesel code is just an MText inside a block, I also have a few which are attributes within blocks but they all function identically from what I can see, just regen and its worked so far unless I've just gotten lucky
Message 8 of 11

Hello sorry for the late reply, and thank you for a really indepth explanation.

I will try messing around with writing up Lisps a bit more as it is very basic commands I use it for unless I request help from others online.

Do you know of a Diesel method which may achieve the same goal however as I am attempting to imbed this into all my templates and files so that the block will become fully automatic and run in the background as not everyone at my workplace understands lisps aswell, making it difficult to make this a workplace standard if this makes sense
Message 9 of 11

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 

 

Message 10 of 11

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

 

Message 11 of 11

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.

Post to forums  

Forma Design Contest


AutoCAD Beta