For the no directory entry error, likely …
fpath = File.expand_path("~/Desktop/myfile.txt")
FYI: Using special folders is fragile at least on Windows as these folders (ie, “Desktop”, “Documents”, “Favorites”, “Videos”, etc.) can be language localized and a Windows system API call may be needed to get the folder name.
What thread ? How old ? Be aware that
#entityID is not persistent between sessions. It predates the
Also, geometric operations can cause saved IDs to become invalid and new IDs created. (Such as when a face is broken into smaller faces, etc.)
If this is within the same session, it does not make much sense to save an array of integers to a text file. (You’d have to convert them back to integers again.)
Just save the array to a
@instance_var reference in your extension submodule.
model = Sketchup.active_model
insts = model.selection.grep(Sketchup::ComponentInstance)
@ids = get_ids(insts)
# ... later on use @ids
I would like to discourage you from passing the model’s selection object around between methods as it’s functionality is limited. In the above example, the result of
#grep is a plane ol’
Array object. So
insts is more versatile, and the
get_ids method becomes more usable by multiple places in the code.
So, in code, when you want to hold onto multiple references, you use an array or a hash. You do not use SketchUp’s selection object. That is meant for the user’s manual use, or if your code must show (highlight) elements for the user to see (and possible use afterward.)
My point is that new coders often misuse the selection object as a temporary collection to hold entities that they want their code to work on. This is not necessary. It also limits what you can do with the members of the selection, as said, it does not have as many nifty methods as a normal array.
And you can easily get a plain array from the selection using
#to_a or any of the many filter methods of
Enumerable which is mixed into the