Question about CATIA VBA efficiency
Question about CATIA VBA efficiency
(OP)
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
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





RE: Question about CATIA VBA efficiency
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?
RE: Question about CATIA VBA efficiency
: )
I want to do something like "Monte Carlo method".
Of course I need to collect some info. after product update.
RE: Question about CATIA VBA efficiency
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
RE: Question about CATIA VBA efficiency
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*****
RE: Question about CATIA VBA efficiency
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