• Login
sketchucation logo sketchucation
  • Login
⚠️ Libfredo 15.4b | Minor release with bugfixes and improvements Update

[HowTo?] Find Instance parent's Instances

Scheduled Pinned Locked Moved Developers' Forum
6 Posts 4 Posters 445 Views 4 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.
  • M Offline
    MarcioAB
    last edited by MarcioAB 30 Nov 2008, 19:25

    Is there any API to find the parent ComponentInstance of a ComponentInstance ? (or any trick code for that?).

    Reading the documentation for entity.parent (below) I wonder why the parent method of a ComponentInstance give back the definition of its parent's Instance. If the parent method give back it's ComponentInstance (and not its parent's Definition), if one needs that parent definition it should just ask for parent.Definition.

    Am I missing something ? Is the part of the documentation that talks about "the future" addressing that ?

    Thank you.

    *parent

    The parent method is used to retrieve the parent entity of the entity. Think of the whole SketchUp model as a "Component Definition", just as you can import a .skp model as a component into another .skp model. Such is this reference. If an entity belongs to the top level model.entities list, then its parent with be the "Model". A Component Instance will have as its parent a Component Definition. An entity within a Group will also have as its parent a Component Definition. In the future, there may be a new "container" that more accurately describes an entities "container".*

    1 Reply Last reply Reply Quote 0
    • D Offline
      Didier Bur
      last edited by 30 Nov 2008, 20:55

      Hi marcio,
      Not sure if I understood you well, but when you say

      @unknownuser said:

      the parent method of a ComponentInstance give back the definition of its parent's Instance

      you're wrong here.
      If A is a component instance, A.parent returns the active_model (assuming you're not mining through nested components).

      And:

      @unknownuser said:

      Is there any API to find the parent ComponentInstance of a ComponentInstance ?

      This doesn't make sense to me. The parent of a component instance cannot be a component instance.
      You can think of A.definition as almost the 'parent' of this instance.
      Hope this helps,

      DB

      1 Reply Last reply Reply Quote 0
      • M Offline
        MarcioAB
        last edited by 1 Dec 2008, 01:18

        Hi Didier, maybe I'm misunderstanding how SketchUP works. Please let me explain how I get it with a bike example:

        [ComponentInstance][ComponentDefinition] <Instance Name> <Definition Name>

        [0x11][0x01] <my><Bike>
        [0x12][0x02] - <Front><Fork>
        [0x13][0x03] - - <this><Wheel> .... front wheel
        [0x14][0x02] - <Rear><Fork>
        [0x13][0x03] - - <this><Wheel> .... rear wheel

        Suppose I select the front wheel instance. Its parent is ComponentInstance:0x12.

        How can I discover that the front fork (ComponentInstance:0x12) is the parent of front wheel and not the rear fork (ComponentInstance:0x14) ?

        Thank you

        1 Reply Last reply Reply Quote 0
        • C Offline
          confitex architure
          last edited by 1 Dec 2008, 13:53

          Is this what you're looking for?

          def parent_of
          	selset = Sketchup.active_model.selection 
          	for e in selset
          		if (e.kind_of?(Sketchup;;ComponentInstance) ) 
          			compo_name = e.definition.name
          			parent_name = e.parent.name
          			puts compo_name
          			puts parent_name
          		end
          	end	 
          end
          

          Emmanuel

          1 Reply Last reply Reply Quote 0
          • R Offline
            RickW
            last edited by 1 Dec 2008, 15:52

            @didier bur said:

            Hi marcio,
            Not sure if I understood you well, but when you say

            @unknownuser said:

            the parent method of a ComponentInstance give back the definition of its parent's Instance

            you're wrong here.
            If A is a component instance, A.parent returns the active_model (assuming you're not mining through nested components).

            And:

            @unknownuser said:

            Is there any API to find the parent ComponentInstance of a ComponentInstance ?

            This doesn't make sense to me. The parent of a component instance cannot be a component instance.
            You can think of A.definition as almost the 'parent' of this instance.
            Hope this helps,

            But nested components is his example, and I've often had the same issue of wanting to know the containing space for a nested g/c. Fortunately, there's a new API command in SU7 that will give the "path" of the entity spaces (e.g. instance1>group1>group2>instance2):

            model=Sketchup.active_model
            model.active_path
            

            this will return 'nil' if you're in the model.entities space, and will return an array of all the groups/components you've entered (manually).

            RickW
            [www.smustard.com](http://www.smustard.com)

            1 Reply Last reply Reply Quote 0
            • M Offline
              MarcioAB
              last edited by 1 Dec 2008, 16:13

              That is exactly what I was looking for !

              Thank you
              Marcio

              Obs: A new documentation for SU7 Ruby APIs could be nice. It could be a kind of open Wiki so we all could help improve it, as write documentation is ... boring.

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

              Advertisement