With a python script I’ve created an NMesh called ‘wave’ (so there is a DataBlock called ‘wave’).
Now I want to assign a scriptlink to this mesh, linking it to ‘test.txt’ and with the event FrameChanged. So I have a look at the reference documents and find this: addScriptLink(text,event)
So far, so good.
If I do alt-P twice I get 2 copies of explode2.py
linked to the object
The “if” is necessary but the “else” is not (I guess).
You have exactly the same code in the 2 branches
of the “if” :-? so there must be some redundancy
right?
I read a lot of your code and rewrite some of it.
In general if someone (at work) asks me to do something
I start by googling to see if you have something
to build on as I hate starting from scratch.
As for this script - it’s not a big deal but…
I tested it with no scripts linked already
I tested it with a dummy script linked already (Text.py)
I deleted all the scripts and tested again.
I was just trying to understand the (uncommented)
“if” and it seemed strange that you had exactly
the same code in the 2 branches (I checked this
by doing Find/Find Again).
It looked to me as if you were using an “if” to test
to see if there was already a link to the script
and to prevent duplicated execution on “framechange”.
but this still doesn’t address the point of my last mail
You have exactly the same code in the 2 branches
of the “if”
i.e. MESH3D.addScriptLink(NAME,EVENT)
Whatever test you put in the boolean expression
this is the code that gets executed.
I’ve taken the if out and I get exactly the same result
I get a link to 'explode2.py". As I said in the last mail`
I see the point of checking for duplication before
linking but otherwise why bother?
Ok, i understand the aesthetic side of your argumentation but …
my code carries out the operation only one and single time,
even if it appears twice in the text . If the script is yet linked, it
do just what it has to do : nothing .
The new code would oblige to carry out at least the following
operations:
1/ to seek for the variable NAME again (‘once’ again, we have
just done it in the test above)
2/ to translate it into text whereas it is “already” text ( are you
sure that it is so profitable)
3/ to write in the console, which is very long for an operation for
which nobody has a vital need .
( je comprends le coté esthétique de l’argument mais mon code
ne réalisera l’opération qu’une seule et unique fois,
même si elle apparaît deux fois dans le texte. Si le script est déjà
linké, alors il fera la seule chose qu’il doit faire : rien .
Le nouveau code obligerait à effectuer au moins
les opérations suivantes :
1/ chercher de nouveau NAME (encore une fois, on
vient de le faire dans le test au dessus)
2/ le traduire en texte alors que c’est déjà du texte
(pas très rentable)
3/ ecrire dans la console, ce qui est long pour
une opération dont personne n’a un besoin vital )