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

    Glued_to problem

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 3 Posters 318 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.
    • existmeE Offline
      existme
      last edited by

      I am developing a set of camera toolbox for Sketchup. I have separate mount models and camera models. I need to have a functionality to automatically attach camera models on mount models. I exactly align camera models to the surface of the mount and put it on the center of the face.

      Problem:
      I use the following code:

      camera_instance = Sketchup.active_model.entities.add_instance componentdefinition, t glueto_face = findPartByName(mount_comp, "GlueTo") # find the face to attach camera_instance.glued_to = gluedto_face

      But Sketchup raises an error that:
      Can only glue to something in the same component

      I know that it is possible to glue_to a face of another component because when I manually insert component from UI, the camera.glued_to is set to the instance of the mount. I wonder how to do it through Ruby.

      Any help would be appreciated.

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

        You can only glue an instance onto a face that is in the same context as the instance.
        Although you have not given all of, or clearly explained your code... here goes...

        glueto_face = findPartByName(mount_comp, "GlueTo")
        What does this findPartByName() method do ?
        mount_comp is not defined
        camera_instance is defined as the instance of the camera [ componentdefinition] which you have just added.
        You then seek to glue the camera_instance onto a face, that presumably was returned by your unexplained method...
        camera_instance.glued_to = gluedto_face

        The camera-component may well have internal instances but only an instance of the camera-component can be glued to a face that itself is in the same entities context as the instance.
        You cannot glue a camera-instance onto a mount-instance, the glued_to= requires a face and that face must be in the context as the instance.

        You need to rethink how you do this...
        You have the mount transformation and presumably details of its 'snap' point relative to its origin.
        So you can easily transform that point by snap_point.transform!(mount_comp.transformation). Now use that to locate the camera-instance in the [unspecified] 't' transformation...

        To make the camera-instance 'lock' onto the mount-instance you will need to give them matching unique ids as attributes [timestamps ?], then using convoluted observers watch for the mount being transformed and if so apply a making a matching transformation for the camera etc - this is likely to be pretty involved...

        Can you not have the camera and mount as a combined component [made unique] - or two parts put into a group in code - it will then mean the two then move/rotate as one, unless you work within their container and then transform the camera relative to the mount etc.

        TIG

        1 Reply Last reply Reply Quote 0
        • existmeE Offline
          existme
          last edited by

          @tig said:

          You can only glue an instance onto a face that is in the same context as the instance.
          Although you have not given all of, or clearly explained your code... here goes...

          Thanks a lot for your quick reply. I thought may be putting all the code here would be irrelevant as long as functional description is known. findPartByName seeks through a component which is made of other components to return an instance by name

          [pre:17k1x45e]def findPartByName(entity, name) res=nil if (entity.is_a? Sketchup::Group) return entity if(entity.name==name) entity.entities.each{|e| res = findPartByName(e,name);return res if res!=nil;} elsif (entity.is_a? Sketchup::ComponentInstance) return entity if(entity.name==name) entity.definition.entities.each{|e| res = findPartByName(e,name);return res if res!=nil;} end return res end[/pre:17k1x45e]

          I have turned the face into a group in the mount component so I can find it by name and I have double checked that it is the correct face. The transformations is a little bit complex but anyway it is correct. I mean the camera will be placed exactly on the face that I need to align to it. The only problem is that I need to glue them together. I know it is possible (maybe with some tricks) because when you place the camera manually on that face, it will be glued to it.

          I cannot make them a unique component because each of them has different property sheets and I don't want to force users to open the component and view the property sheet.
          I've attached some pictures maybe they help to understand the problem.

          http://s22.postimg.org/umt9oiwsx/cam_mount.jpg

          http://s22.postimg.org/oxd147qmp/cam_mount2.jpg

          /Reza

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

            Placing an instance of a component onto a face and 'gluing' it is accessible via the API.
            You can also manually place it onto a group or other instance and it will 'glue' onto that container, unfortunately it is NOT possible to glue this way via the API.

            You can easily place the instances in the correct relative relationships, but not glue one to the other.

            If the camera always rotates around its insertion point about its own vertical axis then you code simply needs to find those, which are easily got from its transformation.

            You could make a group of the initially [correctly placed] mount and camera instances, to effect a 'linking' as they are moved etc later, the rotation of the camera is informed by its own transformation so transforming it later relative to itself seems straightforward too...

            TIG

            1 Reply Last reply Reply Quote 0
            • existmeE Offline
              existme
              last edited by

              Thanks so much πŸ˜„ It's a pity that you cannot glue to other component's faces via API.

              1 Reply Last reply Reply Quote 0
              • tt_suT Offline
                tt_su
                last edited by

                @existme said:

                Thanks so much πŸ˜„ It's a pity that you cannot glue to other component's faces via API.

                Indeed. 😞

                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