python的CATIA宏 [英] CATIA macro from python

查看:214
本文介绍了python的CATIA宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用我的宏(.CATScript)打开catia界面,并将宏脚本中列出的更改更改为.CATpart,然后将输出作为.stp文件提供.是否可以使用python实现此功能?

I would like to use my macro (.CATScript) to open the catia interface and make the changes listed in the macro script to the .CATpart and give output as .stp file. Is it possible to use python to realise this function?

>使用Python脚本运行Catia宏中有一个示例,但在我的情况下不起作用.我按如下所示编辑了代码,然后运行了它.

There was an example in Run a Catia macro with a python script, but it didn't work in my case. I edited the code as below and gave it a run.

import win32com.client
catapp = win32com.client.Dispatch("CATIA.Application")
catapp.StartCommand('Macro_schweller_model_lsopt.CATScript')

我的错误是

File "C:\FK-Programme\python36-32\Anaconda\Install\lib\site-packages\win32com\client\dynamic.py", line 91, in _GetGoodDispatch
    IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)

com_error: (-2147221005, 'Ungültige Klassenzeichenfolge', None, None)

我的.CATscript看起来像这样

My .CATscript looks like this

Sub CATMain()

    Dim FileToOpen as String
    Dim partDocument1 As Document
    Dim part1 As Part
    Dim AnglePara As Parameter
    Dim parameters1 As Parameters
    Dim AmplitudePara As Parameter
    Dim WavelengthPara As Parameter

    FileToOpen = "E:\Datei\Results\Optimization\LS_OPT_results\Optimization_model_1\Schweller_fully_corrugated.CATPart"

    Set partDocument1 = CATIA.Documents.Open(FileToOpen)

    Set part1 = partDocument1.Part

    Set parameters1 = part1.Parameters

    Set AnglePara = parameters1.RootParameterSet.DirectParameters.Item("Angle")

    AnglePara.Value = -7

    Set AmplitudePara = parameters1.RootParameterSet.DirectParameters.Item("Amplitude")

    AmplitudePara.Value = 30

    Set WavelengthPara = parameters1.RootParameterSet.DirectParameters.Item("Wavelength")

    WavelengthPara.Value = 30

    CATIA.DisplayFileAlerts = False

    partDocument1.Part.Update

    partDocument1.ExportData "E:\Datei\Results\Optimization\LS_OPT_results\Optimization_model_1\Schweller.stp", "stp" 


End Sub 

推荐答案

StartCommand方法只能(据我所知)只能启动分配给工具栏按钮的宏.我建议您改为使用SystemService.ExecuteScript方法,该方法允许您直接运行脚本.然后,您的示例将被修改为如下所示:

The StartCommand method can (as far as I know) only start macros assigned to toolbar buttons. I advise you to instead use the SystemService.ExecuteScript method, which allows you to run the script directly. Your example would then be modified to look something like this:

import win32com.client
catapp = win32com.client.Dispatch("CATIA.Application")
catapp.SystemService.ExecuteScript(
    # Macro library name/path
    r"C:\Path\To\Directory\Containing\The\Script",
    # Type of macro library (document/directory/VBA project)
    1,  # directory
    # Macro name
    "Macro_schweller_model_lsopt.CATScript",
    # Function name
    "CATMain",
    # Arguments
    tuple(),
)

有关SystemService.ExecuteScript方法的更多信息,请访问 http://catiadoc.free.fr/online/interfaces/interface_SystemService.htm#ExecuteScript .

More information on the SystemService.ExecuteScript method is available at http://catiadoc.free.fr/online/interfaces/interface_SystemService.htm#ExecuteScript.

这篇关于python的CATIA宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