iCAx开思网

标题: CAA问题 [打印本页]

作者: xinghesnak    时间: 2006-2-9 14:20
标题: CAA问题
我用ExecuteScript运行CATVba程序,可是调试总过不去。。。大哥们帮忙!
***************************************
#include "TestCmd.h"
#include "CATIndicationAgent.h"
#include "CATMathPlane.h"
#include "CATScriptUtilities.h"
#include "CATCreateExternalObject.h"
#include "CatScriptLibraryType.h"
#include "CATVariant.h"

CATCreateClass(TestCmd);
CATUnicodeString  functionName("CATMain");
CATUnicodeString& iFunctionName=functionName;
CATVariant  var;  

TestCmd::TestCmd() :
  CATStateCommand ("TestCmd", CATDlgEngOneShot, CATCommandModeExclusive)
  ,_Indication(NULL)
{
    CATScriptUtilities::ExecuteScript("C:\\Documents and Settings\\liguangyi\\Local Settings\\Temp\\VBAProject1.catvba", catScriptLibraryTypeVBAProject, "模块1", var, iFunctionName, NULL, 0,TRUE);   
}
*****************************************************************

报错如下:

.......

## start step: link2nd   at 02/09/2006-14:02:37
# make: ASSET\CmdModule.m intel_a\code\bin\CmdModule.dll
TestCmd.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static long __stdcall CATScriptUtilities::ExecuteScript(class CATUnicodeString const &,enum CatScriptLibraryType,class CATUnicodeString const &,struct tagVARIANT &,class CATUnicodeString const &,struct tagVARIANT *,unsigned int,unsigned char)" (__imp_?ExecuteScript@CATScriptUtilities@@SGJABVCATUnicodeString@@W4CatScriptLibraryType@@0AAUtagVARIANT@@0PAU4@IE@Z)
D:\WORK\CATIA-VC++\workspace2\.\intel_a\code\bin\CmdModule.dll : fatal error LNK1120: 1 unresolved externals
# make-ERROR: intel_a\code\bin\CmdModule.dll
## end   step: link2nd   at 02/09/2006-14:02:38

## start step: dummynls   at 02/09/2006-14:02:38
## end   step: dummynls   at 02/09/2006-14:02:38

== Command done, return code = 0


     小弟觉得参数1和参数3有问题,可是论坛里没有这方面的帖子,相关的也只是引用script程序,不是引用CATVba程序,初学不会,见笑了。望高手们明示.....
作者: saeba    时间: 2006-2-9 14:50
Nothing to do with the parameters. It is only a link error.

You have to insert the right module name in your make file. (mkmake?).
作者: xinghesnak    时间: 2006-2-9 17:01
我的VBA模块名就叫"模块1"啊?没有错误。。。另外seaba兄的英语真好哈^_^
作者: silvia    时间: 2006-2-10 11:28
如果你觉得参数1和参数3有问题
那么就加
CATUnicodeString.h+强制cast
试试看be
作者: xinghesnak    时间: 2006-2-10 13:35
还是不行啊。。。。
作者: saeba    时间: 2006-2-10 17:12
Sorry i don't have Chinese IME installed so I can only type alphabets...

-_-...     I mean there is nothing to do with your source.
You error is a link error, say, the linker can not find the good object to link the symbol "ExecuteScript@CATScriptUtilities...".
So you have to tell the linker where to find it.

To do this, you have to add the module name which contains the symbol "ExecuteScript@CATScriptUtilities..." in your makefile (NOT the cpp file!).
(nothing to do with your VBA模块名!!!)
There is a file in the same directory (named src?) of your cpp files which has a name like ***.mkmake or something.
You have to edit this file.

So what to add? You can place your mouse pointer on the word CATScriptUtilities and press Ctrl+F1 so a help window will appear, and in the bottom of the page, there should be the module name.

Sorry I don't have CAA any longer so can't help you more but you can ask anyone who knows how to edit a makefile.

