sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Entities relationship - Sketchup Ruby SDK

    Scheduled Pinned Locked Moved Developers' Forum
    14 Posts 4 Posters 1.2k 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.
    • Dan RathbunD Offline
      Dan Rathbun
      last edited by

      Did You group the boxes, and then give each group a name ??

      I'm not here much anymore.

      1 Reply Last reply Reply Quote 0
      • N Offline
        nicholas_yue
        last edited by

        @dan rathbun said:

        Did You group the boxes, and then give each group a name ??

        No, I didn't

        I am working on an exporter and need to deal with scenes as is rather than require the plugin user to change their work flow.

        I am kind of re-building a scene representation from a polygon soup.

        1 Reply Last reply Reply Quote 0
        • Dan RathbunD Offline
          Dan Rathbun
          last edited by

          Well then unless the "boxes" have been grouped or made into a component... then they are nothing but primitives that happen to share vertices.

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • N Offline
            nicholas_yue
            last edited by

            @dan rathbun said:

            Well then unless the "boxes" have been grouped or made into a component... then they are nothing but primitives that happen to share vertices.

            Hi Dan,

            Thanks for the advisory.

            As you can see, I am new to Sketchup's workflow and best practices.

            If I understand correctly, it is reasonable to expect some group/component from proper Sketchup usage.

            Regards

            1 Reply Last reply Reply Quote 0
            • Dan RathbunD Offline
              Dan Rathbun
              last edited by

              @nicholas_yue said:

              If I understand correctly, it is reasonable to expect some group/component from proper Sketchup usage.

              Well.. yes, if the user wants to treat the collection as an entity,.. give it name so it can be found, or have that name when it's exported,... make it easy to move, or scale the "group".... and have the faces in the group inherit a color and/or material en masse (by assigning them to the group in one step. Otherwise you have to assign them to each individual face.)

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • thomthomT Offline
                thomthom
                last edited by

                @nicholas_yue said:

                @dan rathbun said:

                Did You group the boxes, and then give each group a name ??

                No, I didn't

                I am working on an exporter and need to deal with scenes as is rather than require the plugin user to change their work flow.

                Normal workflow would be to group or make components out of objects. In which case you can get the name. group.name and componentinstance.name, componentinstance.definition.name.

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

                1 Reply Last reply Reply Quote 0
                • TIGT Offline
                  TIG Moderator
                  last edited by

                  If you simply can't group/component the boxes' geometry [which would be a logical step when making them!]... BUT they are separated by 'gaps' then if you take a face or an edge you can use .all_connected - to get an array of all faces and edges connected to the face or edge. So if you know that there are just two separate sets of geometry in the same context that will be connected to each other, then make a list of all entities - say...
                  ents=Sketchup.active_model.entities

                  • then take
                    box1=ents[-1].all_connected
                  • to list all edges/faces connected to the last entity in the model... then
                    box2=[] ents.each{|e| if not e.all_connected.include?(box1[0]) box2=e.all_connected break end }
                  • Now box1 and box2 are arrays of the two 'separate' sets of geometry. If you just want just the boxes' faces then filer the arrays for e.class==Sketchup::Face etc...
                    Note that this will fail IF there's any other geometry or objects in the SKP...

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • N Offline
                    nicholas_yue
                    last edited by

                    @tig said:

                    ents=Sketchup.active_model.entities

                    • then take
                      box1=ents[-1].all_connected
                    • to list all edges/faces connected to the last entity in the model... then
                      box2=[] ents.each{|e| if not e.all_connected.include?(box1[0]) box2=e.all_connected break end }

                    I tried but it get's really slow with very large scene.

                    I am after a more direct way to find out
                    (1) How many objects are in the model
                    (2) For each object, what are the faces, edges, vertex

                    I am doing this to write out the information as a text output so I can render it in Renderman.

                    Is there an easier approach for folks writing exporter for SketchUp, I had a look at some of the example exporter and they don't look straight forward.

                    1 Reply Last reply Reply Quote 0
                    • thomthomT Offline
                      thomthom
                      last edited by

                      @nicholas_yue said:

                      (1) How many objects are in the model

                      If you mean "objects" as in groups or components, that is easy. Use model.definitions to access that. But if you mean "objects" as in clusters of connected meshes which isn't connected, then TIG's way is the only way to do it.

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

                      1 Reply Last reply Reply Quote 0
                      • Dan RathbunD Offline
                        Dan Rathbun
                        last edited by

                        @nicholas_yue said:

                        I am after a more direct way to find out
                        (1) How many objects are in the model

                        Sketchup.active_model.entities.count
                        also:
                        model.number_faces

                        I'm not here much anymore.

                        1 Reply Last reply Reply Quote 0
                        • thomthomT Offline
                          thomthom
                          last edited by

                          @dan rathbun said:

                          @nicholas_yue said:

                          I am after a more direct way to find out
                          (1) How many objects are in the model

                          Sketchup.active_model.entities.count

                          That only returns the number of entities in the root context, entities inside groups and components are not counted.

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

                          1 Reply Last reply Reply Quote 0
                          • Dan RathbunD Offline
                            Dan Rathbun
                            last edited by

                            Yep.. and doesn't account for other kinds of things that would likely be exported, like: Layers, Materials, Colors, Scenes, Styles, AttributeDictionary etc.

                            Basically all the collection counts need to be summed, together with model.entities and definitions.each.entities, but it may be possible to use ObjectSpace.each_object to get raw numbers, rather than iterating the model DOM... but only ONE model must be open, or the numbers are worthless.

                            I'm not here much anymore.

                            1 Reply Last reply Reply Quote 0
                            • N Offline
                              nicholas_yue
                              last edited by

                              Thanks for all the suggestions, pointers and tips.

                              I am making progress exporting both raw entities and entities within components instances (including the transformation)

                              It's not complete yet (some instance are place wrongly) but I should be able to figure the rest out (might be group handling etc)

                              Thank you once again.

                              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