Weird DimensionLinear behavior
-
Dimensions that are inside components change their texts based on the instance scale. This is true in the GUI as well as the API.
For example, in the images below, the rectangles are instances of the same component. I open the left one, get a dimension entity and its text and then open the right one and get the text of the same entity which changed. A similar thing happens for positioning
Is there a way to get all texts of the dimension instance? Is there a way of programmatically change one?
(I'm using SU 17.2.2555)
-
you can do things by comparing instance scaling...
model = Sketchup.active_model defs = model.definitions insts = defs[0].instances insts.each{|i| p (i.scaled_size - i.unscaled_size)[0].to_mm if i.scaled_size != i.unscaled_size}
john
-
@ittayd said:
Is there a way to get all texts of the dimension instance?
As John explains you have to iterate the definition's instances collection, and apply the scaling of each instance's transform, to the value of the length between the start and end points (vertices.)
dim_length = defn_dim.start[1].distance(defn_dim.end[1])
The DC extension adds the
yscale
,zaxis
,zscale
methods to the
Geom::Transformation
class.@ittayd said:
Is there a way of programmatically change one?
NO. If the dimension is a member of a definition's entities, changing 1 changes them all.
-
Thanks, I'm asking about ways to interact with the text: getting, setting.
-
@ittayd said:
Thanks, I'm asking about ways to interact with the text: getting, setting.
No this is not what you asked!
Such a simple thing (as what method's a class has) can be easily found by looking at the API dictionary.
http://ruby.sketchup.com/Sketchup/DimensionLinear.html
... which is a subclass of (and therefore inherits methods from
http://ruby.sketchup.com/Sketchup/Dimension.html... which is a subclass of (and therefore inherits methods from
http://ruby.sketchup.com/Sketchup/Drawingelement.html... which is a subclass of (and therefore inherits methods from
http://ruby.sketchup.com/Sketchup/Entity.html... which is a subclass of (and therefore inherits methods from
http://ruby-doc.org/core-2.2.4/Object.html
You asked about dims nested inside transformed instances.
I am not sure if the
.text
getter will return transformed lengths or not. Also not sure what happens when the context is open and not. So test.The means I showed above avoids the conversion of text (
String
) into a numeric (Length
) object, and just gets the length.
Advertisement