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

Please help me to get a group's layer

Scheduled Pinned Locked Moved Developers' Forum
7 Posts 3 Posters 900 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.
  • L Offline
    Lê Việt Trường
    last edited by 5 Jan 2017, 05:39

    Hi there,
    Im beginner to Sketchup ruby,
    Im writing something like this:

    a = instance.parent.layer.name
    

    with "instance" is a component instance placed inside a group/component. "instance.parent" returns a ComponentDefinition, not the instance, so that i cant get the layer's name i wanted.
    Is there some way for me can get this?
    Thanks.

    1 Reply Last reply Reply Quote 0
    • T Offline
      TIG Moderator
      last edited by 5 Jan 2017, 14:14

      a = instance.parent.**instances[0].**layer.name
      Should now return the instance's parent [definition], then the group, then its layer, then that layer's name.

      TIG

      1 Reply Last reply Reply Quote 0
      • D Offline
        Dan Rathbun
        last edited by 5 Jan 2017, 15:11

        Hey TIG, what if the parent group definition has more than 1 instance, and the target is not the first in the instances collection ?

        Could a coder "tag" the target instance by pushing it's reference into the selection set, and then iterate the instances collection looking for a match ?

        ... Or, do they have to walk the model's entities tree ?

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • T Offline
          TIG Moderator
          last edited by 5 Jan 2017, 16:14

          @Dan

          I did think of that !
          But since we don't know the rest of the OP's code I assumed that the group was unique.

          Without more info, if there are multiple instances of the instance's parent group definition, then how can we know which of those the user intends to reference...
          If the instance is simply derived from its definition, and the user knows it's always nested inside a group, then he only needs to worry if there are multiple group instances...
          If the user has 'selected' the instance previously, e.g. by editing the group containing it then the group itself has been automatically made_unique, so there is only one instance.
          Since the OP is not currently at an advanced level I suspect he is not picking the instance using a tool & pick_helper.
          However, if the OP were doing this, then the pick_helper itself could be used to find the path to the picked instance and from that determine the actual instance of the group that the picked instance is inside ?
          In fact I think this is the only likely solution ?
          Since the same instance occurs inside several copied groups the actual container's instance is needed ?

          With v2017 the new instance_path method might help - from an input_point - but who knows ? ...

          TIG

          1 Reply Last reply Reply Quote 0
          • D Offline
            Dan Rathbun
            last edited by 6 Jan 2017, 16:58

            Good answer(s)!

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • D Offline
              Dan Rathbun
              last edited by 3 Feb 2017, 18:28

              (This last question needs it 's own thread.)

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • L Offline
                Lê Việt Trường
                last edited by 4 Feb 2017, 00:38

                Thank you Masters.
                I have another problem:
                I wrote code to make BOM base on ComponentReport of TIG. Then I place data on a html datatable.So I have to replace all "\n" by "<br>" like this:

                
                des=c.definition.description
                des=des.gsub("\n","<br>")
                
                

                Then the datatable looks good. Then I save data in a .xlsx file. Still look good when openned in Excel. But when I inserted it to LayOut, it create "x000D" before every new line in cell. Please help me how to solve this. Thanks a lottt.

                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