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

    Snapto or glueto with 2 faces

    Scheduled Pinned Locked Moved Developers' Forum
    10 Posts 3 Posters 288 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.
    • R Offline
      Robin1991
      last edited by

      Hey to everyone! πŸ˜•

      I hope someone is able to help me with my problem.

      I coded two components. These colored faces are the areas which snap the components with each other by moving the right one in the near of the left.

      Is it possible to snap these two faces with "snapto"behavior?
      Should I prefer "glueto"?
      What are you thinking about any other codes?

      Glad to her any answers! πŸ˜„

      greetings, Rob πŸ€“


      problem.jpg

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

        If you want to strictly limit just those two faces to snap to each other you need to make a custom tool. If you rely on the standard behaviour of component's Glue To they will stick to anything.

        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

          The snapto= behavior simply determines the kind[s] of face that the instance will snap-to - so defn.snapto=SnapTo_Arbitrary will snap an instance onto all face.
          The method instance.glue_to= is used to determine the face the instance will glue onto.
          The instance.definition.behavior has to support snapto/is2d=true/etc already before the gluing will work and the axis must have the blue/z perpendicularly out of the face it's gluing onto.

          TIG

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

            All right thank you thomthom, I've feared it πŸ˜† Lets see if I can handle this 😳 πŸ˜„

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

              Thanks TIG for your answer!

              So glue_to would be the answer when I code:

              
              instance.definition.behavior.is2d=true
              instance.glue_to=left_face
              
              

              like this?

              I'm new to this stuff so please excuse any folish code examples πŸ‘Š

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

                Try it and see... what's the worst that can happen πŸ˜•
                Should be OK...
                BUT you must have located the glued instance on the glued face before .glue_to= otherwise weirdness ensues...

                TIG

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

                  So I used this code to access my component "gelander" and I want it to be snapped against snaptoface2.
                  I coded the instance and defined its behavior.

                  # Load the component definition
                  model = Sketchup.active_model
                  def_list = model.definitions
                  def_path = Sketchup.find_support_file "gelander.skp", "Components/"
                  comp_def = def_list.load def_path
                  # Create the component instances
                  ents = model.entities
                  inst1 = ents.add_instance comp_def, [0, 0, 0]
                  #..just to look if instance is already active
                  inst1.definition.set_attribute('dynamic_attributes','weight',0)
                  inst1.definition.set_attribute('dynamic_attributes','position','')
                  
                  #defining snaptoface
                  snaptoface2=ents.add_face [0.099.m,0.15.m,1.65.m],[0.099.m,0.65.m,1.65.m],[0.099.m,0.65.m,1.7.m],[0.099.m,0.15.m,1.7.m]
                  snaptoface2.material =[128, 0, 128] 
                   
                  inst1.definition.behavior.is2d=true
                  inst1.definition.behavior.glue_to=snaptoface2 
                  

                  When I comment out the last line is2d is set to true but when I try to access glue_to-function it reports "Run aborted".

                  Again sorry if I messed up this whole code, I'm working on it since a month or less... 😳

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

                    You need a snapto behavior defining...
                    inst1.definition.behavior.snapto=SnapTo_Arbitrary
                    as well as the 'is2d' behavior...
                    The glue_to is NOT a behavior of a definition!
                    It is a property/method of the instance - so use
                    inst1.glue_to=snaptoface2
                    πŸ˜’

                    TIG

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

                      sorry for this...whops 😞

                      I changed the code but it still recalls an error...

                      ` # Load the component definition
                      model = Sketchup.active_model
                      def_list = model.definitions
                      def_path = Sketchup.find_support_file "gelander.skp", "Components/Pfisterer"
                      comp_def = def_list.load def_path

                      Create the component instances

                      ents = model.entities
                      inst1 = ents.add_instance comp_def, [0, 0, 0]

                      inst1.definition.set_attribute('dynamic_attributes','weight',0)
                      inst1.definition.set_attribute('dynamic_attributes','position','')

                      snaptoface2=ents.add_face [0.01.m,0.15.m,1.65.m],[0.01.m,0.65.m,1.65.m],[0.01.m,0.65.m,1.7.m],[0.01.m,0.15.m,1.7.m]
                      snaptoface2.material =[128, 0, 128]

                      inst1.definition.behavior.is2d=true
                      inst1.glue_to=snaptoface2`

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

                        Robin

                        Please reread my post you have to set the definition's is2d= AND its snapto=... and then the instance's glue_to= ...

                        If you are loading a premade component ten why not give that the correct behaviors so you needed worry about reinventing them each time? and then you just need to place the component onto the face and tell it to glue_to it!
                        You should add the instance with a transformation, OR Geom::Transformation.new() and then later transform it so that it's located on the face to which you want to glue it - it's z-axis needs to be parallel to the face.normal and it's origin somewhere on the face...
                        It will not magically 'jump' onto the face - you need to code that. There after it will stick onto the face's plane like any other glued component, and move with the face too...

                        TIG

                        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