Knowing the ComponentInstance a DimensionLinear is attached

Knowing the ComponentInstance a DimensionLinear is attached

Postby ittayd » Wed Jun 21, 2017 8:11 pm

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

ittayd 
 

Re: Knowing the ComponentInstance a DimensionLinear is attac

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

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

    Re: Knowing the ComponentInstance a DimensionLinear is attac

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

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

    ittayd 
     

    Re: Knowing the ComponentInstance a DimensionLinear is attac

    Postby Dan Rathbun » Fri Jun 30, 2017 5:48 am

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

      Re: Knowing the ComponentInstance a DimensionLinear is attac

      Postby TIG » Fri Jun 30, 2017 11:45 am

      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 !!!
      1
      TIG
      User avatar
      TIG 
      Global Moderator
       

      SketchUcation One-Liner Adverts

      by Ad Machine » 5 minutes ago



      Ad Machine 
      Robot
       



       

      Return to Developers' Forum

      Who is online

      Users browsing this forum: anshie and 7 guests

      Visit our sponsors: