I tried to use the jointTenon (and i had to change the code a bit so that tenon height and width are a bit different for my case).
I found the tenons to be not as robust as they could be. I think it would be better to use placement/Support for tenons.
for o in selection:
objRef = MagicPanels.getReference(selection[i])
subs = FreeCADGui.Selection.getSelectionEx()[i].SubObjects
i = i + 1
for objFace in subs:
vertexes = objFace.Vertexes
vertexNames = []
for vtx in vertexes:
for idx, v2 in enumerate(objRef.Shape.Vertexes):
if vtx.isSame(v2):
vertexNames.append(f'Vertex{idx + 1}')
[ faceType, eAll, eThick, eShort, eLong ] = MagicPanels.getFaceEdges(objRef, objFace)
if len(eLong) > 0:
edge = eLong[0]
elif len(eShort) > 0:
edge = eShort[0]
elif len(eThick) > 0:
edge = eThick[0]
sizes = MagicPanels.getSizes(objRef)
sizes.sort()
thick = sizes[0]
jointSize = thick / 3 ## tenon width is 1/3 of the width of the shape
jointHeight = 30
size = edge.Length - (7) * 2 ## i use 7mm for the tenon offset
Length = size
Width = jointSize
Height = jointHeight
oo, ox, oy, of = vertexes[0], vertexes[2], vertexes[1], vertexes[3]
no, nx, ny, nf = vertexNames[0], vertexNames[2], vertexNames[1], vertexNames[3]
z_axis_relative = ox.Point.sub(oo.Point).cross(oy.Point.sub(oo.Point))
com_relative = objRef.Shape.CenterOfMass.sub(oo.Point)
if (z_axis_relative.dot(com_relative) > 0):
oo, ox, oy, of = of, ox, oy, oo ## the tenon would overlap with the object, so we need to point at the other side
no, nx, ny, nf = nf, nx, ny, no
joint = FreeCAD.ActiveDocument.addObject("Part::Box","tenon")
if oo.distToShape(ox)[0] == edge.Length:
print("case1")
joint.Width, joint.Height, joint.Length = jointSize, jointHeight, size
joint.AttachmentOffset.Base = (7, jointSize, 0)
else:
print(f"case2 {oo.distToShape(ox)[0]} {edge.Length}")
joint.Length, joint.Height, joint.Width = jointSize, jointHeight, size
joint.AttachmentOffset.Base = (jointSize, 7, 0)
joint.Support = [(objRef, (no, nx, ny))]
joint.MapMode = 'OXY'
#MagicPanels.setContainerPlacement(joint, x, y, z, 0, "center")
MagicPanels.moveToFirst([ joint ], objRef)
i don't know if this would work perfectly in all cases, but at least for me it results in more robust tenons that are easier to tweak afterwards, and that move together with the panel on which they were made