Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Macro to run when I open File

Status
Not open for further replies.

appvid

Automotive
Nov 9, 2012
81
Hello,

I have no clue how to do this. I wanted to create a start part for a group of designers. Any designer opens the file A macro should run automatically and give the results. Is there any way to evoke / trigger macro when a particular file gets opened.

thanks a lot for your help


regards
var

 
Replies continue below

Recommended for you

Instead of having the user open the file, how about having your program open the file and then triggering the method?
 
Well , This program is a check whether previous user did what supposed to be done on one particular file.
once next user opens file, macro runs and he knows if some thing was not done.

As per your suggestion user should manually run the program. but we want script to run automatically. (not batch scripts)

hope it is clear..

regards
var
 
Yes, the user would run the program.
The program opens the file and runs the check.

I can see another way to do this with Reactions; but, again the user would have to launch the check code manually - or the reaction could be set up to fire when something is changed.

If you want to check if something is done, maybe embed the code as a reaction in the starter part.
That way, the check is made at geometry creation time.
sine you are using a start part, I think this is your nest bet.

I have never heard of a OnOpen event attached to a file that can be used as I think you are hoping there is.

Another way to do this is to have a program always running and pinging Catia looking for the file.
When it finds the file is open, it runs the program.
I am no fan of this technique because the program will have to be launched at boot up or as a batch with Catia - to keep it automated.
And it will always be running.
And you need a good ping rate to make sure you get the file as soon as it opens - which might be disruptive to the user that opens the file if they aren't expecting the code to run.
Lots of issues with this idea.....


 
Yes you are right with program always running has some impact on system performance.

Let me explain our work flow bit more.

Catia user-A required to fill one Excel file after they he done with changes on a part. Some users don not care some users often forget. [glasses].

When subsequent change request comes up, available user (user-B) takes it up and he would know when opening the file that previous user (user-A) did fill the excel or not. If not done, he would intimate user-A and get the necessary Excel form filled up.

This code should run only once. so Iam thinking to do while opening the file.

If i go with reaction, scripts runs again and again obviously we do not want to do. [smile2].

regards
var
 
Hello appvid,

The application presented in this video works as follows:
1. Constantly monitors each CATIA Session.
2. On file open, checks the version of it and displays the relevant message.

What you need is a similar, slightly modified, application ie an application which will
1. Constantly monitors each CATIA Session.
2. On file open, checks the name of the file and runs a specific macro.



-GEL
Impossible is nothing.
 
Exactly, this is what I need.

How do i do this GELFS...
 
May be FERNANDO will have idea if I can run macro while opening a particular catpart.


 
you can create a toolbar that first open your CatPart file then run your macro.
 
farzad, User still
1) Drag catia file to catia application and open
2) Ctl+o
3) File--open




 
+
4) Windows Explorer Double-Click on a CATIA file.
5) Windows Explorer RMB Open
6) CATIA Power Input C:Open
7) CATIA Open in a new Window

-GEL
Impossible is nothing.
 
Appvid, I mean if you want to run your macro while opening a practical catpart, you can create a new toolbar and a new command to do this my friend (this's my suggest for you)

but I don't know how you can run your macro while opening a practical catpart with (Ctrl+O)! that is interesting for me too !
 
Farzad, I believe there is way for running macro while opening part too... Your idea is creative one, but just does not fulfill my needs 100%. Another thing is that I need to run this macro on only production released parts.

1) Macro must only run on few files. ( example- Files in D:/ drive)
2) Macro must only run once on each part in the session

Any one has any idea if i can use mouse clicks on active window to trigger macro by using reactions (KWA).

thanks
var
 
Hi,

From my point of view, in a CATIA macro (or an external CATIA application), you can open directly a specific CATIA file and do what ever you want on that part. But what I understood from you is that you need also to check an Excel file if is filed in a specific way or not. What are you checking? Some cells if they are filled or not, a timestamps or? You will need also to check the Excel file in same time, I suppose if all is OK the user can go further...

A CATIA file can be opened without problems, you need to get in your application first CATIA object then do your checks. It's much more complicated if you have more CATIA sessions opened...

For example, the code bellow can be copied and paste in a vbs file (paste in Notepad and change extension from txt to vbs and run by double click). Anyway, for your user can be just one click on an icon to fire a macro in CATIA to do all checks in a specific part and compare with the checks in Excel. Same thing if you will create an external application, depending on what you want.

Code:
On Error Resume Next
Set objCATIA = GetObject(, "CATIA.Application")
'~ If Err.Number <> 0 Then  ' this part of code is commented because is supposed that you have already CATIA opened
'~ Set objCATIA = CreateObject("CATIA.Application")
'~ Err.Clear
'~ End If
'~ On Error Goto 0

objCATIA.Visible = true
objCATIA.DisplayFileAlerts = true

'Create a new part in already opened CATIA
'~ Set objProd = objCATIA.Documents.Add("Part")
'Open a  part with name test, change as you wish
Set objProd = objCATIA.Documents.Open("c:\temp\test.CATPart")

Dim oShell

'~ ' Create the WshShell object to run a specific CATScript in CATIA from a specific location
''' the code from that CATScript can be also implemented here but with some modifications...

Set oShell = WScript.CreateObject("WScript.Shell")

oShell.Run ("c:\_Makro\counter_iso.CATScript")

Regards
Fernando

 
Helloo Fernando, Glad you saw my question and replied. please see the attached picture. I want every one in the team to know if excel file is filled or not after the changes to CATpart (in release directory). All I want to know is there any way to run macro automatically.

I think you will have some idea.

regards
Var

 
Now what you want is much more clear for everyone.

In fact, you need a macro to launch a CATPart (this can be done by user in an input box), search the file in R folder, open in CATIA if existing, immediately open excel file (or do it in background), search your CATPart number in the file and check in column A what is filled (is much easier like this, user can compare and see what is missing).

Of course all of these can be done in same macro....I still have something unclear, how or where is specified your CATPart number in excel file? I mean 9999A-004 and all others? I suppose the xls file 9999A is for all of them, isn't it?

See, if you don't give all info's, no one can give a good answer, you will put the developer on a wrong track...

Regards
Fernando

 
Well, I can manage to write script to access excel file and find out which revision is not filled. All I need is how to trigger macro. (Either by rule or reaction automatically).

Your code is to launch Catia and run macro. What I am looking is, Catia session is already open and when I open file macro should.

For example, When you close catia with out saving file, a message pops up saying " DO YOU WANT TO SAVE FILE".... and if you see video from GELFS somehow it reads what version of file and displays it an screen.

see that attached picture too


 
 http://files.engineering.com/getfile.aspx?folder=8ec27dbb-3e41-4ff8-bc9b-98612379f09a&file=question-2.jpg
Hi,

Did you read the code posted? VBScript is checking first if CATIA is opened (GetObject) and then opening the CATIA file (is not opening CATIA - CreateObject). Of course you need to adapt the code. In same script you can open Excel file and also fire automatically a vba macro already done inside Excel file.

What you want can be done in many ways, depend only what kind of solution you choose. Of course, you can search on Google to see how to open and run automatically a macro in Excel, fired from a vbs script or another kind of application.

Or you can do everything inside a CATIA macro (opening files and checking Excel). I believe you don't need rules or reactions....or if you are more familiar with Excel VBA you can do it directly from there communicating with CATIA...

Regards
Fernando

 
what appvid wants it's something similar to an "open" event on workbook in excel.. catch the event on CATIA and use to test the letter of the drive..

I do not have any knowledge of caa/rade but i think that is what he is looking for..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor