×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Question about CATIA VBA efficiency

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

RE: Question about CATIA VBA efficiency

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?

RE: Question about CATIA VBA efficiency

(OP)

: )
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

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

RE: Question about CATIA VBA efficiency

(OP)
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*****

RE: Question about CATIA VBA efficiency

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources