Hello,
I have a simple python script that changes the block type. When I run it, it seems to skip some of the blocks.
To run, just load the attached script and run it. It looks for all the blocks and changes it.
Solved! Go to Solution.
Ah. figured it out. I needed to add this line:
ce.setAttributeSource(block,"/ce/block/type", "USER")
Hi
I think you need to check the blocks of CE whether all the closures were exactly made, and reiterate to get the entire blocks.
Dr. Selvavinayagam
Thank you for the response.
In my example, I have 9 blocks. When I run the script, it works on 8 of them. The 9th one does not change.
However, I can select the block and change the type manually using the UI.
I'll give your suggestion a try, nonetheless, thank you.
-Robert
After some more experiments, I found that if I select the block that did not respond to the script, and
update it manually using the UI, the block will then respond to the script thereafter. This seems like a bug,
or there is something I am not doing correctly.
Ah. figured it out. I needed to add this line:
ce.setAttributeSource(block,"/ce/block/type", "USER")
This is a bit tricky. When setting attributes in Python, it's the user set values of these attributes that are changed. The default values for the attribute type are not changed. So, if you have a block with the attribute type whose source is "default", its value won't change. If you have a block with the attribute type whose source is a user-set value (bold in the Inspector), then this value will change. Basically, this means that in Python you have to set the attribute value and set the source to be "USER" as you've figured out.