sketchucation logo sketchucation
    • 登入
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    🔌 Easy Offset | Offset selected faces in SketchUp in positive and negative offsets. Download

    [Plugin] Component/group tools

    已排程 已置頂 已鎖定 已移動 Plugins
    30 貼文 16 Posters 45.8k 瀏覽 16 Watching
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • artmusicstudioA 離線
      artmusicstudio
      最後由 編輯

      hello,
      i went thru all topics dealing with component naming,
      but i cannot find a solution.

      i would like to give a name to a created component by this code:

      ######## start code

      model = Sketchup.active_model
      entities = model.active_entities
      rl1 = [0, y1, 0]
      rl2 = [0, y2, z]
      group = entities.add_group
      entities2 = group.entities
      new_line = entities2.add_line rl1, rl2
      length = new_line.length

             centerpoint = rl1
                                        # Create a circle perpendicular to the normal or Z axis
             vector = rl2
             vector2 = vector.normalize!
         
             edges = entities2.add_circle centerpoint, vector2, $thradius
          
             kreis = entities2.add_face edges
             kreis.pushpull -(5/$faktor)/100
          
         $masterrailingtms = group.to_component      
         # HERE I WOULD LIKE TO DEFINE A NAME FOR THIS NEW COMPONENT, WHICH I CAN SEE IN IN SKP ENTITY-INORMATION-WINDOW. this name also hopefully appears in the copied instances of this component, but most important is the name for component [0]
      

      ######## end code

      can somebody help me?
      thanx
      stan

      1 條回覆 最後回覆 回覆 引用 0
      • TIGT 離線
        TIG Moderator
        最後由 編輯

        Your
        xxxx = group.to_component
        refers to an component-instance NOT a component-definition: so to find the instance's definition use:
        defn = xxx.definition
        then rename it thus:
        defn.name = "foo_fighter"
        Be aware if there is already a 'foo_fighter' definition it'll become 'foo_fighter#1' etc

        PS: don't use global $var variables which will potentially clash with others tools - wrap your code in your own module and use @var instead.

        TIG

        1 條回覆 最後回覆 回覆 引用 0
        • artmusicstudioA 離線
          artmusicstudio
          最後由 編輯

          hi tig, thanx,
          this work well, one step further for me, now i can identify the "children" of the masters exactly. that's perfect.
          just to understand exactly:
          a name of component instance defined by this method appears in the field "description"

          a group named by group.name = "xxx" appears in the filed "name"

          is there also a way to NAME a component or its instance besides a description?

          thanx
          stan

          1 條回覆 最後回覆 回覆 引用 0
          • TIGT 離線
            TIG Moderator
            最後由 編輯

            Both components and groups [and also images for that matter] that you see placed inside a model are instances of their 'definition'.

            Every 'definition' has a unique definition.name - this can be reset provided it is unique - if 'xxx' is already used SketchUp auto-increments the name as 'xxx#1' etc.
            For a component that is the 'Definition Name' displayed in Entity Info, the Component-Browser's top-most field, and in the Outliner as <defname>.
            A component-instance can also have a instance.name this the 'Name' displayed in Entity Info, and in the Outliner as name<defname>. This need not be assigned and it does not need to be unique.
            You can find defn = instance.definition etc.

            A group also has a unique definition.name that is usually hidden from the user - something like ' Group#99'. You can change this through the API to another unique definition.name - but for what purpose?
            There is also group.name - akin to the instance.name. This need not be assigned and it does not need to be unique. This is the 'Name' displayed in Entity Info and in the Outliner [if the Name=='' then the Outliner says 'Group']
            You cannot directly find a group.definition in the API, BUT defn = group.entities.parent should return its definition.

            The definition.description can be assigned and for a component appears this in the second-from-top field in the Component-Browser.
            Although you can assign a definition.description to a group it is not seen anywhere by a user - it is only accessible through the API.

            When you convert a group to a component the name of the component definition is taken as the group's definition.name [e.g. ' Group#666'] NOT the group.name.
            What is returned by the group's conversion to a component is an instance NOT a definition, so to find the definition itself use the code given in the earlier reply. Then you can use defn.name='xxxx' as desired...

            TIG

            1 條回覆 最後回覆 回覆 引用 0
            • plot-parisP 離線
              plot-paris
              最後由 編輯

              is there a Version that works with SketchUp 2016?

              Bulk conversion of components to groups doesn't seem to be working (and is sorely needed when importing a 3ds-model, where every object is a component)

              1 條回覆 最後回覆 回覆 引用 0
              • M 離線
                Mooeee
                最後由 編輯

                Is there any news as to whether this plugin will be updated to SketchUp 2017 as it looks a really useful plugin, or is there a similar plugin out there to use.

                1 條回覆 最後回覆 回覆 引用 0
                • sdmitchS 離線
                  sdmitch
                  最後由 編輯

                  @plot-paris said:

                  Bulk conversion of components to groups doesn't seem to be working (and is sorely needed when importing a 3ds-model, where every object is a component)

                  Here is a code snippet you can try. Paste it into the Ruby Console and press Enter. It will convert all Component instances in the selection to a group.

                  @mod = Sketchup.active_model
                  @ent = @mod.active_entities
                  @sel = @mod.selection
                  @vue = @mod.active_view
                  cmps = @sel.grep(Sketchup;;ComponentInstance)
                  cmps.each{|ci|
                   grp = @ent.add_group(ci)
                   grp.name = ci.definition.name
                   ci.explode
                  }
                  @mod.definitions.purge_unused
                  
                  

                  Nothing is worthless, it can always be used as a bad example.

                  http://sdmitch.blogspot.com/

                  1 條回覆 最後回覆 回覆 引用 0
                  • BoxB 離線
                    Box
                    最後由 編輯

                    Hopefully Plot will enjoy your post even though it is 1 year later.

                    1 條回覆 最後回覆 回覆 引用 0
                    • sdmitchS 離線
                      sdmitch
                      最後由 編輯

                      @box said:

                      Hopefully Plot will enjoy your post even though it is 1 year later.

                      DOH!!!

                      Nothing is worthless, it can always be used as a bad example.

                      http://sdmitch.blogspot.com/

                      1 條回覆 最後回覆 回覆 引用 0
                      • F 離線
                        faust07
                        最後由 編輯

                        Thanks sdmitch, used your code snippet to convert components to groups for MSPhysics. The reason is that MSP does not accept components for coupling with joints. The conversion of about 200 components with subcomponents into groups would have taken a long time...

                        1 條回覆 最後回覆 回覆 引用 0
                        • 1
                        • 2
                        • 2 / 2
                        • 第一個貼文
                          最後的貼文
                        Buy SketchPlus
                        Buy SUbD
                        Buy WrapR
                        Buy eBook
                        Buy Modelur
                        Buy Vertex Tools
                        Buy SketchCuisine
                        Buy FormFonts

                        Advertisement