Author Topic: DIESEL : substr 4 characters from right  (Read 10439 times)

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1420
DIESEL : substr 4 characters from right
« on: November 01, 2014, 12:48:15 PM »
Continuously of this thread http://www.theswamp.org/index.php?topic=48081.0;all
Could substr works from right to left.
We adding a revsion (R00, R01, ...) at end of file name. But should not apear in dwg title.
File name : 3120B01-D-A101-R00
dwg title  : 3120B01-D-A101
I created this DIESEL Expresion,
Code: [Select]
$(substr,$(getvar,DWGNAME),1,14)But not every time the file name is 18 characters, So is there a way to substr 4 characters from right
« Last Edit: November 01, 2014, 12:51:25 PM by HasanCAD »

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: DIESEL : substr 4 characters from right
« Reply #1 on: November 01, 2014, 01:52:34 PM »
Try:
Code: [Select]
$(substr,$(getvar,dwgname),1,$(-,$(strlen,$(getvar,dwgname)),8))

HasanCAD

  • Swamp Rat
  • Posts: 1420
Re: DIESEL : substr 4 characters from right
« Reply #2 on: November 01, 2014, 02:30:21 PM »
Working perfect, Thanks LEE
Is there a link to explain DIESEL.
« Last Edit: November 01, 2014, 02:35:29 PM by HasanCAD »

Crank

  • Water Moccasin
  • Posts: 1503
Vault Professional 2023     +     AEC Collection


HasanCAD

  • Swamp Rat
  • Posts: 1420
Re: DIESEL : substr 4 characters from right
« Reply #5 on: November 04, 2014, 03:38:14 AM »
Try:
Code: [Select]
$(substr,$(getvar,dwgname),1,$(-,$(strlen,$(getvar,dwgname)),8))

