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

Set group parent - How to?

Scheduled Pinned Locked Moved Developers' Forum
7 Posts 3 Posters 211 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
    th3lurker
    last edited by th3lurker 4 Mar 2013, 07:52

    This is probably a no brainer, but searching "set parent" "set owner" didn't return anything.
    Thing is, i still have some issues with add_group's speed as the number of groups in the model increases. So this idea popped in my head this morning, months after i last touched that code, what if i create an empty project with just shy of 1500 nameless, parentless groups? When i export i open that project, i pick an empty group, place my entities and rename the groups, but then i have to create this tree structure, where some groups own other groups. For example a wall group owning a window group owning a left frame, right frame , glass and etc. groups. This structure varies a lot. I see there is the possibility to move groups inside of the Outliner, but how can i do this in code?
    Thanks

    Edit: Is it me, or have they sped up the process? I could swear a couple of versions ago this would take a minute or so:

    def add_groups
       model = Sketchup.active_model
       ents = model.active_entities
    	for i in 0..1500
    		ents.add_group
    	end
    end
    
    1 Reply Last reply Reply Quote 0
    • T Offline
      thomthom
      last edited by 4 Mar 2013, 08:33

      @th3lurker said:

      This is probably a no brainer, but searching "set parent" "set owner" didn't return anything.
      Thing is, i still have some issues with add_group's speed as the number of groups in the model increases. So this idea popped in my head this morning, months after i last touched that code, what if i create an empty project with just shy of 1500 nameless, parentless groups? When i export i open that project, i pick an empty group, place my entities and rename the groups, but then i have to create this tree structure, where some groups own other groups. For example a wall group owning a window group owning a left frame, right frame , glass and etc. groups. This structure varies a lot. I see there is the possibility to move groups inside of the Outliner, but how can i do this in code?
      Thanks

      You cannot set the parent of a group or component. A group is in reality a special component instance - it even have a definition: http://www.thomthom.net/thoughts/2012/02/definitions-and-instances-in-sketchup/
      You can insert a new instance of a group in a new context using Entitie.add_instance - then delete the original, but that's the closest you get. But I wouldn't think that would be any faster. And you cannot create parent-less group or component instances.

      @th3lurker said:

      Edit: Is it me, or have they sped up the process? I could swear a couple of versions ago this would take a minute or so:

      Are you using OSX? (Please fill out your profile with system information.)
      There was a bug there I think related to adding groups that was fixed.

      Thomas Thomassen — SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund

      1 Reply Last reply Reply Quote 0
      • T Offline
        th3lurker
        last edited by 4 Mar 2013, 09:18

        @thomthom said:

        You cannot set the parent of a group or component. A group is in reality a special component instance - it even have a definition: http://www.thomthom.net/thoughts/2012/02/definitions-and-instances-in-sketchup/
        You can insert a new instance of a group in a new context using Entitie.add_instance - then delete the original, but that's the closest you get. But I wouldn't think that would be any faster. And you cannot create parent-less group or component instances.

        I see, i have no idea of the process behind moving a group inside of the outliner, it may well be a copy-paste operation.

        @thomthom said:

        Are you using OSX? (Please fill out your profile with system information.)
        There was a bug there I think related to adding groups that was fixed.

        I'm on windows, and i managed to track the slow-down to the number of groups in the project, but now it seems to work a lot faster. Sometimes we reach numbers of 2000+ volumes, each in an individual group, plus a couple of dozen other groups that make up the parents of these volumes, though they don't contain any drawable entities, just other groups. Exporting could take up to a full two minutes on these projects. I've even had crashes. I would gladly share the code with you guys, i'm sure you'd greatly improve it, but i am not allowed to.

        1 Reply Last reply Reply Quote 0
        • T Offline
          thomthom
          last edited by 4 Mar 2013, 09:24

          Adding entities to SketchUp does indeed slow down as more entities are already in the context you're adding it to. I'm suspecting it's SketchUp doing some check to see if entities merge etc.

          Another thing - keeping the Outliner open when you add geometry is known to cause slow-downs and possible crashes. Might it be that you had previously kept this window open?

          Also, you're aware of the disable_ui argument of Model.start_operation that will usually make most operations faster?

          And feel free to post code, might give us some ideas.

          Thomas Thomassen — SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

          1 Reply Last reply Reply Quote 0
          • T Offline
            thomthom
            last edited by 4 Mar 2013, 09:26

            Ah, just noticed the very last sentence of your post. Are you able to make a code sample which replicates your result? One generic enough for you to share?

            Thomas Thomassen — SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply Reply Quote 0
            • D Offline
              Dan Rathbun
              last edited by 5 Mar 2013, 00:24

              FYI: Empty group instances will get cleaned up by SketchUp quite quickly. To make them persistent they must have something within their entities, say a cpoint (that can be on a hidden layer.)

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • T Offline
                th3lurker
                last edited by 14 Mar 2013, 13:52

                Sorry, i was away for a few days. No, i don't have the time at the moment to post code, but i basically goes like this. I'll use Floor 0/ Wall 1/ Window/ Left Window Frame as an example.
                I have no idea how many volumes will be added to Left Window Frame until i have completed reading the file. This is important because entities.fill_from_mesh erases everything in the entity it is called from. So i create two "parallel" tree structures, one containing the groups (EG:Floor 0/ Wall 1/ Window/ Left Window Frame &Floor 0/ Wall 1/ Window/ Right Window Frame) and another containing the mesh, texture data for each face, other stuff and a "pointer" to the group this is supposed to go in to. When i finished reading all the data i start using it and create and fill each group.entities with the mesh, then i apply the information to the textures. The most timeconsuming in this is, by far, entities.add_group, taking up to a full 0.5 seconds when the number of groups jumps past 1500. I was hoping i could create an empty project with ~2000 empty groups, which i could just juggle around to create the exact tree stucture i need. There is no "stardard" tree structure for any of our projects, a wall might contain none or dozens of windows.
                I also understood that the c++ sketchup sdk is no longer supported, so we didn't take the risk to invest time in that.

                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