Snapto or glueto with 2 faces
-
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
-
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.
-
The
snapto=
behavior simply determines the kind[s] of face that the instance will snap-to - sodefn.snapto=SnapTo_Arbitrary
will snap an instance onto all face.
The methodinstance.glue_to=
is used to determine the face the instance will glue onto.
Theinstance.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. -
All right thank you thomthom, I've feared it Lets see if I can handle this
-
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
-
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... -
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...
-
You need a
snapto
behavior defining...
inst1.definition.behavior.snapto=SnapTo_Arbitrary
as well as the 'is2d' behavior...
Theglue_to
is NOT abehavior
of a definition!
It is a property/method of the instance - so use
inst1.glue_to=snaptoface2
-
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_pathCreate 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` -
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...
Advertisement