Great. I'm glad you were able to adapt my proof of concept for your use case, but for posterity, I want to reiterate what I said in my original post:
Edit: I developed the second code example further to eliminate this redundancy.
Great. I'm glad you were able to adapt my proof of concept for your use case, but for posterity, I want to reiterate what I said in my original post:
Edit: I developed the second code example further to eliminate this redundancy.
Under no circumstances should any significant code be placed at the outermost level of a property change script. This script will be executed for every change to every property on this component. You will be constructing the function in the def
from scratch on every property change whether you care about the particular change or not.
Guard everything in Vision property change events with an
if event.propertyName=="something":
check at the outermost indent level.
If you must, place the def
inside the if...
. But better (way, way better, and faster) is to move function definitions to a script in the project library, where its def
will happen once and persist for all callers to use quickly. (Same with imports.)
Edit: Justin, you introduced this abomination in your advice above. You've offered similar advice in other topics, citing convenience to excuse the poor practice. Please stop.
I can't let this pass:
It would have been an extra few seconds for you to show two code blocks, with one labeled "place this in a project library script", and the other for the event, altered to call someScript.someFunction()
. Conveys the same information, without displaying bad practices.
That is simply not a reasonable understanding for most supplicants here. Or lurkers. Do you really think our OP will go back and split up his working code into two pieces? Or even understand what parts need to be where?
Let me repeat: please stop.
Point taken, and thank you for the stern rebuke. When I get time, I'll go back and correct the answers above. Feel free to PM me with any other answers you take issue with, and if I can, I'll fix them as well.
@pturmel, @Dharani_T : The solution has been corrected.
Thanks for the corrected code !!.
As said earlier,
i have 6 circles (Circle 1, Circle 2..) for 6 canvas
How to make
circle = canvas.parent.getComponent('Circle')
as dynamic
I imagined that each canvas and circle would be separated into six container components. In this way, they there would be no need for the circles and canvases to have unique names.
I have 6 canvas and 6 circles separate as
but how to have separate each canvas and circle.
Can u explain if u dont mind.
I see. That layout is not what I had envisioned. Is template1 always associated with circle1, and 2 with 2, and so on?
yes you are right
In your setCircleColor function, you could probably use the name attribute of the canvas to create the needed suffix for your circle.
The canvas will always be correct, since it is the direct ancestor of the component that calls the function that gets it, so the circle which is called by name would be the only part of the scripting that would need to be dynamic. To do this, you would change this line:
circle = canvas.parent.getComponent('Circle')
to this:
circleSuffix = canvas.name.replace('Template Canvas', '')
circleName = 'Circle' + circleSuffix
circle = canvas.parent.getComponent(circleName)
Working as expected!! Thank you for the support as always.
You're welcome. FWIW, this post was my 100th solution, so...
Thanks!
Only 1000 more to catch up with Phil !