Author Topic: Diesel Expression - Pick up the right values after delimiter -  (Read 3491 times)

0 Members and 1 Guest are viewing this topic.

cyberlacs

  • Guest
I would like to take the last digit after the tab -

Example I sequential number which is the file name.
1.dwg | 2.dwg | ... | 985.dwg
In this case the review is 0(zero) have to have this value


When the project has a review adiociono the delimiter -
1-1.dwg This project has 1 review.
2-5.dwg This project has 5 reviews.
985-15.dwg This project has 15 revisions - kkkkk Oh my God

I tried to search the Diesel expressions SPLIT method and has not.

How do I get a custom field

I'm waiting

Thank you

DIW_CADtech

  • Bull Frog
  • Posts: 368
  • Push limits, embrace success, & discard failure.
Re: Diesel Expression - Pick up the right values after delimiter -
« Reply #1 on: June 16, 2016, 12:54:43 PM »
Maybe this could help.

I use similar expressions to parse drawing names and remove/include dashes or other text.  you may have to modify this .. but take what you need.

$(substr,$(getvar,dwgname),1,3)

Will return first three letters of drawing name.
I guess it depends on the full patterning of your drawing naming convention. Do you have a set number of characters before the review count?

This may help too.
http://www.crlf.de/Dokumente/Diesel/Diesel.html

also found this

Code: [Select]
/*        D I E S E L
 
       Dumb Interpretively Evaluated String Expression Language
 
    This "Dumb Interpretively Executed String Expression Language" is  the
    kernel  of a  macro  language  you can customise by adding C code and
    embedding it into your program.
 
    It is short, written in portable C, and is readily integrated into any
    program.   It  is  useful  primarily  to  programs which  need a very
    rudimentary macro expansion facility without the complexity of a  full
    language such as Lisp or FORTH.
 
    DIESEL  copies  its  input directly  to  the  output  until  a  macro
    character, "$" or quoted string is encountered.  Quoted strings may be
    used  to  suppress evaluation  of sequences of characters which would
    otherwise be interpreted as macros.  Quote marks may  be  included in
    quoted strings by two adjacent quote marks.  For example:
 
"$(if,1,True,False)="""$(if,1,True,False)""""
 
    Status  retrieval, computation,  and  display are performed by DIESEL
    functions. The available  functions  are  as  follows.   User-defined
    functions  are  not  implemented;  what  you  see  is  all you've got.
    Naturally, if  you embed  DIESEL  in  your  application,  you'll  add
    functions  that  provide access to information and actions within your
    own program.  DIESEL's arithmetic  functions  accept  either  floating
    point  or  integer arguments, and perform all calculations in floating
    point.
 
    DIESEL String Functions
    -----------------------
 
    $(+,<val1>,<val2>,...<valn>)
The  sum  of  the  numbers <val1>, <val2>, ...<valn> is returned.
 
    $(-,<val1>,<val2>,...<valn>)
The  result  of subtracting the numbers <val2> through <valn> from
<val1> is returned.
 
    $(*,<val1>,<val2>,...<valn>)
The result of multiplying the numbers  <val1>,<val2>,...<valn> is
returned.
 
    $(/,<val1>,<val2>,...<valn>)
The  result of dividing the number <val1> by <val2>,...  <valn> is
returned.
 
    $(=,<val1>,<val2>)
If the numbers  <val1>  and  <val2>  are  equal  1  is  returned,
otherwise 0 is returned.
 
    $(<,<val1>,<val2>)
If  the number <val1> is less than <val2> 1 is returned, otherwise
0 is returned.
 
    $(>,<val1>,<val2>)
If the number  <val1>  is  greater  than  <val2>  1  is  returned,
otherwise 0 is returned.
 
    $(!=,<val1>,<val2>)
If  the  numbers  <val1>  and  <val2> are not equal 1 is returned,
otherwise 0 is returned.
 
    $(<=,<val1>,<val2>)
If the number <val1>  is  less than  or  equal  to  <val2>  1 is
returned, otherwise 0 is returned.
 
    $(>=,<val1>,<val2>)
If  the  number  <val1>  is  greater  than or equal to <val2> 1 is
returned, otherwise 0 is returned.
 
    $(AND,<val1>,<val2>,...<valn>)
The bitwise logical AND of the integers <val1> through <valn> is
returned.
 
    $(EQ,<val1>,<val2>)
If the strings <val1> and <val2>  are  identical  1  is  returned,
otherwise 0.
 
    $(EVAL,<str>)
The  string <str> is passed to the DIESEL evaluator and the result
of evaluating it is returned.
 
    $(FIX,<value>)
The real number <value> is truncated to an integer  by discarding
any fractional part.
 
    $(IF,<expr>,<dotrue>,<dofalse>)
If  <expr>  is nonzero,  <dotrue>  is evaluated  and returned.
Otherwise,  <dofalse>  is  evaluated  and returned.  Note that the
branch not chosen by <expr> is not evaluated.
 
    $(INDEX,<which>,<string>)
<string> is assumed to contain one or more values delimited by the
macro argument separator character, comma.  <which> selects one of
these values to be extracted, with the first item  numbered  zero.
 
    $(NTH,<which>,<arg0>,<arg1>,<argN>)
Evaluates  and returns  the  argument selected  by  <which>. If
<which> is 0, <arg0> is returned, and so on.  Note the difference
between  $(NTH)  and  $(INDEX);  $(NTH) returns one of a series of
arguments to the function while $(INDEX) extracts a value  from  a
comma-delimited string passed as a single argument.  Arguments not
selected by <which> are not evaluated.
 
    $(OR,<val1>,<val2>,...<valn>)
The  bitwise  logical  OR of the integers <val1> through <valn> is
returned.
 
    $(STRFILL,<string>,<ncopies>)
Returns the result of concatenating <ncopies> of <string>.
 
    $(STRLEN,<string>)
Returns the length of <string> in characters.
 
    $(SUBSTR,<string>,<start>,<length>)
Returns  the  substring  of <string> starting at character <start>
and extending for <length> characters. Characters in  the  string
are numbered from 1.  If <length> is omitted, the entire remaining
length of the string is returned.
 
    $(UPPER,<string>)
The  <string> is returned converted to upper case according to the
rules of the current locale.
 
    $(XOR,<val1>,<val2>,...<valn>)
The bitwise logical XOR of the integers <val1> through <valn> is
returned.
...
*/

I am very  trainable....   (forgive my spelling)

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Diesel Expression - Pick up the right values after delimiter -
« Reply #2 on: June 16, 2016, 05:14:50 PM »
I would suggest something like the following, but I believe DIESEL has a 256 character limit on evaluated expressions, so this is unlikely to work.

Code: [Select]
$(if,$(eq,-,$(substr,$(getvar,dwgname),$(-,$(strlen,$(getvar,dwgname)),6),1)),
    $(substr,$(getvar,dwgname),$(-,$(strlen,$(getvar,dwgname)),5),2),
    $(if,$(eq,-,$(substr,$(getvar,dwgname),$(-,$(strlen,$(getvar,dwgname)),5),1)),
        $(substr,$(getvar,dwgname),$(-,$(strlen,$(getvar,dwgname)),4),1),
        0
     )
 )

Here's a similar thread:
https://www.theswamp.org/index.php?topic=48081.0

ChrisCarlson

  • Guest
Re: Diesel Expression - Pick up the right values after delimiter -
« Reply #3 on: June 17, 2016, 08:26:55 AM »
Your best bet is to standard-ize the file name. Diesel does not recognize hyphens as a delimiter, pretty sure it's CSV style only.

I would do 000-00 through 985-15, etc.


015-12
Code: [Select]
$(substr,$(getvar,dwgname"),5,2)
Would return 12

123-05

would return 05

DIW_CADtech

  • Bull Frog
  • Posts: 368
  • Push limits, embrace success, & discard failure.
Re: Diesel Expression - Pick up the right values after delimiter -
« Reply #4 on: June 17, 2016, 06:17:42 PM »
if your revisons are at least always 2 digits  (01 thru 99)  then you could use a math functuion to determin the location start

stringlenth - 5    ((2 digits plus ".dwg")

so no matter what your file name length you can start 2 digits before the "."

I am very  trainable....   (forgive my spelling)

DIW_CADtech

  • Bull Frog
  • Posts: 368
  • Push limits, embrace success, & discard failure.
Re: Diesel Expression - Pick up the right values after delimiter -
« Reply #5 on: June 17, 2016, 06:31:17 PM »
like this....

Code: [Select]
$(substr,$(getvar,dwgname),$(-,$(strlen,$(getvar,dwgname)),5),2)
No matter the character count it will return the last two digits prior to the "."
I am very  trainable....   (forgive my spelling)