1

I often times have the need to import 3D points (x,y,z data) into the CAD software CATIA. Currently I do this by creating an excel spreadsheet using a java library, and then executing a visual basic macro from within excel to add the data to CATIA. Now I'm not much of a VB guy, which is why I'd like to skip the excel step and directly send data to CATIA. Is there a way to do this? Maybe a java library to allow me to call VB code? Or maybe there is a java api to CATIA which I could use?

Kind regards, MHOOO

MHOOO
  • 633
  • 6
  • 15

1 Answers1

3

Unless you are lucky enough to have a CAA licence, the only API exposed by CATIA V5 is the VB one. The good thing is that this is in fact a COM interface, which you can invoke not only from VBA but also from a variety of languages that do support this protocol. (C++, Python, Java, ...).

For Java, you need a library for accessing COM and thus the CATIA API. The easiest for me is Jacob (http://danadler.com/jacob/).

Here's some sample code using Jacob:

import java.net.UnknownHostException;

import com.jacob.com.Dispatch;
import com.jacob.com.Variant;

import com.jacob.activeX.ActiveXComponent;

class TestMacroInvocation
{
    public static void main( String [] args ) throws Exception
    {
        ActiveXComponent catia = new ActiveXComponent("CATIA.Application");
        catia.setProperty("Visible", new Variant(true));
        Dispatch oDocuments = catia.getProperty("Documents").toDispatch();
        Dispatch oDocument = Dispatch.call(oDocuments, "Open", "C:\\Users\\Me\\Desktop\\TestRib.CATPart").toDispatch();

        Dispatch.call(catia, "StartCommand", "MyMacro");
        Dispatch.call(catia, "Quit");
    }

It's just a different way to use the CATIA VBA API, and you'll have to rely on the documentation provided by Dassault Sytèmes.

Hope this helps.

Community
  • 1
  • 1
cma
  • 425
  • 3
  • 10
  • 1
    This is exactly what I ended up doing. Only problem is the speed of the COM interface. I have to add several thousands of points and with the COM interface I can only add ~70 per second (interestingly enough, I can get ~300 per second if I click on the menubar inside CATIA). You wouldn't know how to speed that up by any chance? – MHOOO Jan 17 '12 at 13:02
  • In fact, when using the API from VBA (from inside CATIA), you're using IDispatch. IDispatch is sslllooowwww. When using the CATIA API from Java (or from Excel or whatever), it is even worse since each method invocation (or property access) involves inter-process communication (between your java process and the CNext.exe process). May be accessing the API from C++ (importing the TLB in your VC++ project) can speed up things, but I haven't tried it. – cma Jan 18 '12 at 17:28
  • I read that catia's VBA interface is in fact using the TLB files, so I doubt importing and using them in C++ would make any difference. Then again I don't have a CAA license available to work with anyway. Fastest means I can come up with is exporting the data into IGS first and then importing that. – MHOOO Jan 19 '12 at 20:35
  • 1
    Indeed VBA uses the TLBs, but to my knowledge relies on IDispatch to make the calls (I'm no expert, though, so if anyone knows the exact VBA calling mechanisms, please jump in). My point was that you can use the TLBs from a C++ program without having the CAA licence. See http://msdn.microsoft.com/en-us/library/8etzzkb6%28v=vs.71%29.aspx . – cma Jan 20 '12 at 10:32
  • 1
    Interesting. I'll have to try that out. – MHOOO Jan 20 '12 at 13:57