ArnaudG
Mechanical
- Dec 5, 2019
- 25
Hi all, I have this weird question because I created a law in my part that launches a CATscript macro. This law is automatically evaluated when the parts opens (during its opening).
By the way this is exactly what appvid was trying to do in this topic : thread560-364824 (I can explain that in another topic or here if it's needed).
The problem is that my macro uses CATIA.ActiveDocument to find the document on which it has stuff to do. However, when the document is still in the process of opening, it's not the active document yet and if it's the first document to be opened in the session, there is no active document at all and I have an error.
I thought I found a way to get my opening document to work on it with a pretty heavy method but it used to work : I compared the opened documents to the opened windows AND to the components of the opened assemblies (because of course when you open an assembly, its components are opened as well just to simplify everything...). With this I was able to get only one remaining component that should be the document in the process of opening.
But when I tried with a more realistic assembly opened I faced another problem : this assembly contains parts which are copies with link so you can have one part (A) which is a copy with link to another part (B) and if you open A, be is opened as well and listed in CATIA.Documents. But B is not the file I'm opening either.
I don't want to do a loop to check if each body of each opened part has a Solid which has a source element that leads from parent to parent to a part that is in the opened documents and exclude this file from my potential opening document.
And of course I can't use the CATIA.Documents.Item(index) because the last opened document is not always the last or first index in the collection.
In my law (fog law) I'm able to find the name of the document containing the law, but I can't pass this name to the CATscript (I don't have KWA license so I can't create actions or embedded scripts to call with the vbscript.Run(arguments) command in EKL).
So I'm looking for a way to detect if the document containing the law that launched the CATscript is a document that is currently opening or that is already opened (and in this case ActiveDocument will work fine). The only thing that I could think of would be to have an external macro launched with CATIA and that monitors the events (open event in this case) so that I can find maybe what is happening and if my macro is launched from an opening document or not).
I also realize something else while writing this : at some point all the parts will have the law created, so when I open an assembly containing these parts the law will trigger the macro and will take ages to open a large assembly so I must be able to prevent the law from triggering during the opening process (or at least not launch the macro because it's the macro that will take some time to process).
To be short and as a summary, the ultimate goal would be to not launch the macro when the file is opening (which could mean not trigger the law during opening even if the law must be triggered if any modification is done to the part).
By the way this is exactly what appvid was trying to do in this topic : thread560-364824 (I can explain that in another topic or here if it's needed).
The problem is that my macro uses CATIA.ActiveDocument to find the document on which it has stuff to do. However, when the document is still in the process of opening, it's not the active document yet and if it's the first document to be opened in the session, there is no active document at all and I have an error.
I thought I found a way to get my opening document to work on it with a pretty heavy method but it used to work : I compared the opened documents to the opened windows AND to the components of the opened assemblies (because of course when you open an assembly, its components are opened as well just to simplify everything...). With this I was able to get only one remaining component that should be the document in the process of opening.
But when I tried with a more realistic assembly opened I faced another problem : this assembly contains parts which are copies with link so you can have one part (A) which is a copy with link to another part (B) and if you open A, be is opened as well and listed in CATIA.Documents. But B is not the file I'm opening either.
I don't want to do a loop to check if each body of each opened part has a Solid which has a source element that leads from parent to parent to a part that is in the opened documents and exclude this file from my potential opening document.
And of course I can't use the CATIA.Documents.Item(index) because the last opened document is not always the last or first index in the collection.
In my law (fog law) I'm able to find the name of the document containing the law, but I can't pass this name to the CATscript (I don't have KWA license so I can't create actions or embedded scripts to call with the vbscript.Run(arguments) command in EKL).
So I'm looking for a way to detect if the document containing the law that launched the CATscript is a document that is currently opening or that is already opened (and in this case ActiveDocument will work fine). The only thing that I could think of would be to have an external macro launched with CATIA and that monitors the events (open event in this case) so that I can find maybe what is happening and if my macro is launched from an opening document or not).
I also realize something else while writing this : at some point all the parts will have the law created, so when I open an assembly containing these parts the law will trigger the macro and will take ages to open a large assembly so I must be able to prevent the law from triggering during the opening process (or at least not launch the macro because it's the macro that will take some time to process).
To be short and as a summary, the ultimate goal would be to not launch the macro when the file is opening (which could mean not trigger the law during opening even if the law must be triggered if any modification is done to the part).