[ 本帖最后由 saeba 于 2006-2-10 17:14 编辑 ]
作者: zzzrrr    时间: 2006-2-10 21:32
应确保每一个caa头文件所需要的module都包含在imakefile.mk文件中。
作者: xinghesnak    时间: 2006-2-11 10:19
说一句,saeba兄,你没有装输入法?你在国外啊?不过,多谢你的建议,我已经调试成功了。我的参数设置没有问题,就是在Imakefile.mk中应该增加moule名,而且在IdentityCard.h中应该增加CODE,谢啦!同时也多谢zzzrrr兄!
作者: DarkNeo    时间: 2006-2-13 10:21
看论坛学英语,好!哪天我的英语也这么好就好了
作者: xinghesnak    时间: 2006-2-14 11:21
大哥们,又遇到问题了,我的VBA程序里含有Selection.SelectElement2 的语句,我看CAA帮助说需要用 CATApplication.Subscribe 来返回第一个参数值,可是小弟不会用啊,哪位大哥会用CATApplication.Subscribe语句?
作者: xinghesnak    时间: 2006-2-14 11:42
CATApplication.Subscribe用法如下:

o Subscribe
public int Subscribe( int                     iSubscribingType,
                               CATCommand*  iToClient,
                               void*                  iClientData,
                              void(*)()              UserStaticMethod)  

                Adds a transaction/idle subscription to a command.
Parameters:
iSubscribingType
               The subscribing type.
                Legal values: Can be set to CATSubscribeEndTransaction (=1) or to CATSubscribeIdle (=2)
iToClient
               The command to call with its UserStaticMethod
iClientData
               Data useful to UserStaticMethod
UserStaticMethod
              The method to call when the state defined by iSubscribingType is reached.
Returns:
              0 if the transaction/idle subscription is successfully added and 0 otherwise

我主要不知道那几个参数都写什么,返回值是哪个啊?

[ 本帖最后由 xinghesnak 于 2006-2-14 11:48 编辑 ]
作者: xinghesnak    时间: 2006-2-15 08:40
小弟发现不光selection.selectelement2报错,selectelement和selectelement3也同样报错,好像是只要是在VBA中交互式操作,用CAA调用就会报错......高手们帮忙啊!
作者: xinghesnak    时间: 2006-2-15 13:48
顶顶......^_^
作者: xinghesnak    时间: 2006-2-16 08:05
雄起!雄起!
作者: hick    时间: 2006-2-16 09:25
帮你顶顶,手头没环境

看看callback
作者: xinghesnak    时间: 2006-2-17 15:41
callback是什么东东?^_^
作者: xinghesnak    时间: 2006-2-20 08:03
还是要顶,真的没有人会吗?
作者: saeba    时间: 2006-2-21 14:39
public int Subscribe( int                     iSubscribingType,
                               CATCommand*  iToClient,
                               void*                  iClientData,
                              void(*)()              UserStaticMethod)  

iSubscribingType: 1 or 2, you can try both
iToClient: pointer to your(?) command
iClientData: Do you want to pass some data to your command? if no, set it NULL; yes? pointer to your data.
UserStaticMethod: pointer to a method of your command which must be "static", this will be used as a callback. (so if some event happens, system will call this method, this is called "callback")

However I don't think you REALLY want to use this.
Better paste you VBA code and mark where the error occurs, and the error messsages.
So someone familiar with VBA could help you.

I don't think anybody here ever have chance to use this CATApplication::Subscribe().
作者: xinghesnak    时间: 2006-2-21 17:01
To saeba:Thank you very much!
VBA code and mark where the error occurs is:
Function GetPart(InfString As String, Optional Product As Product, Optional RootProduct As Product) As Part
          Dim TagPrduct, Status
          ReDim InputObjectType(0)
          InputObjectType(0) = "Product"
          LocSel.Clear
          Status = LocSel.SelectElement3(InputObjectType, "选择用来存放 " & InfString & " 的 Product:", False, CATMultiSelTriggWhenSelPerf, False)                                               *********错误的就是这行,就是屏幕选取受到限制
