@@ -24,6 +24,9 @@ def createGridfinityBaseplate(input: BaseplateGeneratorInput, targetComponent: a
2424 0
2525 )
2626
27+ connectionHoleYTool = None
28+ connectionHoleXTool = None
29+
2730 if input .hasSkeletonizedBottom :
2831 centerCutoutSketch = baseGenerator .createCircleAtPointSketch (
2932 faceUtils .getBottomFace (baseBody ),
@@ -108,42 +111,11 @@ def createGridfinityBaseplate(input: BaseplateGeneratorInput, targetComponent: a
108111 targetComponent ,
109112 )
110113 extraCutoutBodies .append (centerCutoutBody )
111-
112114 if input .hasConnectionHoles :
113- connectionHoleFace = min ([face for face in centerCutoutBody .faces if faceUtils .isYNormal (face )], key = lambda x : x .boundingBox .minPoint .y )
114- connectionHoleSketch : adsk .fusion .Sketch = targetComponent .sketches .add (connectionHoleFace )
115- connectionHoleSketch .name = "side connector hole"
116- sketchCurves = connectionHoleSketch .sketchCurves
117- dimensions = connectionHoleSketch .sketchDimensions
118- constraints = connectionHoleSketch .geometricConstraints
119- sketchUtils .convertToConstruction (sketchCurves )
120- [sketchHorizontalEdge1 , sketchHorizontalEdge2 ] = [line for line in sketchCurves .sketchLines if sketchUtils .isHorizontal (line )]
121- line1 = sketchCurves .sketchLines .addByTwoPoints (sketchHorizontalEdge1 .startSketchPoint .geometry , sketchHorizontalEdge2 .endSketchPoint .geometry )
122- line1 .isConstruction = True
123- constraints .addMidPoint (line1 .startSketchPoint , sketchHorizontalEdge1 )
124- constraints .addMidPoint (line1 .endSketchPoint , sketchHorizontalEdge2 )
125-
126- circle = sketchCurves .sketchCircles .addByCenterRadius (
127- connectionHoleSketch .originPoint .geometry ,
128- input .connectionScrewHolesDiameter / 2
129- )
130- constraints .addMidPoint (circle .centerSketchPoint , line1 )
131- dimensions .addRadialDimension (circle , line1 .startSketchPoint .geometry , True )
132- connectionHoleTool = extrudeUtils .simpleDistanceExtrude (
133- connectionHoleSketch .profiles .item (0 ),
134- adsk .fusion .FeatureOperations .NewBodyFeatureOperation ,
135- input .baseWidth / 2 ,
136- adsk .fusion .ExtentDirections .PositiveExtentDirection ,
137- [],
138- targetComponent ,
139- )
140- connectionHolePattern = patternUtils .circPattern (
141- commonUtils .objectCollectionFromList (connectionHoleTool .bodies ),
142- constructionAxis ,
143- 4 ,
144- targetComponent ,
145- )
146- extraCutoutBodies = extraCutoutBodies + list (connectionHoleTool .bodies ) + list (connectionHolePattern .bodies )
115+ connectionHoleFaceY = min ([face for face in centerCutoutBody .faces if faceUtils .isYNormal (face )], key = lambda x : x .boundingBox .minPoint .y )
116+ connectionHoleYTool = createConnectionHoleTool (connectionHoleFaceY , input .connectionScrewHolesDiameter / 2 , input .baseWidth / 2 , targetComponent )
117+ connectionHoleFaceX = min ([face for face in centerCutoutBody .faces if faceUtils .isXNormal (face )], key = lambda x : x .boundingBox .minPoint .x )
118+ connectionHoleXTool = createConnectionHoleTool (connectionHoleFaceX , input .connectionScrewHolesDiameter / 2 , input .baseWidth / 2 , targetComponent )
147119
148120 holeCuttingBodies : list [adsk .fusion .BRepBody ] = []
149121
@@ -272,6 +244,44 @@ def createGridfinityBaseplate(input: BaseplateGeneratorInput, targetComponent: a
272244 )
273245 bottomChamfer .name = "bottom shamfer"
274246
247+ if not connectionHoleYTool is None and not connectionHoleXTool is None :
248+ holeToolsXFeature = patternUtils .recPattern (
249+ commonUtils .objectCollectionFromList (connectionHoleXTool .bodies ),
250+ (targetComponent .xConstructionAxis , targetComponent .yConstructionAxis ),
251+ (input .baseWidth , input .baseLength ),
252+ (1 , input .baseplateLength ),
253+ targetComponent
254+ )
255+ connectionHoleXToolList = list (connectionHoleXTool .bodies ) + list (holeToolsXFeature .bodies )
256+
257+ holeToolsYFeature = patternUtils .recPattern (
258+ commonUtils .objectCollectionFromList (connectionHoleYTool .bodies ),
259+ (targetComponent .xConstructionAxis , targetComponent .yConstructionAxis ),
260+ (input .baseWidth , input .baseLength ),
261+ (input .baseplateWidth , 1 ),
262+ targetComponent
263+ )
264+ connectionHoleYToolList = list (connectionHoleYTool .bodies ) + list (holeToolsYFeature .bodies )
265+
266+ constructionPlaneXZInput : adsk .fusion .ConstructionPlaneInput = targetComponent .constructionPlanes .createInput ()
267+ constructionPlaneXZInput .setByOffset (targetComponent .xZConstructionPlane , adsk .core .ValueInput .createByReal (input .baseplateLength * input .baseLength / 2 - input .xyTolerance ))
268+ constructionPlaneXZ = targetComponent .constructionPlanes .add (constructionPlaneXZInput )
269+ constructionPlaneXZ .isLightBulbOn = False
270+
271+ constructionPlaneYZInput : adsk .fusion .ConstructionPlaneInput = targetComponent .constructionPlanes .createInput ()
272+ constructionPlaneYZInput .setByOffset (targetComponent .yZConstructionPlane , adsk .core .ValueInput .createByReal (input .baseplateWidth * input .baseWidth / 2 - input .xyTolerance ))
273+ constructionPlaneYZ = targetComponent .constructionPlanes .add (constructionPlaneYZInput )
274+ constructionPlaneYZ .isLightBulbOn = False
275+
276+ mirrorConnectionHolesYZInput = features .mirrorFeatures .createInput (commonUtils .objectCollectionFromList (connectionHoleXToolList ), constructionPlaneYZ )
277+ mirrorConnectionHolesYZ = features .mirrorFeatures .add (mirrorConnectionHolesYZInput )
278+
279+ mirrorConnectionHolesXZInput = features .mirrorFeatures .createInput (commonUtils .objectCollectionFromList (connectionHoleYToolList ), constructionPlaneXZ )
280+ mirrorConnectionHolesXZ = features .mirrorFeatures .add (mirrorConnectionHolesXZInput )
281+
282+ cuttingTools = cuttingTools + list (mirrorConnectionHolesYZ .bodies ) + list (mirrorConnectionHolesXZ .bodies ) + connectionHoleYToolList + connectionHoleXToolList
283+
284+
275285 # cut everything
276286 toolBodies = commonUtils .objectCollectionFromList (cuttingTools )
277287 finalCut = combineUtils .cutBody (
@@ -282,3 +292,32 @@ def createGridfinityBaseplate(input: BaseplateGeneratorInput, targetComponent: a
282292 finalCut .name = "final baseplate cut"
283293
284294 return binInterfaceBody
295+
296+ def createConnectionHoleTool (connectionHoleFace : adsk .fusion .BRepFace , diameter : float , depth : float , targetComponent : adsk .fusion .Component ):
297+ connectionHoleSketch : adsk .fusion .Sketch = targetComponent .sketches .add (connectionHoleFace )
298+ connectionHoleSketch .name = "side connector hole"
299+ sketchCurves = connectionHoleSketch .sketchCurves
300+ dimensions = connectionHoleSketch .sketchDimensions
301+ constraints = connectionHoleSketch .geometricConstraints
302+ sketchUtils .convertToConstruction (sketchCurves )
303+ [sketchHorizontalEdge1 , sketchHorizontalEdge2 ] = [line for line in sketchCurves .sketchLines if sketchUtils .isHorizontal (line )]
304+ line1 = sketchCurves .sketchLines .addByTwoPoints (sketchHorizontalEdge1 .startSketchPoint .geometry , sketchHorizontalEdge2 .endSketchPoint .geometry )
305+ line1 .isConstruction = True
306+ constraints .addMidPoint (line1 .startSketchPoint , sketchHorizontalEdge1 )
307+ constraints .addMidPoint (line1 .endSketchPoint , sketchHorizontalEdge2 )
308+
309+ circle = sketchCurves .sketchCircles .addByCenterRadius (
310+ connectionHoleSketch .originPoint .geometry ,
311+ diameter
312+ )
313+ constraints .addMidPoint (circle .centerSketchPoint , line1 )
314+ dimensions .addRadialDimension (circle , line1 .startSketchPoint .geometry , True )
315+ connectionHoleTool = extrudeUtils .simpleDistanceExtrude (
316+ connectionHoleSketch .profiles .item (0 ),
317+ adsk .fusion .FeatureOperations .NewBodyFeatureOperation ,
318+ depth ,
319+ adsk .fusion .ExtentDirections .PositiveExtentDirection ,
320+ [],
321+ targetComponent ,
322+ )
323+ return connectionHoleTool
0 commit comments