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!

Question about CATIA VBA efficiency

Status
Not open for further replies.

threepoints

Automotive
Nov 6, 2006
3
TW
Dear all:

I plan to make a VBA macro for rutine works for me.
The structure:
Product
└Part1(fix)
└Part2
└constraints
some constraints are exist with Part2.

There are some parameters control by VBA, and send to Part1 and Part2
(basically are rnd() values, I check CATIA fomula and can't find random function)

example:
=======================================================================
Private Sub runanalysis_Click()

Dim StartTime As Date, EndTime As Date
StartTime = Timer

Set productDocument1 = CATIA.Documents.Item("Product1.CATProduct")
Set product1 = productDocument1.Product
Set documents1 = CATIA.Documents
Set partDocument1 = documents1.Item("Part1.CATPart")
Set XXX = partDocument1.Part
Set para1 = XXX.Parameters

Dim lh_h1_rnd As Length
Set lh_h1_rnd = para1.Item("lh_h1_rnd")

For i = 1 To 1000
lh_h1_rnd.Value = Rnd() * 10
product1.Update
'store a parameter to an array()
Next i

'export the array() data to EXCEL.
EndTime = Timer
MsgBox "Calculate total" & Format(EndTime - StartTime, "00:00") & "seconds"
End Sub

=======================================================================

From my previous experience, the macro will run slower and slower when loop cycles increases.
My question is:
1. Any suggestion for speed up CATIA loop macro?
2. Any VBA function can clean CATIA buffer or ...etc, and CATIA can reset?
3. I have another idea that could I run 100 loops, then close CATIA, re-open, run again. But how to write this automatically.

Thanks everyone....

3PTs from Taiwan
 
Replies continue below

Recommended for you

So you are looking in Part1 for a parameter called lh_h1_rnd
Then you set the parameter's value to a random number multiplied by 10...and you do this 1000 times...why? What is this supposed to do?
 

: )
I want to do something like "Monte Carlo method".
Of course I need to collect some info. after product update.
 
You could try executing this behavior with CATIA in Batch Mode. This would require you to migrate your code to something other than VBA (Likely VB.Net) which would launch the CATIA Session, Load the Model, run the "experiments" and export the results.

I am not sure if this will help or not, but you could also try dumping the Undo stack after n number of product updates.

Call CATIA.StartCommand("Clear History")

--Doug
 
Thanks Doug

I'll try CATIA.StartCommand("Clear History"), report improvement effect tomorrow.
For batch mode, I have no this ability now, but I will try to understand.

*****2015\5\20*****
I add
Set CATIA = GetObject(, "CATIA.Application")
CATIAStartcommand "Clear History"


but always get "click ok to terminate" or I have to force-close CATIA.
How do I use this command?
*****2015\5\20*****
 
This command will clear the undo stack on the active document. For Instance, if you open a blank CATPart/CATProduct and click a few times in the background (this adds an 'Empty Selection' item in the undo history. If you then run a CATIA.StartCommand("Clear History") through a simple macro, you will notice the 'Undo' button will no longer be selectable as the Undo Stack has been flushed.

If I were to try implementing this in your code, I would execute it after you have recorded your outputs after the Product update. Again, this is probably a long shot to improve execution of your code but reducing large volumes of data modification being stored in the undo stack might help prevent some of the slow down in your routine.

--Doug
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top