• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Knowing the ComponentInstance a DimensionLinear is attached

Scheduled Pinned Locked Moved Developers' Forum
5 Posts 3 Posters 1.4k 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 21 Jun 2017, 19:11

    I have a dimension attached to a component instance (it moves with it, changes when it is stretched, etc.). Using the API, dim.start[1].parent returns a ComponentDefinition. This of course doesn't tell me which instance it is attached to. Is there a way of knowing? Or is it a bug?

    (A brute force method is to go over every instance, iterate over all its vertices and compare with the one of the dimension. I'm looking for something more elegant, and that will work when attaching to an edge etc.)

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

      @ittayd said:

      I have a dimension attached to a component instance (it moves with it, changes when it is stretched, etc.).

      Using the API, dim.start[1].parent returns a ComponentDefinition. This of course doesn't tell me which instance it is attached to. Is there a way of knowing?

      Yes.

      dim.start[0]

      Test it. If it is nil the dimension is unassociated.

      dim.start[0].nil?

      or simply in Ruby:
      ` inst_start = dim.start[0]
      if inst_start

      use it

      else

      assume it is nil as nil evals as FALSE in Ruby

      end`

      You can also use Ruby's multiple assignment:
      ent, point = dim.start

      Ref: http://ruby-doc.org/core-2.0.0/doc/syntax/assignment_rdoc.html

      @ittayd said:

      Or is it a bug?

      Sounds like a brain bug. 😉 (Reference to "Starship Troopers II".)

      As the API doc is quite clear that the first member of the returned array is supposed to be a reference to the entity.

      I'm not here much anymore.

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

        dim.start[0] will return a Vertex or Edge. How do I know the ComponentInstance dim.start[0] is part of? As I wrote dim.start[0].parent returns a ComponentDefinition.

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

          FYI, it's been shown By ittayd that this is bugged. Thomas Thomassen has filed the bug internally.

          The method is supposed (according to the API docs) to return the instance in favor of any primitive (vertex, edge, etc.)

          See:
          https://forums.sketchup.com/t/how-can-i-tell-to-which-instance-a-dimension-is-attached/47309

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • T Offline
            TIG Moderator
            last edited by 30 Jun 2017, 10:45

            Until it's fixed how about a clunky and convoluted workaround ?
            If the pa=dim.start[0].parent is a component-definition then you need to see if there is pa.instances[1] if not then the one instance is the answer.
            If there are more than one instance you need to iterate those, and assemble a list of their transformation.origin positions [ensuring the transformation steps back to match the dim's parent's and of course takes into account any instance scaling etc...] - let's call that 'pvs'.
            The pt=dim.start[0] gives you a point inside the definition.
            You have ps=dim.start[1] as the point of the dim in 3d space.
            Transform the 'pvs' inversely and compare that point with ps, if they match then you could have a hit.
            Of course two or more instances where some are rotated or flipped so that vertex is coincident in 3d returns two or more 'hit' points, so it'd not be possible to determine the attachment that way...

            So, it's better if it worked like it should !!!

            TIG

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

            Advertisement