Could you please explain this code. and what relation between deleting 4 characters and number 8?
I think that is it file extension and dot and 3 characters, Is it correct?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: DIESEL : substr 4 characters from right
« Reply #6 on: November 04, 2014, 04:00:29 AM »
At the command line, what is
Code - Auto/Visual Lisp: [Select]
  1. (getvar 'dwgname)
  2.  
  3. (strlen (getvar 'dwgname))
  4.  
  5. (strlen "-R00.dwg")
  6.  
  7. ( -  (strlen (getvar 'dwgname )) 8)
  8.  
  9.    (getvar 'dwgname )
  10.    1
  11.    ( -  (strlen (getvar 'dwgname )) 8)
  12. )
  13.  
  14.  

It's really that simple to evaluate.

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: DIESEL : substr 4 characters from right
« Reply #7 on: November 04, 2014, 04:44:54 AM »
Try:
Code: [Select]
$(substr,$(getvar,dwgname),1,$(-,$(strlen,$(getvar,dwgname)),8))

Could you please explain this code. and what relation between deleting 4 characters and number 8?
I think that is it file extension and dot and 3 characters, Is it correct?

As Kerry has suggested, in order to understand the code it is a good idea to evaluate each of the expressions (starting from the innermost expression outwards), see & understand the value returned by each expression, and how that return value is then passed to another expression.

Since many DIESEL expressions have AutoLISP equivalents, you can evaluate the equivalent AutoLISP expressions (as Kerry has suggested above), or alternatively, you can use the menucmd function to evaluate the DIESEL expressions directly, for example:

Code: [Select]
_$ (menucmd "m=$(getvar,dwgname)")
"Drawing1-R00.dwg"
_$ (menucmd "m=$(strlen,$(getvar,dwgname))")
"16"
_$ (menucmd "m=$(-,$(strlen,$(getvar,dwgname)),8)")
"8"
_$ (menucmd "m=$(substr,$(getvar,dwgname),1,$(-,$(strlen,$(getvar,dwgname)),8))")
"Drawing1"

Regarding the subtraction of 8 characters in order to remove 4 characters from the drawing name, the key point is that the DWGNAME system variable will return the drawing filename including the file extension - hence the DIESEL expression is removing the revision & file extension: "-R00.dwg" = 8 characters.

Lee

HasanCAD

  • Swamp Rat
  • Posts: 1420
Re: DIESEL : substr 4 characters from right
« Reply #8 on: November 04, 2014, 08:10:12 AM »
Thanks Kerry
Thanks Lee
OK, How to find out the common expressions between DIESEL and Lisp?
« Last Edit: November 04, 2014, 10:52:31 AM by HasanCAD »

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Re: DIESEL : substr 4 characters from right
« Reply #9 on: November 04, 2014, 08:46:06 AM »
Thanks Kerry
Thanks Lee
OK, How to find out the common expressions between DIESEL and Lisp?

1. Use the search feature of this forum.
2. Use the search feature of Duck duck go, google, bing or yahoo.

...

Code - Text: [Select]
  1. /*                             D I E S E L
  2.  
  3.        Dumb Interpretively Evaluated String Expression Language
  4.  
  5.     This "Dumb Interpretively Executed String Expression Language" is  the
  6.     kernel  of  a  macro  language  you can customise by adding C code and
  7.     embedding it into your program.
  8.  
  9.     It is short, written in portable C, and is readily integrated into any
  10.     program.   It  is  useful  primarily  to  programs  which  need a very
  11.     rudimentary macro expansion facility without the complexity of a  full
  12.     language such as Lisp or FORTH.
  13.  
  14.     DIESEL  copies  its  input  directly  to  the  output  until  a  macro
  15.     character, "$" or quoted string is encountered.  Quoted strings may be
  16.     used  to  suppress  evaluation  of sequences of characters which would
  17.     otherwise be interpreted as macros.  Quote marks may  be  included  in
  18.     quoted strings by two adjacent quote marks.  For example:
  19.  
  20.         "$(if,1,True,False)="""$(if,1,True,False)""""
  21.  
  22.     Status  retrieval,  computation,  and  display are performed by DIESEL
  23.     functions.  The available  functions  are  as  follows.   User-defined
  24.     functions  are  not  implemented;  what  you  see  is  all you've got.
  25.     Naturally, if  you  embed  DIESEL  in  your  application,  you'll  add
  26.     functions  that  provide access to information and actions within your
  27.     own program.  DIESEL's arithmetic  functions  accept  either  floating
  28.     point  or  integer arguments, and perform all calculations in floating
  29.     point.
  30.  
  31.     DIESEL String Functions
  32.     -----------------------
  33.  
  34.     $(+,<val1>,<val2>,...<valn>)
  35.         The  sum  of  the  numbers <val1>, <val2>, ...<valn> is returned.
  36.  
  37.     $(-,<val1>,<val2>,...<valn>)
  38.         The  result  of subtracting the numbers <val2> through <valn> from
  39.         <val1> is returned.
  40.  
  41.     $(*,<val1>,<val2>,...<valn>)
  42.         The result of multiplying the numbers  <val1>,<val2>,...<valn>  is
  43.         returned.
  44.  
  45.     $(/,<val1>,<val2>,...<valn>)
  46.         The  result of dividing the number <val1> by <val2>,...  <valn> is
  47.         returned.
  48.  
  49.     $(=,<val1>,<val2>)
  50.         If the  numbers  <val1>  and  <val2>  are  equal  1  is  returned,
  51.         otherwise 0 is returned.
  52.  
  53.     $(<,<val1>,<val2>)
  54.         If  the number <val1> is less than <val2> 1 is returned, otherwise
  55.         0 is returned.
  56.  
  57.     $(>,<val1>,<val2>)
  58.         If the number  <val1>  is  greater  than  <val2>  1  is  returned,
  59.         otherwise 0 is returned.
  60.  
  61.     $(!=,<val1>,<val2>)
  62.         If  the  numbers  <val1>  and  <val2> are not equal 1 is returned,
  63.         otherwise 0 is returned.
  64.  
  65.     $(<=,<val1>,<val2>)
  66.         If the number <val1>  is  less  than  or  equal  to  <val2>  1  is
  67.         returned, otherwise 0 is returned.
  68.  
  69.     $(>=,<val1>,<val2>)
  70.         If  the  number  <val1>  is  greater  than or equal to <val2> 1 is
  71.         returned, otherwise 0 is returned.
  72.  
  73.     $(AND,<val1>,<val2>,...<valn>)
  74.         The bitwise logical AND of the integers <val1> through  <valn>  is
  75.         returned.
  76.  
  77.     $(EQ,<val1>,<val2>)
  78.         If the strings <val1> and <val2>  are  identical  1  is  returned,
  79.         otherwise 0.
  80.  
  81.     $(EVAL,<str>)
  82.         The  string <str> is passed to the DIESEL evaluator and the result
  83.         of evaluating it is returned.
  84.  
  85.     $(FIX,<value>)
  86.         The real number <value> is truncated to an integer  by  discarding
  87.         any fractional part.
  88.  
  89.     $(IF,<expr>,<dotrue>,<dofalse>)
  90.         If  <expr>  is  nonzero,  <dotrue>  is  evaluated  and   returned.
  91.         Otherwise,  <dofalse>  is  evaluated  and returned.  Note that the
  92.         branch not chosen by <expr> is not evaluated.
  93.  
  94.     $(INDEX,<which>,<string>)
  95.         <string> is assumed to contain one or more values delimited by the
  96.         macro argument separator character, comma.  <which> selects one of
  97.         these values to be extracted, with the first item  numbered  zero.
  98.  
  99.     $(NTH,<which>,<arg0>,<arg1>,<argN>)
  100.         Evaluates  and  returns  the  argument  selected  by  <which>.  If
  101.         <which> is 0, <arg0> is returned, and so on.  Note the  difference
  102.         between  $(NTH)  and  $(INDEX);  $(NTH) returns one of a series of
  103.         arguments to the function while $(INDEX) extracts a value  from  a
  104.         comma-delimited string passed as a single argument.  Arguments not
  105.         selected by <which> are not evaluated.
  106.  
  107.     $(OR,<val1>,<val2>,...<valn>)
  108.         The  bitwise  logical  OR of the integers <val1> through <valn> is
  109.         returned.
  110.  
  111.     $(STRFILL,<string>,<ncopies>)
  112.         Returns the result of concatenating <ncopies> of <string>.
  113.  
  114.     $(STRLEN,<string>)
  115.         Returns the length of <string> in characters.
  116.  
  117.     $(SUBSTR,<string>,<start>,<length>)
  118.         Returns  the  substring  of <string> starting at character <start>
  119.         and extending for <length> characters.  Characters in  the  string
  120.         are numbered from 1.  If <length> is omitted, the entire remaining
  121.         length of the string is returned.
  122.  
  123.     $(UPPER,<string>)
  124.         The  <string> is returned converted to upper case according to the
  125.         rules of the current locale.
  126.  
  127.     $(XOR,<val1>,<val2>,...<valn>)
  128.         The bitwise logical XOR of the integers <val1> through  <valn>  is
  129.         returned.
  130. ...
  131. */
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

HasanCAD

  • Swamp Rat
  • Posts: 1420
Re: DIESEL : substr 4 characters from right
« Reply #10 on: November 04, 2015, 07:53:53 AM »
Thanks Kerry
Thanks Lee
OK, How to find out the common expressions between DIESEL and Lisp?

1. Use the search feature of this forum.
2. Use the search feature of Duck duck go, google, bing or yahoo.

...


Thanks John Kaul
Sorry for late but I saw the answer few mnts back
Thanks again

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
Re: DIESEL : substr 4 characters from right
« Reply #11 on: November 04, 2015, 08:13:18 AM »

Code - Text: [Select]
  1. /*                             D I E S E L
  2.  
  3.        Dumb Interpretively Evaluated String Expression Language
  4.  
  5.     This "Dumb Interpretively Executed String Expression Language" is  the
  6.     kernel  of  a  macro  language  you can customise by adding C code and
  7.     embedding it into your program.
  8.  
  9.     It is short, written in portable C, and is readily integrated into any
  10.     program.   It  is  useful  primarily  to  programs  which  need a very
  11.     rudimentary macro expansion facility without the complexity of a  full
  12.     language such as Lisp or FORTH.
  13. */
That is the start to a very informative document. If we could get several examples for each function it would be a really nice reference. :-)

TheSwamp.org  (serving the CAD community since 2003)

HasanCAD

  • Swamp Rat
  • Posts: 1420
Re: DIESEL : substr 4 characters from right
« Reply #12 on: November 04, 2015, 12:26:57 PM »
This is as start
Code - Auto/Visual Lisp: [Select]
  1.     DIESEL String Functions
  2.     -----------------------
  3.  
  4.     $(+,<val1>,<val2>,...<valn>)
  5.         The  sum  of  the  numbers <val1>, <val2>, ...<valn> is returned.
  6. Example:
  7. (menucmd "m=$(+,1,2)")
  8. "3"
  9.  
  10. (menucmd "m=$(+,2,1)")
  11. "3"
  12.  
  13. (menucmd "m=$(+,1,2,1)")
  14. "4"
  15.  
  16. (menucmd "m=$(+,1,2,3)")
  17. "6"
  18.  
  19. (menucmd "m=$(+,1,2,3,4,5,6)")
  20. "21"
  21.  
  22. ; (menucmd "m=EXPRESSION")used to give the result in VLIDE
  23. ; in FIELDS we us EXPRESSION ONLY
  24.  
  25.  
  26. ; The result can used as variable but be note that the variable type is string
  27. (setq a (menucmd "m=$(+,1,1)"))
  28. (type a)
  29. STR
  30.  
  31. ; Be note that we can not use variables
  32. ; If needed we have to add the expression itself
  33. (menucmd "m=$(+,pls02,1)")
  34. " $(+,??) "
  35.  
  36. (menucmd "m=$(+,$(+,1,2),1)")
  37. "4"
  38.  
  39.     $(-,<val1>,<val2>,...<valn>)
  40.         The  result  of subtracting the numbers <val2> through <valn> from
  41.         <val1> is returned.
  42. Example:
  43. (menucmd "m=$(-,1,2)")
  44. "-1"
  45.  
  46. (menucmd "m=$(-,2,1)")
  47. "1"
  48.  
  49. (menucmd "m=$(-,1,2,3,4,5,6)")
  50. "-19"
  51.  
  52. (menucmd "m=$(-,6,3)")
  53. "3"
  54.  
  55. (menucmd "m=$(-,6,5,4,3,2,1)")
  56. "-9"
  57.  
  58.      $(*,<val1>,<val2>,...<valn>)
  59.         The result of multiplying the numbers  <val1>,<val2>,...<valn>  is
  60.         returned.
  61. Example:
  62. (menucmd "m=$(*,1,2)")
  63. "2"
  64.  
  65. (menucmd "m=$(*,2,1)")
  66. "2"
  67.  
  68. (menucmd "m=$(*,1,2,3,4,5,6)")
  69. "720"
  70.  
  71. (menucmd "m=$(*,6,5,4,3,2,1)")
  72. "720"
  73.  
  74.  
  75.  
  76.     $(/,<val1>,<val2>,...<valn>)
  77.         The  result of dividing the number <val1> by <val2>,...  <valn> is
  78.         returned.
  79. Example:
  80. (menucmd "m=$(/,1,2)")
  81. "0.5"
  82.  
  83. (menucmd "m=$(/,1,2,3)")
  84. "0.16666667"
  85.  
  86. (menucmd "m=$(/,0.5,3)")
  87. "0.16666667"
  88.  
  89. (menucmd "m=$(/,0.5,1,2)")
  90. "0.25"
  91.  
  92. (menucmd "m=$(/,3,2,1)")
  93. "1.5"
  94.  
  95. (menucmd "m=$(/,2,1)")
  96. "2"
  97.  
  98. (menucmd "m=$(/,1,2,3,4,5,6)")
  99. "0.00138889"
  100.  
  101. (menucmd "m=$(/,6,5,4,3,2,1)")
  102. "0.5"
  103.  

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: DIESEL : substr 4 characters from right
« Reply #13 on: November 04, 2015, 12:33:10 PM »
I just use this reference.