Reading the SU API
-
OK, is this the correct way to find all components (including nested ones) in the model?
model = Sketchup.active_model model.definitions.each do |c| puts "Component; #{c.name}" end -
That is showing all the component definitions, in the model. Including nested definitions.
Is that what you are trying to do? Or do you want a list that includes every isntance of each definition too? For that do:
model = Sketchup.active_model model.definitions.each do |c| c.instances.each do |ins| puts "Component; #{ins}" end endChris
-
OK, is this right?
model = Sketchup.active_model model.definitions.each do |c| c.instances.each do |s| puts "Component; #{c.name} #{s.transformation.origin.to_s}" end endMy output (Box03 inside Box01):
%(#BF0000)[Component: Box02 (106.466771", -5.289104", 0")
Component: Box03 (11.477469", 39.803972", 6.9375")
Component: Box01 (0", 0", 0")] -
Understood:-)
%(#BF0000)[106.466771389033
-5.28910358007033
6.57113252700015e-015
11.4774687529651
39.8039723918033
6.93750000000001
0.0
0.0
0.0] -
The
[to_s](http://code.google.com/apis/sketchup/docs/ourdoc/point3d.html#to_s)method is appropriate for printing a Point3d. You can't just print an Array and have it come out reasonably. -
....s.transformation.origin.to_a....originis a 3D-point - alternatively would return an array like [0,0,0] which you can use as a point or take xyz values -
Understood:-) Can you mix strings, and numbers in a array without having to change them (to_s or to_f) later? If so is it efficient?
-
Things like a 3d-point can be made into an array using to_a - these are then all floats [0.0,1.2,3.4]
An array can be made thus
array=[]
array[0]=1
array[1]=2.3
array[2]="Cat"
array[3]=nil
array.push([1,2,3,4])
array<<true
my_variable=123456789
array=array+[my_variable]
so array >>> [1,2.3,"Cat",nil,[1,2,3,4],true,myvaraible]
i.e. an integer, a float, a string, nil, an array, a boolean and a variable's value.
Individual items can be changed thus array[5]=false changes the boolean value
arrays can be sorted, added, subtracted, reversed, compacted, flattened, made_unique etc etc - they are very useful! -
Thanks!-) Think, I learned a lot of "stuff" in the past few days. Think I'll go back a couple of weeks, and see if I can better comprehend those posts:-)
-
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement