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

Create groups of instances correctly

Scheduled Pinned Locked Moved Developers' Forum
8 Posts 3 Posters 342 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.
  • D Offline
    dacastror
    last edited by 15 Mar 2014, 18:58

    Hi all, I want to create a new group and place inside group or component with previously created in sketchup. I have observed that writing .Add_group(component) or .Add_group(group) may cause bug splats.. I do not know how to do this properly, Thanks in advance for your help
    (google translator)

    1 Reply Last reply Reply Quote 0
    • D Offline
      Dan Rathbun
      last edited by 15 Mar 2014, 22:09

      See this snippet example: [Code] encapsulate instance into group

      The error that was causing BugSplats was supposed to be fixed in v8.

      I'm not here much anymore.

      1 Reply Last reply Reply Quote 0
      • T Offline
        TIG Moderator
        last edited by 15 Mar 2014, 23:30

        You should use gp=entities.add_group()
        Then immediately gents=gp.entities
        then add things to the ' gents'...

        The only time you can add a group specifying its contents directly is if you are SURE that the contents are in the sane context as the group itself.

        It you 'cross-thread' context and entities you get splats...

        If you manually select some items and then 'group' them then that group is in the same context as the items selected - you cannot manually select items across different contexts...

        Similarly in code, you can only add items to a group directly IF they are BOTH in the active_entities context...

        So this will work:
        model=Sketchup.active_model ss=model.selection gp=model.active_entities.add_group(ss.to_a)
        BUT this MIGHT fail if the model.entities != model.entities
        model=Sketchup.active_model ss=model.selection gp=model.entities.add_group(ss.to_a)
        The selection might NOT be in the model.entities context.
        However, since a [manual] selection is always in the active_entities, it might be safe.
        A foolproof way would be:
        model=Sketchup.active_model
        ss=model.selection
        gp=ss[0].parent.entities.add_group(ss.to_a)[/ruby]

        Just THINK what you are coding 😒

        TIG

        1 Reply Last reply Reply Quote 0
        • D Offline
          dacastror
          last edited by 16 Mar 2014, 02:38

          thank you very much Dan and TIG this information is exactly what I needed 😄

          1 Reply Last reply Reply Quote 0
          • D Offline
            dacastror
            last edited by 16 Mar 2014, 03:36

            Unfortunately I have to perform the task outside the active context for what I'm going to use the method proposed by Dan, but I think you need to add the following properties;

            material, attribute_dictionaries, layer, description, entity_name, name, receives_shadows, casts_shadows

            I wonder if there are more properties that can be inherited by the new instance
            (google translator)

            1 Reply Last reply Reply Quote 0
            • T Offline
              TIG Moderator
              last edited by 16 Mar 2014, 13:59

              material ?

              TIG

              1 Reply Last reply Reply Quote 0
              • D Offline
                dacastror
                last edited by 16 Mar 2014, 17:07

                Yes, if the user has applied a material without opening the instance, the material is assigned to the instance and not to the faces, then it would seem that after executing the code, the object has lost color

                1 Reply Last reply Reply Quote 0
                • D Offline
                  Dan Rathbun
                  last edited by 16 Mar 2014, 21:36

                  @dacastror said:

                  ... Dan, but I think you need to add the following properties;

                  material, attribute_dictionaries, layer, description, entity_name, name, receives_shadows, casts_shadows

                  I wonder if there are more properties that can be inherited by the new instance
                  (google translator)

                  Yes you are correct. Just before the old instance is deleted, it's properties need to be copied over to the new instance.

                  I'm not here much anymore.

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

                  Advertisement