IF STATEMENT DO NOT CONSIDER LETTERS AS NON-ZERO CHARACTER???

IF STATEMENT DO NOT CONSIDER LETTERS AS NON-ZERO CHARACTER???

Anonymous
Not applicable
1,284 Views
9 Replies
Message 1 of 10

IF STATEMENT DO NOT CONSIDER LETTERS AS NON-ZERO CHARACTER???

Anonymous
Not applicable

Hi I am working with If statement to automate my "next sheet" number for my template. I used this formula and was expecting this ,

 

LAYOUT TAB NAME: 007-END

 

$(if,$(substr,$(getvar,"CTAB"),5,1)"0" --->if 5th character = non-zero
,$(substr,$(getvar,"CTAB"),5,3) ---> If true (a non-zero which is E), it will return 5th to 7th character which is END
,$(if,$(substr,$(getvar,"CTAB"),6,1)"0" --> If it's false then it will look if 6th character = non-zero
,$(substr,$(getvar,"CTAB"),6,2) ---> If true (a non-zero), it will return the 6th and 7th character
,$(substr,$(getvar,"CTAB"),7,1))) ---> If false then it will return the 7th character only

 

It's a 7 character-length string. The formula works with other layout tab like 001-002, 002-003, ...... returning 2 and 3 respectively and 003-04A, 04A-04B..... returning 4A and 4B.

However for 007-END it returns an error  $(IF,??).

I tried to change the layout name to 007-4ND it returns 4ND. 

This means the formula is okay for any non-zero character (numbers 1-9) except for letters like in this case is letter E.

 

0 Likes
Accepted solutions (1)
1,285 Views
9 Replies
Replies (9)
Message 2 of 10

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... 

$(if,$(substr,$(getvar,"CTAB"),5,1)"0" --->if 5th character = non-zero
....


 

I don't work with Diesel except in a Modemacro expression, but knowing there's something close to equivalence with AutoLisp expressions apart from the commas and dollar signs in the structure of it, shouldn't there be some kind of "equals" function connecting the sub-string function with the "0"?  In AutoLisp terms, this is what it would be -- the red parts have no equivalent in your Diesel expression:

 

(if (= (substr (getvar 'ctab) 5 1) "0")

  ... then ...

  ... else ...

 

and likewise in your next evaluation of the 6th character.  As you have it, it looks like the sub-string function would return something other than nil, and the "0" would be  the 'then' expression [what to do if there is a 5th character, no matter what it is].

Kent Cooper, AIA
0 Likes
Message 3 of 10

Paul_Gander
Advocate
Advocate
Accepted solution
You need to use $(eq, to compare the character from ctab with your 0 character. You would use $(=, for comparing numerical values. If I've understood your logic correctly the whole formula should look like this: 
$(if,$(eq,$(substr,$(getvar,ctab),5,1),0),$(if,$(eq,$(substr,$(getvar,ctab),6,1),0),$(substr,$(getvar,ctab),7,1),$(substr,$(getvar,ctab),6,2)),$(substr,$(getvar,ctab),5,3))

We are looking for equal to 0 rather than NOT equal to 0 so I've switched the 'then' and 'else' clauses around. I'm assuming you are using this code in a field.

0 Likes
Message 4 of 10

Anonymous
Not applicable
Hi Paul,
Yup its the same logic. And Thank you so much. It works very well. Maybe, you could also help me regarding the format of mtext where i inserted a field. If the result is END or 4B (a two or three characters), the mtext format is okay. But if the result is only one character say for example 1 or 2, the mtext will include additional line spacing. What should I do, so that the result will just be on the correct position on the layout regardless of the result. Below are the screen shots.
a.

b.  

c.


d.





I don't wanna adjust the mtext position everytime the result is one character only.


0 Likes
Message 5 of 10

Anonymous
Not applicable

Hi Paul,
Yup its the same logic. And Thank you so much. It works very well. Maybe, you could also help me regarding the format of mtext where i inserted a field. If the result is END or 4B (a two or three characters), the mtext format is okay. But if the result is only one character say for example 1 or 2, the mtext will include additional line spacing. What should I do, so that the result will just be on the correct position on the layout regardless of the result. Below are the screen shots.
a.
1.JPG
b.  
2.JPG
c.
3.JPG



d.
4.JPG

I don't want to adjust the mtext position every time the result is only one character. Thanks.

0 Likes
Message 6 of 10

Anonymous
Not applicable

Thank you Kent. The "0" is negligible, I forgot to delete it though.

 

Your right! There should be something that would compare the given data with 0. I tried the = sign but it didn't work. An equivalent (eq) function did it comparing the data with 0 and returns a value of 1 if its true. You may see the reply of Paul below.

 

Another problem i encountered which you may have already encountered is concerning the format of the mtext. Its okay if the result is either a two or three-character long. However, when the result is a one-character long, it adds another line spacing which changes its position on the layout. Its absurd to move it to its proper position every time the result would be a one-character long.

 

I attached some screenshots on my reply to Paul.

0 Likes
Message 7 of 10

Sea-Haven
Mentor
Mentor
 

A good idea is dont ask two questions in one post where they are irrelevant ask about mtext in another you may get more answers that way. Look at www.lee-mac.com strip mtext.

 

Back to your first post another way not diesel is to check what the character number is eg "A" = 65 "Z"=90 "a" = 97 "z"= 122 "0" = 48 "9"=57 but be aware you have 52 characters upper and lower case, just check the range 48-57

0 Likes
Message 8 of 10

Paul_Gander
Advocate
Advocate

Are you able to post an example dwg file showing the issue so we can see how you've formatted your text/field?

 

Thanks.

0 Likes
Message 9 of 10

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... if the result is only one character say for example 1 or 2, the mtext will include additional line spacing. ....
d.
4.JPG

I don't want to adjust the mtext position every time the result is only one character. Thanks.


 

Can you make the Mtext Top-Center  justified [with appropriately adjusted insertion point]?  I would think that would result in the same positioning whether or not there is a blank second line.  Or, can it be just Text  instead of Mtext?  The M in Mtext, after all, stands for something completely irrelevant to what you're doing.

Kent Cooper, AIA
0 Likes
Message 10 of 10

Anonymous
Not applicable

Thank you Kent! You are right about using Top Center. 

 

Thank you guys!

0 Likes