Weird DimensionLinear behavior

Weird DimensionLinear behavior

Postby ittayd » Sun Jun 18, 2017 3:14 pm

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)
left.PNG

right.PNG
0

ittayd 
 

Re: Weird DimensionLinear behavior

Postby driven » Sun Jun 18, 2017 5:58 pm

you can do things by comparing instance scaling...

Code: Select all
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
0
learn from the mistakes of others, you may not live long enough to make them all yourself...

driven 
PluginStore Author
PluginStore Author
 

Re: Weird DimensionLinear behavior

Postby Dan Rathbun » Tue Jun 27, 2017 12:28 am

ittayd wrote: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, zscalemethods to the
Geom::Transformation class.

ittayd wrote: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.
0
    I'm not here much anymore. But a PM will fire email notifications.
    User avatar
    Dan Rathbun 
    PluginStore Author
    PluginStore Author
     

    Re: Weird DimensionLinear behavior

    Postby ittayd » Tue Jun 27, 2017 3:39 am

    Thanks, I'm asking about ways to interact with the text: getting, setting.
    0

    ittayd 
     

    Re: Weird DimensionLinear behavior

    Postby Dan Rathbun » Fri Jun 30, 2017 6:07 am

    ittayd wrote: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.
    0
      I'm not here much anymore. But a PM will fire email notifications.
      User avatar
      Dan Rathbun 
      PluginStore Author
      PluginStore Author
       

      SketchUcation One-Liner Adverts

      by Ad Machine » 5 minutes ago



      Ad Machine 
      Robot
       



       

      Return to Developers' Forum

      Who is online

      Users browsing this forum: No registered users and 2 guests

      Visit our sponsors: