こちらの続きです。
メッシュの六角形分割に挑む3 - C#ATIA
今日は順調に進んでます。
"大量に平面を作らなきゃだめだな" と思っていたのですが、
平面切断にはX方向のオフセットとYZ軸の回転があり、これを
利用すると一枚の平面だけ作れば良いこと気が付きました。
作るものを減らした方が処理が速くなりますからね。
前々回の平面切断を修正して、尚且つ複数の平面切断を処理出来るように
変更しました。
def meshPlaneCut_Numerical_MultiOffset( mesh: adsk.fusion.MeshBody, plane: adsk.fusion.ConstructionPlane, offsetList: list, rotateZ: float): for length in offsetList: meshPlaneCut_Numerical( mesh, plane, length, rotateZ ) adsk.doEvents() import math # offsetX: ユーザーが使用している長さの単位でOK # rotateZ: 単位は度(degree) def meshPlaneCut_Numerical( mesh: adsk.fusion.MeshBody, plane: adsk.fusion.ConstructionPlane, offsetX: float, rotateZ: float): app: adsk.core.Application = adsk.core.Application.get() des: adsk.fusion.Design = mesh.parentComponent.parentDesign unitsMgr: adsk.core.UnitsManager = des.unitsManager length = unitsMgr.convert( offsetX, unitsMgr.defaultLengthUnits, unitsMgr.internalUnits ) rad = math.radians(rotateZ) ui :adsk.core.UserInterface = app.userInterface sels :adsk.core.Selections = ui.activeSelections sels.clear() app.executeTextCommand(u'Commands.Start ParaMeshPlaneCutCommand') app.executeTextCommand(u'UI.EnableCommandInput infoBodyToModify') sels.add(mesh) app.executeTextCommand(u'UI.EnableCommandInput planeSelectionInfo') sels.add(plane) app.executeTextCommand(u'Commands.SetString infoCutType infoCutTypeSplitFaces') app.executeTextCommand(u'Commands.SetDouble RotateZ {}'.format(rad)) app.executeTextCommand(u'Commands.SetDouble AxisX {}' .format(length)) app.executeTextCommand(u'NuCommands.CommitCmd')
オフセットの長さの単位はFusion360で設定している単位で、
角度は "度" でOKにしています。その方が分かりやすいですから。
これをこんな感じで呼び出すと
for ang in [0,60,-60]: meshPlaneCut_Numerical_MultiOffset( meshs[0], root.yZConstructionPlane, range(-60,60,5), ang )
こんな感じになります。(左:実行前 右:実行後)
六角形が見えてきましたよ。