.........
end function

how to replace CATApplication::Subscribe() to the first parameter of CATUtilities::executescript()????
where is the return value of CATApplication::Subscribe()??

For example:The path of MyVBA projectis:"d:\1.catvba",two moudle:"11"and "22"--------"Sub main"
作者: saeba    时间: 2006-2-21 18:55
what is the error message?

>我看CAA帮助说需要用 CATApplication.Subscribe 来返回第一个参数值
I don't understand why...
Could you paste this part of the document?

>how to replace CATApplication::Subscribe() to the first parameter of >CATUtilities::executescript()????
The first parameter of CATUtilities::executescript() is a UncodeString...
作者: xinghesnak    时间: 2006-2-22 08:44
ExecuteScript 的用法:

public static HRESULT __stdcall ExecuteScript( const CATUnicodeString&  iLibraryName,
                                                                                  CatScriptLibraryType  iType,
                                                                           const CATUnicodeString&  iProgramName,
                                                                                               CATVariant&  oResult,
                                                                           const CATUnicodeString&  iFunctionName = "CATMain",
                                                                                                CATVariant*  iParams = NULL,
                                                                                                 unsigned int  iParamCount = 0,
                                                                                                 CATBoolean  iAutomaticReplay = TRUE)  

A short-cut method which runs a function written in a scripting language synchronously. ExecuteScript will return only once the scripted function has finished running.
Note:If the script uses one of the following methods:
         Selection.SelectElement2         *************我在VBA中的就是用的这个方法!
         Document.Indicate2D
         Document.Indicate3D
the current method must be ran on idle, using CATApplication.Subscribe with the CATSubscribeIdle value for the first parameter.
Parameters:
iLibraryName
                            The library in which the script is contained
iLibraryType
                           The type of the library
iProgramName
                           The name of the program in the library
oResult
                           The value returned by the function (if any)
iFunctionName
                           The name of the function to invoke
iParameters
                           An C++ array of parameters for the function
iParamCount
                           The size of the parameter array.
iAutomaticReplay
                           Specifies whether the replay is automatic or if it is explicitly done from a user interaction
作者: saeba    时间: 2006-2-22 11:20
>the current method must be ran on idle, using CATApplication.Subscribe with the CATSubscribeIdle value for the first parameter.

Ok this is the point.

"the current method must be ran on idle", what is "the current method"?
I guess it could be the Active method of your command, or any method in your command which called ExecuteScript().
So how can I make it "be ran on idle"?
Use CATApplication.Subscribe() to subscribe this method (the above method) run in type of  CATSubscribeIdle. I guess you should do this in the constructor of your command.
You may code like this:
CATApplication::Subscribe(CATSubscribeIdle, this, NULL, MyCommand::MyMethod);
(understand why "this"? )

Note, you misunderstood " the first parameter", here it means the first parameter of the method CATApplication.Subscribe(), NOT CATUtilities::executescript()!!!

I don't guarantee this work, it's all based on my understanding/guessing.
作者: xinghesnak    时间: 2006-2-23 15:26
To saeba:
        Thank you for your help! I always think that " the first parameter" is the first parameter of the method CATUtilities::executescript().Now I try it again! If I still meet some difficult progrem,I hope you can help me,Thank you !!!
