こちらの続きです。
pycatiaを味わう4 - C#ATIA
折角なので、既存のVBAマクロをpython化します。
CATIA_V5_SimpleMacroMenu/sample/sample_Draft_View_Lock_UnLock.bas at master · kantoku-code/CATIA_V5_SimpleMacroMenu · GitHub
# pycatia Draft_View_Lock_UnLock # https://github.com/kantoku-code/CATIA_V5_SimpleMacroMenu/blob/master/sample/sample_Draft_View_Lock_UnLock.bas import traceback import os import sys import pathlib sys.path.insert(0, os.path.abspath("..\\pycatia")) from pycatia import catia from pycatia.drafting_interfaces.drawing_document import DrawingDocument from pycatia.drafting_interfaces.drawing_views import DrawingViews from pycatia.drafting_interfaces.drawing_view import DrawingView SUFFIX_DOCUMENT_TYPE_MAP = { ".CATProduct": "ProductDocument", ".CATPart": "PartDocument", ".CATDrawing": "DrawingDocument", } def main() -> None: if not can_execute("DrawingDocument"): return caa = catia() try: drawDoc: DrawingDocument = DrawingDocument( caa.active_document.com_object ) views: DrawingViews = DrawingViews( drawDoc.sheets.active_sheet.views.com_object ) if views.count < 3: return view: DrawingView = DrawingView( views.item(3).com_object ) lockStatus: bool = view.lock_status msg = "アンロック" if lockStatus else "ロック" lockStatus = not lockStatus for idx in range(3, views.count + 1): view = DrawingView( views.item(idx).com_object ) view.lock_status = lockStatus caa.refresh_display = True caa.message_box(f"全てのビューを{msg}しました") except: caa.message_box( f"エラー:\n{traceback.format_exc()}" ) def can_execute(documentTypes) -> bool: ''' アクティブなドキュメントが実行可能なタイプか? ''' if not type(documentTypes) == list: documentTypes = [documentTypes] caa = catia() doc = caa.active_document docType = SUFFIX_DOCUMENT_TYPE_MAP[ pathlib.Path(doc.full_name).suffix ] res = docType in documentTypes if not res: msgLst = [ "ファイルのタイプが異なります。" , f"{documentTypes}", " のみです", ] caa.message_box("\n".join(msgLst)) return res main()
ちょっと時間が無いので、解説は次回に。