Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to know if a document is opening ? 1

Status
Not open for further replies.

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).
 
Replies continue below

Recommended for you

Hi.

ArnaudG said:
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

Why is that? How do you launch the script from a law?
I personally can think of many weird and unconventional ways of passing string data between CATIA automation routines ;)
 
I use the LaunchMacroFromFile function because I can't use Run with parameters as I said as it means that the script is in the tree (which means that you must have the KWA license in order to create a script action).

I also tried to send the value of the path to a parameter but the way the law works won't let me do that. I can create a law with string formal parameters but it can't be evaluated in a formula and if I use the trick of length formal parameters, I can't write another parameter (it says that a law must evaluate at least one and only one formal parameter).
Maybe there's something to do in the law that can work.

Here's what I wrote ("Corps principal" is main body in french, Longueur.1 is my length formal parameter, MACRO_Path is a string parameter that I created in the parameters of the part).

Code:
/*Loi créé(e) par aguitton 2020-01-14*/
let oBody(feature)
let str1(string)
let str2(string)
let str3(string)
let str4(string)
let i(integer)

set oBody = `Corps principal` 
str1= oBody.Owner.Id()
str2 = oBody.Owner.AbsoluteId()
str3=ReplaceSubText(oBody.Owner.AbsoluteId(),str1,"") 
i=str3.Length()-1
str4=str3.Extract(0,i)
/*Message(str4)*/


if Longueur.1 <>0mm
	MACRO_Path =str4
else 
	MACRO_Path =str4

I also tried with 2 formal parameters with something basic. Let say I have fLongIn and fLongOut as length formal parameters, this works as long as I don't want to write in MACRO_Path. I can use this law in a formula (I use it with 2 dummies parameters in an empty part).

Code:
/*Loi créée par A. Guitton*/
let oBody(feature)
let str1(string)
let str2(string)
let str3(string)
let str4(string)
let i(integer)

if fLongIn<>0mm
	fLongOut=1mm

set oBody = `Corps principal` 
str1= oBody.Owner.Id()
str2 = oBody.Owner.AbsoluteId()
str3=ReplaceSubText(oBody.Owner.AbsoluteId(),str1,"") 
i=str3.Length()-1
str4=str3.Extract(0,i)
Message(str4)
 
No I didn't find any solution to avoid evaluate the law when the part opens (it's always evaluated because of the conditions I have inside and I can't change those conditions). I tried the search through each body to find the potential linked element. I still have an error somewhere but the good point with that error is that it makes the macro exit and in this case it's not a problem because during the opening I don't need to have the macro launched (it's here to update some parameters but they are already updated before closing the part).
Worst case I can still have a message box to ask the user to manually launch the macro to have everything updated but it doesn't seem to be useful.
 
ArnaudG said:
No I didn't find any solution to avoid evaluate the law when the part opens (it's always evaluated because of the conditions I have inside and I can't change those conditions).

I'm actually asking not about how to avoid, but about how to enable. I can't achieve automatic law evaluation using sample part from documentation ([tt]KwrObject.CATPart[/tt]).
Can you please provide a sample part that would have a law that runs a script on opening?
 
I guess it depends on the conditions of the law and some settings. I join a part and a screenshot of my settings. If I open this part, the law is evaluated and therefore the according macro is launched. The macros should be in D: but you can change the path in the law if you want.

Settings_dpdugd.png
 
Thank you, now I finally got it working.

From the top of my head - use [tt]Trace[/tt] function in KW to write arbitrary string data to the log file that can be easily read by a script (see CATIA documentation on trace log location).

 
As for this:

ArnaudG said:
Worst case I can still have a message box to ask the user to manually launch the macro to have everything updated but it doesn't seem to be useful.

Every automation tool have to have an ability to be launched manually.
Furthermore, it's in user's interests to produce "correct" and updated part, and he's probably even has some legal responsibilities to do that.
So despite of many advantages of complete userless automation, it's not always bad to ask for a little interaction on his side..
 
Thanks, I'll check the Trace function. If I can make it work that would be so helpful.
Thanks also for your last remark/advice about user interaction ;)
 
Hi, I was able to use the Trace function successfully ! Thanks again.

Now I have another problem because on my computer the trace file create has a weird name (it uses GMT time even though my laptop is set to eastern american time) but I found a workaround by declaring a user file for the knowledge trace.
You can add CATKnowledgeTracePath = .... in your environment file (CATEnv) and point to a specific file (it will be created anyway by catia, you don't have to create it before using it).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor