why my 3dsmax code will execute twice

why my 3dsmax code will execute twice

2849931823
Observer Observer
283 Views
5 Replies
Message 1 of 6

why my 3dsmax code will execute twice

2849931823
Observer
Observer

My 3dsmax script code will be executed incorrectly twice, whether I run it in the script editor or script listener, the code will always be executed twice
Just like below:

print("hello world")
"hello world"
"hello world"
I have tried reinstalling 3dsmax, but it still cannot be resolved. This issue is causing me a lot of trouble

I hope someone can help me solve this problem, thank you very much!!!

0 Likes
Accepted solutions (1)
284 Views
5 Replies
Replies (5)
Message 2 of 6

MartinBeh
Advisor
Advisor

This is normal behavior.

You are seeing first the output of the print statement, and second the return value of your statement, which is the same string.

You could wrap your code into a block with a return code, i.e.

(
    print "Hello!"
    ok
)

Now you should only see one "Hello!" from the output of the print statement followed by the return value of the block, which is "OK"

 

Or you replace print with format, which returns OK on itself and use format "Hello!\n"

Martin B   EESignature
→ please 'Like' posts that are helpful; if a post answers your question please click the "Accept Solution" button.
Message 3 of 6

2849931823
Observer
Observer

All of my code will run twice,Just like the code below me:

global i=0
i+=1
print(i)

will get

1
2

The final value of i will be 2

 

If I use a script to render images, I will render them twice in the end, which greatly increases my time,

I can't understand how this bug actually came about

However, thank you for your response

0 Likes
Message 4 of 6

MartinBeh
Advisor
Advisor

Very strange!

Where do you run those three lines of code, in the listener or as a separate script? In a callback? 

 

This is the output I get from your three lines of code when run as a separate script:

0
1
1
1

The first zero is the return value of "global i=0"

The first one is the the return value of "i+=1"

The second one is the result of the print statement "print(i)"

And the third one is the return value of the print statement

 

And you say that all you get is 

1
2

That seems really odd. In particular it is odd that the "global i=0" is not repeated for you but the rest.

 

Do you have any callbacks running?

Martin B   EESignature
→ please 'Like' posts that are helpful; if a post answers your question please click the "Accept Solution" button.
0 Likes
Message 5 of 6

2849931823
Observer
Observer

The problem was caused by some reasons. I uninstalled 3dsmax2024 and then reinstalled it. It was completely normal before uninstallation, but the problem occurred after reinstallation. Whether I run it from a script listener or a script editor, all the code will run twice.

I suspect that some files were not completely uninstalled and caused this problem. I tried uninstalling 3dsmax2024 and installing 3dsmax2023, but it will still run twice in 2023.

Now, I can only control the rendering of a specified number of images from the code now, and then exit the code to achieve my goal, otherwise I will still render twice.

Thank you very much for your reply

0 Likes
Message 6 of 6

MartinBeh
Advisor
Advisor
Accepted solution

That still does not explain why only a part of your code is executed twice (i.e. not the "global i=0" part). And why you are not seeing all of the output I am seeing (my "0 1 1 1" vs your "1 2").

Martin B   EESignature
→ please 'Like' posts that are helpful; if a post answers your question please click the "Accept Solution" button.
0 Likes