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

Ruby api: reference point within a component

Scheduled Pinned Locked Moved Developers' Forum
3 Posts 3 Posters 718 Views
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.
  • T Offline
    torel
    last edited by 1 Dec 2014, 18:52

    Hi there,

    have a question, could not find elegant answer by myself, could be useful for others as well, so experts please help:

    imagine you have two component definitions C_outer and C_inner, an instance of C_inner is part of C_outer. For example C_outer is a house and C_inner is a door. We also have a reference point in C_inner's geometry, for example the center of the keyhole, that we want to use later to align other objects, for example to place a key into the keyhole.

    So if I create multiple instances of C_outer, i.e. multiple houses, how can I easily find the position of the keyhole of a given house? (I could retrieve the position of the house instance via ComponentInstance::transformation, but I will also need the transformation of the door, for which I first needed to find the door instance among the entities of the house which is quite cumbersome - is there a nicer way?)

    Hope the question is clear, tell me if I should elaborate more!

    Thx,
    Balazs

    Ropefall - plugin to easily draw ropes, wires, cables
    http://www.sketchrope.com
    (with non-expiring licence, no subscription)

    1 Reply Last reply Reply Quote 0
    • T Offline
      tt_su
      last edited by 3 Dec 2014, 10:51

      @torel said:

      (I could retrieve the position of the house instance via ComponentInstance::transformation, but I will also need the transformation of the door, for which I first needed to find the door instance among the entities of the house which is quite cumbersome - is there a nicer way?)

      That's how you do it - you need to combine all them transformations.

      1 Reply Last reply Reply Quote 0
      • D Offline
        Dan Rathbun
        last edited by 5 Dec 2014, 16:45

        Yes you do not need to search among ALL the house's entities, IF you know the door's definition.

        IF you do, then simply look in the definition's instances() collection.

        If there are multiple door definition's, then you can iterate the model's DefinitionList collection, testing each definition for some identity (name value, or attribute in an attribute dictionary, etc.,) ignoring any definitions that have no instance, ie:
        !defn.instances.empty?

        I'm not here much anymore.

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

        Advertisement