Problem when using conditions

Problem when using conditions

tomanT9U6N
Contributor Contributor
1,145 Views
13 Replies
Message 1 of 14

Problem when using conditions

tomanT9U6N
Contributor
Contributor

Hello, can someone explain to me why the IF condition cannot be used in this code?

The time.txt file contains only the number 1688722295

Interestingly, if I delete the IF condition in this code, the program will work.

 

FILE OPEN "time.txt" FOR READ AS "inp"
INT $read_seconds = 0
FILE READ $read_seconds FROM "inp"
FILE CLOSE "inp"

INT $diff = time() - $read_seconds

IF $diff > 60 {
	MESSAGE INFO $diff
}
0 Likes
Accepted solutions (2)
1,146 Views
13 Replies
Replies (13)
Message 2 of 14

kevin.hammond3WX4X
Advocate
Advocate

Try this, enclose the condition to be checked.

 

FILE OPEN "time.txt" FOR READ AS "inp"
INT $read_seconds = 0
FILE READ $read_seconds FROM "inp"
FILE CLOSE "inp"
 
INT $diff = time() - $read_seconds
 
IF ($diff > 60) {
MESSAGE INFO $diff
}
0 Likes
Message 3 of 14

tomanT9U6N
Contributor
Contributor
I've tried and still get the error: unsupported element or command
0 Likes
Message 4 of 14

kevin.hammond3WX4X
Advocate
Advocate

Works for me, after i put the full path to time.txt in

i.e

FILE OPEN "C:\Users\KevinHammond\Desktop\time.txt" FOR READ AS "inp"
INT $read_seconds = 0
FILE READ $read_seconds FROM "inp"
FILE CLOSE "inp"

INT $diff = time() - $read_seconds

IF ($diff > 60) {
MESSAGE INFO $diff
}

 

0 Likes
Message 5 of 14

tomanT9U6N
Contributor
Contributor
Thank you then it is not a bug in the code, but in my computer.
0 Likes
Message 6 of 14

Sean571
Advocate
Advocate

Make sure the file is not located in folder that doesn't have read/write access like in "Program Files" or something. 

Sean Wroblewski
Applications Engineer

0 Likes
Message 7 of 14

old_snickers
Advocate
Advocate

I'm really confused now. Why does this work with the quotes at "inp" and another recently issue did not?

0 Likes
Message 8 of 14

tomanT9U6N
Contributor
Contributor

Writing data to the file and reading data from the file works. The macro error occurs when I insert an arbitrary condition in the code. 🫤

0 Likes
Message 9 of 14

lokesh.kalia
Autodesk
Autodesk

@old_snickers Hi. You don't actually need the double quotes around inp, given that this is a single word without spaces.

See the extract from the Macro Programming Guide below, which shows an example of defining so-called file handles without any quotes:

 

file-handle-doc.png

You can find the latest version of the Macro Programming Guide here: https://www.autodesk.com/support/technical/article/caas/tsarticles/ts/26zXUqtRe1Tur1KdK1pctn.html

(scroll down towards the bottom of the page).

 

@tomanT9U6N Hi. Unfortunately, I also can't reproduce your error. You might try using the 'macro debugger', it might give a clue to what is going wrong.

You invoke this by:

 

macro debug <path-to-macro-file>

 

I hope that will help.



Lokesh Kalia
Senior Manager, Software Development
Message 10 of 14

kevin.hammond3WX4X
Advocate
Advocate

I more item to check....

Is the macro being run from from a trusted files or trusted directory, i have seen macros questioned from time to time usually if they are stored on a network drive. check options as below.

kevinhammond3WX4X_0-1688969415929.png

Hope you get sorted 🙂

 

0 Likes
Message 11 of 14

tomanT9U6N
Contributor
Contributor

When I try macro debug, the whole code is displayed in one line. That's weird.

0 Likes
Message 12 of 14

tomanT9U6N
Contributor
Contributor
Accepted solution

Thank you all for your help, but the problem seems to be with my PC.

0 Likes
Message 13 of 14

kevin.hammond3WX4X
Advocate
Advocate
Accepted solution

1 last thing based on your last response.

what text editor are you using, i am wondering whether when you hit enter to go to the next line whether you are getting a carriage return line feed command?

I use notedpad++ but windows text editor will do, i would not use wordpad as it can give spurious results.

I have switched on these characters using..View...Show symbols

If you do not have these characters it would cause the whole macro to appear on one line

 

 

kevinhammond3WX4X_0-1688980449896.png

 

Message 14 of 14

tomanT9U6N
Contributor
Contributor

You are an absolute legend! I had the line ordering set to CR. After switching to CRLF the macro works!
Thank you very much 😊

0 Likes