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

    Add_group API returns component instance?

    Scheduled Pinned Locked Moved SketchUp Bug Reporting
    sketchup
    13 Posts 3 Posters 1.2k 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.
    • thomthomT Offline
      thomthom
      last edited by

      I have never experienced that.

      Is that your full example? If you add only that to a .rb file - does that happen?
      Have you tried with all other plugins not loaded?

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

      1 Reply Last reply Reply Quote 0
      • R Offline
        rknmag
        last edited by

        Hi

        Thanks for the reply.

        This code is part of bigger ruby code, I am not sure, where I am messing up. I created simple ruby file with above code and it works without any problem. I stop loading all other plugin that is not helping. Next I will isolate rest of my code to see why it is happening, in case you have any pointers to look for please let me know.

        BTW : My OS is Win 7, I hope it will not have any impact on this issue.

        Thanks
        rknmag

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

          I'm afraid I don't know what it could be.

          You use the reference to the newly created group immaterially? Or is there code in between?
          Is there any code that converts groups to components?

          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

            This won't happen unless the base classes have been interfered with - either within your code or some third-party code - OR your code makes the new group into a component before you try to get its entities.
            Can you supply more code/context etc...

            TIG

            1 Reply Last reply Reply Quote 0
            • R Offline
              rknmag
              last edited by

              Hi

              I am checking the class of the add_group() return value immediately, no other code in-between.

              Thanks
              rknmag

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

                I think I saw another thread where unexpected entities was returned - think it was fixed by a reinstallation.

                Have you tried on another machine?

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

                1 Reply Last reply Reply Quote 0
                • R Offline
                  rknmag
                  last edited by

                  Yes, I tried in two different machines. I also uninstalled Sketchup, download latest version and reinstalled but no luck

                  Thanks
                  rknmag

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

                    If you use this line of code in the Ruby Console what do you get?
                    tgroup=Sketchup.active_model.active_entities.add_group()
                    It should return a reference to a Group, something like:
                    #<Sketchup::Group:0x11379d24>
                    Then
                    tents=tgroup.entities
                    It should return something like:
                    #<Sketchup::Entities:0x112964ac>
                    Now try something like:
                    tents.add_cpoint([1,2,3])
                    It should now add things to the group ?
                    If it fails, then at which step??

                    TIG

                    1 Reply Last reply Reply Quote 0
                    • R Offline
                      rknmag
                      last edited by

                      Hi

                      I tried in Ruby console as suggested by you and it works without any issue. For that matter, If I have only this part of the code in a .rb file and load into Sketchup that also works. My problem comes up in my main program where some more rb files are loaded. Unfortunately those files are too many and inter-related, so now I am trying to separate them and load one by one to isolate the offending code.

                      1 Reply Last reply Reply Quote 0
                      • R Offline
                        rknmag
                        last edited by

                        Hi

                        This issue seems to be related to removing "Susan" definition. Please refer the following code, in this If I remove the code, which erases Susan, then the temp_group creation is success else it return ComponentInstance.
                        And also, I get this error only when I put this code in a rb file and put in "Plugin" directory , if I save the rb file in some other directory and load that file from Ruby console, I don't face this issue.

                        ` component_list = Sketchup.active_model.definitions
                        cm = component_list["Susan"]
                        if(cm != nil && cm.count_instances > 0)

                        If I comment out following line, it works

                        cm.instances.each { | entity | entity.erase! }
                        end
                        entity_list = Sketchup.active_model.entities
                        temp_group = entity_list.add_group
                        UI.messagebox("temp_group class: #{temp_group.class}\n")
                        temp_entity_list = temp_group.entities`

                        Thanks
                        rknmag

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

                          Why are you working with a template that includes 'Susan' in the first place ??
                          That template is just an example - make your own to suit your needs...
                          If this is anything like a reusable script it needs to work with ANY skp...
                          😒
                          Is this code inside at least a def xxx()...end method? [I'm not insisting on a module or a class... here]
                          If your script is loading just 'raw' code at startup it could well make a mess...

                          TIG

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

                            I second TIG's question why you're removing the Susan definition? Why is that essential for the plugin to work?

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

                            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