Jump to content

Diesel expression:Counting down from the end

Recommended Posts


My file name form: AAAA-BBBB-CCCC
Inside: AAAA and CCC was fixed
BBBB is the name of each drawing.
I'm using the Diesel function to insert a name (BBBB) into a drawing canvas.
No.1: The start letter of the string
No.2: the starting letter of the omitted part.
Problem: Because BBBB item is not fixed number of letters. Is there any way to remove the CCCC part. By way of counting down from the end?
Thank you very much

R-03-06_4FloorPlan (Drafting).dwg

Edited by vuxvix
Link to post
Share on other sites

You have full autocad ? A lisp will probably do easier, wcmatch comes to mind and look for "-" and split into a list. AAAA-BBBB-CCCC


; thanks to Lee-mac for this defun 
; www.lee-mac.com
; 44 is comma, 32 is space, 45 is -
(defun _csv->lst ( str / pos )
	(if (setq pos (vl-string-position 45 str))
		(cons (substr str 1 pos) (_csv->lst (substr str (+ pos 2))))
		(list str)

(setq ans (_CSV->LST "AAA-BBBB-CCC"))
("AAA" "BBBB" "CCC")

Then strcat a new answer. 

Link to post
Share on other sites

Working together with the function Bigal posted, you can save the variable in a custom property.

I use the following function to create that custom property in each drawing.

(defun setCustomDwgProp (key value / summaryInfo)
    (setq summaryInfo (vla-get-summaryInfo (vla-get-activeDocument (vlax-get-acad-object))))
    (if (getCustomDwgProp key)
        (vla-setCustomByKey summaryInfo key value)
        (vla-addCustomInfo summaryInfo key value)


You can set the variable like this:

(setCustomDwgProp "Drawingname" "BBBB")


and you can reference them in a field like this:

%<\AcVar CustomDP.DrawingName>%


You can also see all the set properties in File->Drawing Properties->Custom.

Maybe putting this all together will be a solution for you.

Link to post
Share on other sites
Posted (edited)

Hi @BIGAL @Dexus
Sorry for not being able to reply for a while.

Because the question is uploaded every day a lot. And there are not many people who can help. So I try to find support in many places. Apologies if this is not appropriate. Since my work environment mostly uses Autocad LT, I'm not sure if there is any problem with displaying the Fields in other computers. Also I have tried the lisp code, besides creating lisp file, editing lisp is beyond my ability. What can I do to use it.

Ps:I double checked my Field in the post. actually the omitted part has been counted down from the end. I noticed {.dwg} is numbered :12-9 respectively. The coincidence of the length of the string of letters in the file name confused me. Apologies for this silliness.


Edited by vuxvix
Link to post
Share on other sites

If you want to use this in LT then Lisp is not an option. If you do use full AutoCAD and Lisp to create 'fields' then they should still be correct for someone who opens the file with LT it is just LT cannot create the fields using Lisp.

It would help if you could post an example file showing what you are trying to achieve.

Link to post
Share on other sites
Lee Mac
On 9/27/2021 at 7:32 AM, vuxvix said:

My file name form: AAAA-BBBB-CCCC
Inside: AAAA and CCC was fixed


If "AAAA" and "CCCC" are of fixed length as you state above (and let's say that each are 4 characters), you can subtract these lengths plus the delimiter (i.e. 10 characters) from the overall string length to obtain the length of the "BBBB" section, e.g.:



Link to post
Share on other sites

Hi all!
Forgive me, because actually the problem in the topic is because I misunderstood how to count the number of the No.2 value. I have summarized the problem content in the attached file (filename and examples).
Also I want to ask 2 questions:
-filenames with {CCCC} are not fixed length-eg: _yyyyMMdd ;-yyMMdd.
Is it possible to remove it!?
-In the drawing frame also includes the Layout number: I used LeeMac's Lisp layout Field. Looks like it takes the value on each specific layout. So still execute the command on each layout. As I see on the forum, autocad doesn't support it at the moment.
Is there any lisp that does insert prefix sequence number? I use LeeMac's Tabsort, but it only inserts a specific value.
Thanks for all the help.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...