• Login
sketchucation logo sketchucation
  • Login
πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Weird DimensionLinear behavior

Scheduled Pinned Locked Moved Developers' Forum
5 Posts 3 Posters 1.7k Views 3 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    ittayd
    last edited by 18 Jun 2017, 14:14

    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 rectangle
    Right rectangle

    1 Reply Last reply Reply Quote 0
    • D Offline
      driven
      last edited by 18 Jun 2017, 16:58

      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

      learn from the mistakes of others, you may not live long enough to make them all yourself...

      1 Reply Last reply Reply Quote 0
      • D Offline
        Dan Rathbun
        last edited by 26 Jun 2017, 23:28

        @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, zscalemethods 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.

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • I Offline
          ittayd
          last edited by 27 Jun 2017, 02:39

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

          1 Reply Last reply Reply Quote 0
          • D Offline
            Dan Rathbun
            last edited by 30 Jun 2017, 05:07

            @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.

            Link Preview Image
            Class: Sketchup::DimensionLinear

            The DimensionLinear class represents linear dimensions.

            favicon

            SketchUp Ruby API Documentation (ruby.sketchup.com)

            ... 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.

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Buy SketchPlus
            Buy SUbD
            Buy WrapR
            Buy eBook
            Buy Modelur
            Buy Vertex Tools
            Buy SketchCuisine
            Buy FormFonts

            Advertisement