IF statements in diesel expressions

IF statements in diesel expressions

dpalmerVQ54W
Enthusiast Enthusiast
622 Views
2 Replies
Message 1 of 3

IF statements in diesel expressions

dpalmerVQ54W
Enthusiast
Enthusiast

I'm trying to use the IF function to display part of a drawing name, where the filename name varies in length due to the length of project numbers and other addtional parts of buildings and floors.

 

For example

12345-A1-A.dwg

12345-001-A1-A.dwg

12345-001-U1-A1-A.dwg

The red parts of the above filenames are the project number.

 

I found an IF statement in another forum which I adapted btu I'm getting unexpected results which appear to be due to the letters in the filename names, for example the "U" in  the above exmaples.

 

$(if,$(substr,$(getvar,dwgname),6,3),"-00",$(substr,$(getvar,dwgname),1,9),$(substr,$(getvar,dwgname),1,5))

 

This expression is in the Field adjacent to "PC PPROJECT NO."  In the example below it should be displaying 12345-001, ie the first 9 characters of the "DRAWING No."

 

dpalmerVQ54W_0-1703085500661.png

 

If I change the filename so that the project number is the shorter of our options 12345 I get this:

 

dpalmerVQ54W_1-1703085756908.png

 

If I use the longer of our Project No. options and instead of a Unit/Building number (the U1 or BB) I have a site code (eg 11) I get this, which is correct.

 

dpalmerVQ54W_2-1703085981581.png

 

To me it seems that the letters are causing the IF statement to trip up. I was under the impression that it did not matter what the character was for an IF statement to work. I must be wrong.

 

Any help would be appreciated.

David P
AutoCAD 2021
Accepted solutions (1)
623 Views
2 Replies
Replies (2)
Message 2 of 3

Kent1Cooper
Consultant
Consultant
Accepted solution

I don't work in Diesel enough to be sure, but shouldn't the (if) function have an (eq) function wrapped around the (substr) function and the "-00" target value?  As it's written, it seems to only look at the existence of a substring, not whether it is equal to a desired set of characters.

Kent Cooper, AIA
Message 3 of 3

dpalmerVQ54W
Enthusiast
Enthusiast

Thanks @Kent1Cooper that seems to have worked. I used

 

$(if,$(eq,$(substr,$(getvar,dwgname),6,3),"-00"),$(substr,$(getvar,dwgname),1,9),$(substr,$(getvar,dwgname),1,5))

 

took me a while to get the brackets correct.

David P
AutoCAD 2021
0 Likes