こちらの続きです。
ボディをかき集める - C#ATIA
Lineグループでお話が出ていたので少々・・・
機能的にはほぼ変わらないのですが、前回はまだまだpythonの知識もFusionAPIの知識も
今より少なかったので、ちょっと書き直しました。
#FusionAPI_python #Author-kantoku #Description-Collect_All_Body #アクティブなプロダクトの全てのボディをルートにかき集める import traceback import adsk.core as core import adsk.fusion as fusion def run(context): ui: core.UserInterface = None try: app: core.Application = core.Application.get() ui = app.userInterface des: fusion.Design = app.activeProduct root: fusion.Component = des.rootComponent #確認 msg: str = '全てのボディをルートコンポーネントにかき集めます。\nよろしいですか?' title: str = 'ボディかき集め' Res: int = ui.messageBox( msg, title, core.MessageBoxButtonTypes.OKCancelButtonType, core.MessageBoxIconTypes.QuestionIconType ) if Res != core.DialogResults.DialogOK: return # パラメトリックじゃないとNG backupDesignType: int = des.designType if backupDesignType == fusion.DesignTypes.DirectDesignType: des.designType = fusion.DesignTypes.ParametricDesignType # コンポーネントの全てのボディ bodies: list[fusion.BRepBody] = [] [bodies.extend(list(occ.bRepBodies)) for occ in root.allOccurrences] # カット&ペースト [root.features.cutPasteBodies.add(b) for b in bodies] # モードを戻す des.designType = backupDesignType # おしまい ui.messageBox('Done') except: if ui: ui.messageBox('エラー\n{}'.format(traceback.format_exc()))
前回のものを見ていると若干遠回りな書き方をしているなぁ と思い直すと
かなり短いコードになりました。
前回は無条件でパラメトリックモードで終了していますが、今回はダイレクトモードで
実行してもダイレクトモードで終わるようにしています。