Hi @stevebaer could you look into this?
I have a set of scripts that are ran from a button, but if any of them uses rs.SelectedObjects() Rhino throws an error unless I run a script from the PythonEditor first. (So somethings seem to not be loaded correctly from the button-runner)
Ho Jorgen,
Can you share one such button script for testing?
EDIT: are you loading scripts with a macro or is the actual script in the button macro?
-Willem
One script I have imports IFCās through VisualArQ, selects all, meshes, joins based on layer, exports to a new file and reopens. That one always fails unless I run something in python editor.
I have another one too, that sections through stuff and the thing they share is that they use rs.Common("Mesh ā+settingsā ") to mesh all kinds of stuff and then uses rs.LastCreatedObjects() to identify them, and that too fails unless I run the exact same script from the python editor first. Then it works flawlessly after.
But if I make a simple tool like this one:
!_-RunPythonScript (
import rhinoscriptsyntax as rs
def makeBox():
rs.Command("_Box 0 10 10 10")
box = rs.LastCreatedObjects()[0]
return box
box = makeBox()
rs.SelectObject(box)
)
Then it works just fineā¦
So I guess itās not as easy as to just find the bug thenā¦
hmm indeed difficult to find if there is no reproduction possible.
My first guess would be that your script did not load the correct modules.
The error message reads CustomTable ā¦ GetSelectedObjects
The GetSelectedObjects is a method for the ObjectTable not a CustomTable
The python code for SelectedObjects is accesing scriptcontext.doc.Objects so it apprears that from the button scriptcontext.doc.Objects refers to a CustomTable.
Could it be that somewhere in the button scripts scriptcontext is loaded or assigned differently, is there some Grasshopper involved?
-Willem
Hi Willem, thanks for taking a look. The odd thing is that if I use rs.Command(āSelLastā) I get a similar error.
Maybe it has to do with meshing working in the background and a rs.sleep(0) could work, but that doesnāt make sense in the context of running the exact same script from within the python editor just once solves all issues for the instance of Rhinoā¦
Unfortunately I donāt have time to bugtrack this now.
That indicates something more in the Rhino core Iād say.
Does it happen when you run the command SelLast as well?
In that case it could be duplicated with an example file
-Willem
Did you find a repeatable case where a script fails?
No, we hurried off to spend 19.5 hours in the car to pick this little pup up
And has been busy with the little sweet heart since. I hope Iāll have time tomorrow between playing, feeding and more playing while the kids are at school
Oh boy; thatāll keep ya busy. Congratulations
Sure does, Iāve just spent an hour and a halv, doing nothing with her sleeping on my lap
Step one: making the new home āhomeā is going well so far.
OK, so I have done some testing on the script that fails unless ran once from the python editor. And I have no idea why it fails to select the objects, BUT if I add a check to see if they exists first as in āif objs: rs.SelectObjects(objs)ā then it doesnāt fail and I can run it from a button.
Why this fixes it I donāt know. The thing is that I know that they already exists, so do you have any idea why it works in the python editor with out the check?
Iāll restart the computer to verify that this āfixesā it.
Yep, still works after a restart. So that solves the issue, but doesnāt explain it though.
None the less, itās never wrong to check if something exists before I select itā¦
I can send you the script if you want to have a look. Itās my section tool so it needs a display mode installed too.
Sure, send the script. @Alain is this something you can take a look at?
Yes, no problem. Iāll look at it as soon as I get the script.