Replace characters in Mtext's Field Expression

Replace characters in Mtext's Field Expression

Anonymous
Not applicable
2,072 Views
6 Replies
Message 1 of 7

Replace characters in Mtext's Field Expression

Anonymous
Not applicable

Hi All,

 

I would like to ask some Autocad filed expression questions, and here is what i need:

In Mtext, it will automatically change a symbol(_) to another symbol(/) after get part of the filename string

For example, i have a file under the path like this: //a/a/b/c/d/A23456789_B23456789_C2_D.dwg

The Mtext will show like this B23456789/C2/D

 

So I divide the customized field expression(according to my understanding, it means it shows automatically when i placed in the M-Text) into 2 part:

 

(1)(done already) the first part is to get the filename start from the 11th character and count for 14 value with following code:

%<$(substr,$(getvar,dwgname),11,14)>%

 

(2)After that, I would like to replace those underline symbol "_" to slash symbol "/" with following code, (which cannot work well and is my question)

%<$(vl-string-translate "_" "//" $(substr,$(getvar,dwgname),11,14))>%  (<--- Can anyone help me for this)

 

Reference Related:

I have read several posts related to the string replacement and field expression

https://www.augi.com/articles/detail/autocad-fields-forever

 

https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2016/ENU/AutoCAD-AutoLISP/file...

 

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/replacing-substr-s-in-a-string-varia...

 

Thanks,

Will

 

2,073 Views
6 Replies
Replies (6)
Message 2 of 7

ActivistInvestor
Mentor
Mentor

You're confusing DIESEL and LISP. 

 

While they are similar, DIESEL functions are a limited subset of LISP functions, and there is no $(vl-string-translate) DIESEL function, so that isn't going to work. 

 


@Anonymous wrote:

Hi All,

 

I would like to ask some Autocad filed expression questions, and here is what i need:

In Mtext, it will automatically change a symbol(_) to another symbol(/) after get part of the filename string

For example, i have a file under the path like this: //a/a/b/c/d/A23456789_B23456789_C2_D.dwg

The Mtext will show like this B23456789/C2/D

 

So I divide the customized field expression(according to my understanding, it means it shows automatically when i placed in the M-Text) into 2 part:

 

(1)(done already) the first part is to get the filename start from the 11th character and count for 14 value with following code:

%<$(substr,$(getvar,dwgname),11,14)>%

 

(2)After that, I would like to replace those underline symbol "_" to slash symbol "/" with following code, (which cannot work well and is my question)

%<$(vl-string-translate "_" "//" $(substr,$(getvar,dwgname),11,14))>%  (<--- Can anyone help me for this)

 

Reference Related:

I have read several posts related to the string replacement and field expression

https://www.augi.com/articles/detail/autocad-fields-forever

 

https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2016/ENU/AutoCAD-AutoLISP/files/GUID-57060085-C79D-4613-B438-506AC443BCE7-htm.html

 

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/replacing-substr-s-in-a-string-variable/td-p/3783451

 

Thanks,

Will

 


 

0 Likes
Message 3 of 7

Anonymous
Not applicable

Thanks for your answer, so what should i do to make it work?

0 Likes
Message 4 of 7

Satish_Rajdev
Advocate
Advocate

Something like this :

 

 

(defun replace (s)
  (if (vl-string-search "_" s)
    (vl-list->string
      (subst (ascii "/") (ascii "_") (vl-string->list s))
    )
    s
  )
)

Examples :-

 

_$ (replace "B23456789_C2_D")
"B23456789/C2/D"

_$ (replace "//a/a/b/c/d/A23456789_B23456789_C2_D.dwg")
"//a/a/b/c/d/A23456789/B23456789/C2/D.dwg" 

 

Best Regards,
Satish Rajdev


REY Technologies | Linked IN | YouTube Channel


 

Message 5 of 7

Anonymous
Not applicable

Hi Sir, Thanks for your answers, but is it possible to run in the DIESEL expression ?
If so , can you teach me how to work on it?

 

0 Likes
Message 6 of 7

ActivistInvestor
Mentor
Mentor

@Anonymous wrote:

Hi Sir, Thanks for your answers, but is it possible to run in the DIESEL expression ?
If so , can you teach me how to work on it?

 


I don't believe there's any solution for this with DIESEL.  It just doesn't have the functions required to do it.

0 Likes
Message 7 of 7

jtm2020hyo
Collaborator
Collaborator

I have same issue, Did you found some alternative?

0 Likes