作者: joetwo    时间: 2006-2-28 14:14
第一个参数"C:\\Documents and Settings\\liguangyi\\Local Settings\\Temp\\VBAProject1.catvba"和第三个参数 "模块1"怎么定义的呀?
为什么不是"C:\\Documents and Settings\\liguangyi\\Local Settings\\Temp“和”VBAProject1.catvba"?
“模块1”是哪里来的?
谢谢!
作者: xinghesnak    时间: 2006-2-28 15:04
第一个参数指的是Catvba文件的全路径
第三个参数指的是catvba文件中你所要运行的模块的名称(因为一个catvba文件可以包含多个模块,程序并不知道你要执行哪个,需要你去指定)
joetwo,有不明白的尽管说,没关系的!另外saeba兄,听说你终于装了中文输入法了,可喜可贺啊!!!还有就是你说的参数 MyCommand::MyMethod这块怎么添啊?
是这样?          
CATApplication::Subscribe(CATSubscribeIdle,this,NULL,this);
CATScriptUtilities::ExecuteScript("D:\\WORK\\CATIA-VC++\\Program1.catvba", catScriptLibraryTypeVBAProj e ct, "bb", var2, "CATMain", NULL, 0,TRUE);
还是:
CATApplication::Subscribe(CATSubscribeIdle,this,NULL,CATScriptUtilities::ExecuteScript());
CATScriptUtilities::ExecuteScript("D:\\WORK\\CATIA-VC++\\Program1.catvba", catScriptLibraryTypeVBAProj e ct, "bb", var2, "CATMain", NULL, 0,TRUE);

我用的前者,报错如下
D:\WORK\CATIA-VC++\workspace2\.\ASSET\CmdModule.m\src\Test2Cmd.cpp(36) : error C2664: 'Subscribe' : cannot convert parameter 4 from 'class Test2Cmd *const ' to 'void (__cdecl *)(void)'
There is no context in which this conversion is possible

还是用别的啊?
作者: joetwo    时间: 2006-2-28 16:10
谢谢xinghesnak !
我是初学者,问的问题比较低级,呵呵!
请教:
  
我在CATIA中Assembly Design 平台用MS VBScript录制了宏,(宏录制了导入几个零件)。


Language="VBSCRIPT"

Sub CATMain()

Set productDocument1 = CATIA.ActiveDocument

Set product1 = productDocument1.Product

Set products1 = product1.Products

Dim arrayOfVariantOfBSTR1(0)
arrayOfVariantOfBSTR1(0) = "E:\CATIA\A.CATPart"
products1.AddComponentsFromFiles arrayOfVariantOfBSTR1, "All"

Dim arrayOfVariantOfBSTR2(0)
arrayOfVariantOfBSTR2(0) = "E:\CATIA\B.CATPart"
products1.AddComponentsFromFiles arrayOfVariantOfBSTR2, "All"

Dim arrayOfVariantOfBSTR3(0)
arrayOfVariantOfBSTR3(0) = "E:\CATIA\X.CATPart"
products1.AddComponentsFromFiles arrayOfVariantOfBSTR3, "All"

End Sub


我想通过VC++创建一个按钮,实现运行这个宏,(类似CATIA中,宏的运行功能)
我的程序是
CATVariant  oResult;
CATScriptUtilities::ExecuteScript("E:\\",catScriptLibraryTypeDirectory, "Macro7.catvbs", oResult, "CATMain", NULL, 0, TRUE);   (我把录制的宏保存在E盘)
这样编译没有出错,但运行没有结果

请问像我这种方式可行不?
要是我把第一个参数改为"E:\\Macro7.catvbs"的话,第三个参数不知道改怎么处理。
谢谢了!
作者: xinghesnak    时间: 2006-2-28 16:13
上传我的catvba文件
作者: xinghesnak    时间: 2006-2-28 16:27
saeba兄,我的catvba文件也传上来,望高手指导一下吧
作者: saeba    时间: 2006-3-1 14:14
>参数 MyCommand::MyMethod这块怎么添啊?
真是。。。够菜的。。。>_<
这个函数是要你自己写的呀!
MyCommand是你的命令的class
MyMethod是你的命令的一个方法,在这个方法里调用ExecuteScript()。

你真的(仔细)看懂了我上次写的那一段了吗?




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