iCAx开思网

标题: Catia 的 VBA 问题 (新手问题) [打印本页]

作者: a_a_a_a    时间: 2005-5-28 15:29
标题: Catia 的 VBA 问题 (新手问题)
Sub CATMain()
  
     '==================================================================
     ' 1-Prolog
     '==================================================================
     '------------------------------------------------------------------
     ' 1.a-Declare required variables: command set, motion matrix
     '------------------------------------------------------------------
     Dim dValcmd(0 To 1)  'As  ' Double
     'Dim dMotion(11) As Double
  
     '------------------------------------------------------------------
     ' 1.b-Retrieve the root product
     '------------------------------------------------------------------
     Dim oRootProduct As AnyObject
     Set oRootProduct = CATIA.ActiveDocument.Product
  
     '------------------------------------------------------------------
     ' 1.c-Retrieve the Mechanisms as a TechnologicalObject of the Product
     '------------------------------------------------------------------
     Dim cTheMechanisms As AnyObject
     Set cTheMechanisms = oRootProduct.GetTechnologicalObject("Mechanisms")
  
     '------------------------------------------------------------------
     ' 1.d-Take 1st mechanism found, and first moving part
     '------------------------------------------------------------------
     Dim oFirstMechanism As Mechanism
     Set oFirstMechanism = cTheMechanisms.Item(1)
  
     '==================================================================
     ' 2-Retrieve number of moving parts, and first one
     '==================================================================
     Dim iNbProd As Integer
     iNbProd = oFirstMechanism.NbProducts
  
     Dim oMovingPart As Product
     oMovingPart = oFirstMechanism.GetProduct(1)
  
     '==================================================================
     ' 3-Retrieve current command values
     '==================================================================
     oFirstMechanism.GetCommandValues dValcmd()
  
     '==================================================================
     ' 4-Solve for other command values
     '==================================================================
     '------------------------------------------------------------------
     ' 4.a-Create another command set
     '------------------------------------------------------------------
     dValcmd(0) = dValcmd(0) + 10
  
     '------------------------------------------------------------------
     ' 4.b-Apply the command set
     '------------------------------------------------------------------
     oFirstMechanism.PutCommandValues dValcmd
  
     '==================================================================
     ' 5-Retrieve motion for a part after solving and apply it
     '==================================================================
     '------------------------------------------------------------------
     ' 5.a-Retrieve motion for a part after solving
     '------------------------------------------------------------------
     oFirstMechanism.GetProductMotion oMovingPart, dMotion
     '------------------------------------------------------------------
     ' 5.b-Apply the motion to the part
     '------------------------------------------------------------------
     oMovingPart.Move.Apply dMotion
  
End Sub
  
以上程序为Catia自带程序,可是在运行时,程序停在:oFirstMechanism.GetCommandValues dValcmd()
中的GetCommandValues处,并提示:编译错误:函数或接口标记为限制的,或函数使用了Visual Basic不支持的自动化(Automation)类型。
  
请问各位高手,你们如何处理这个问题?
多谢!!!1
作者: a_a_a_a    时间: 2005-5-29 18:43
没人做开发吗?
作者: mei8686    时间: 2005-5-30 10:33
你是用宏录的程序吗.最好说一下你用在什么地方的.哪一个模块
作者: a_a_a_a    时间: 2005-5-30 11:30
'COPYRIGHT DASSAULT SYSTEMES 2000-2001
Option Explicit
Dim Language as String
Language="VBSCRIPT"
  
'*****************************************************************************
' Purpose:      This macro calls the kinematics solver  
'               and applies the computed motion to a  
'               part of the mechanism
'               in a specific product document
' Assumptions:  The product document used as input is result of the  
'               CAAKiiMechanismCreation use case
' Author:        
' Languages:    VBScript
' Version:      V5R6
' Locales:      US English
'*****************************************************************************
  
Sub CATMain()
  
    '==================================================================
    ' 1-Prolog
    '==================================================================
    '------------------------------------------------------------------
    ' 1.a-Declare required variables: command set, motion matrix
    '------------------------------------------------------------------
    Dim dValcmd(1) As Double
    Dim dMotion(11) As Double
  
    '------------------------------------------------------------------
    ' 1.b-Retrieve the root product
    '------------------------------------------------------------------
    Dim oRootProduct As AnyObject
    Set oRootProduct = CATIA.ActiveDocument.Product
  
    '------------------------------------------------------------------
    ' 1.c-Retrieve the Mechanisms as a TechnologicalObject of the Product
    '------------------------------------------------------------------
    Dim cTheMechanisms As AnyObject
    Set cTheMechanisms = oRootProduct.GetTechnologicalObject("Mechanisms")
  
    '------------------------------------------------------------------
    ' 1.d-Take 1st mechanism found, and first moving part
    '------------------------------------------------------------------
    Dim oFirstMechanism As Mechanism
    Set oFirstMechanism = cTheMechanisms.Item(1)
  
    '==================================================================
    ' 2-Retrieve number of moving parts, and first one
    '==================================================================
    Dim iNbProd As Integer
    iNbProd = oFirstMechanism.NbProducts
  
    Dim oMovingPart as Product
    oMovingPart = oFirstMechanism.GetProduct(1)
  
    '==================================================================
    ' 3-Retrieve current command values
    '==================================================================
    oFirstMechanism.GetCommandValues dValcmd
  
    '==================================================================
    ' 4-Solve for other command values
    '==================================================================
    '------------------------------------------------------------------
    ' 4.a-Create another command set
    '------------------------------------------------------------------
    dValcmd(0) = dValcmd(0) + 10
  
    '------------------------------------------------------------------
    ' 4.b-Apply the command set  
    '------------------------------------------------------------------
    oFirstMechanism.PutCommandValues dValcmd
  
    '==================================================================
    ' 5-Retrieve motion for a part after solving and apply it
    '==================================================================
    '------------------------------------------------------------------
    ' 5.a-Retrieve motion for a part after solving
    '------------------------------------------------------------------
    oFirstMechanism.GetProductMotion oMovingPart,dMotion
    '------------------------------------------------------------------
    ' 5.b-Apply the motion to the part  
    '------------------------------------------------------------------
    oMovingPart.Move.Apply dMotion
  
End Sub
  
这是一个Catia帮助中带的一个程序。
  
以上程序应该是VBScript的所以不能在VBA中运行。
  
而且我刚才比较了一下,帮助中几乎所有的程序都是VBScript的。真不明白,放着VBa不用却用VBScript(调试会很不方便),大侠们用什么编程?
Caa?
VBA?
VBScript?(能说说你用的什么编辑工具吗?)
作者: whofullwin    时间: 2009-10-16 11:46
我也遇到了这个问题,请高手指点
作者: whofullwin    时间: 2009-10-16 17:12
GetCommandValues可以通过,PutCommandValues去不行,不知道什么原因,请高手指教!!!!!!!!!1




欢迎光临 iCAx开思网 (https://www.icax.org/) Powered by Discuz! X3.3