Reading the SU API
-
I had sent another reply, but it got timed out and lost. But what I think you are looking for is called the transformation origin. That is the axis of the component. So try this:
component_instance.transformation.origin
That might get you what you want,Chris
-
Once you create a variable in the Ruby Console, it stays until you shut down.
model=Sketchup.active_model
on a PC is needed once. It creates a reference. Even loading another model doesn't bother it. Ditto for model.this and model.that.Are you wondering where your component is? Assuming
compInst
is a ComponentInstance, it's at:compInst.transformation.origin
I am working as hard as I can on the second half of my tutorial. Nobody should be forced to figure out the API from the docs. "Cruel and unusual punishment" is forbidden by our constitution.
-
Thanks Chris, and Martin, I put aside my ruby project, and have been spending my time with SU's Ruby Console, a Web Console, and the SU API, slowly working my way through each classes, and their methods. Did I say that right?-) Yes, a drop dead beginners API guide would be a great help. Assume nothing, and go from Sketchup.active_model.entities...... and all the other "take it for granted" basics. Thanks for pointing me in the direction of component_instance.transformation.origin
Got sidetracked into figuring out how to get to a component inside another. The attached finds all of the ones at the first level, but fails to find the nested ones.model = Sketchup.active_model entities = model.entities definitions=model.definitions entities.each do |e| if e.is_a? Sketchup;;ComponentInstance definitions.each do |d| if e.definition.name == d.name puts "found definitions match for "+e.definition.name+", origin;"+e.transformation.origin.to_s end end end
Nice, now access to nested components.
-
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 end
Chris
-
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 end
My 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....
origin
is 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:-)
-
Advertisement