Hi.
In terms of speed:
CAA -> CATScript -> VBA
Formally .NET is on par with CATScript in making Automation
calls. However, performance drops drastically because of how .NET
manages COM objects, that is all objects that are exposed by CATIA
via Automation.
Each time you access COM object .NET CLR creates
Runtime Callable
Wrapper (RCW) that implicitly
marshals all calls to actual COM object's methods. It does so in a
decent way, but it is a construction of RCW that takes
a lot of time.
At this time it's important to understand how CATIA itself
creates COM objects to be consumed by Automation clients.
CATIA is written in a C++ framework named CAA
that is "Component Application
Architecture". Each logical "object" (say, a
point) is represented with a set of components
each providing certain behavior (implementing interface):
visualization, geometrical model, update mechanism etc. So when an
object gets exposed to Automation (you access it with a script)
another component gets created that allows access
to a certain object properties and methods,
exposing this object to a client application. And
the key thing is that such component is created
(almost) each time you access underlying
object.
So when you go:
var firstObject = CATIA.ActiveDocument.Selection.Item(1);
var objectOne = CATIA.ActiveDocument.Selection.Item(1);
you get two COM-objects that point to the same CATIA object. The
problem here is that for .NET CLR these objects are not identical,
so it creates RCW for each of them wasting twice as much time.
So what you want to do is to make sure that for each COM object
RCW is created exactly once. Basically, you keep reference to every
object retrieved (for instance store it in a collection of any
sort) and then reuse it throughout the whole
application.
In real life we use .NET for applications that implement any
business logic and CATScript for small utilities. Calling CATScript
from .NET is not only tedious, but also has a significant
performance cost since a script engine should be created in order
to execute a given script. So if you have to call a CATScript from
.NET, do it once per application lifetime or seriously
benchmark performance otherwise.