Clear Filters
Clear Filters

link Catia to Matlab

99 views (last 30 days)
Alessio on 6 Sep 2011
Commented: Edward Wilson on 26 Jul 2019
Hi I'm try to connect Matlab to Catia creating a Catia COM server using the command:
C =
but after this i can't do anything because matlab doesn't know the catia's properties, infact I tried to used the function:
I obtain the answer:
1x1 struct array with no fields.
And so i can't use any Catia's functions.
What can I do ?
  1 Comment
supriya la
supriya la on 20 Dec 2018
You can refer some youtube videos.

Sign in to comment.

Accepted Answer

Friedrich on 7 Sep 2011
Edited: Friedrich on 12 Feb 2014
I attached the file to that post.
But please read the full article first.
  • I used Catia v5 R19 and this version comes with a shipped example model “Robot_ABB_S2-Irbl6_2.CATProduct”.I hard link to this in my code. Maybe you have to change this path on your machine.
  • I hard linked to the .NET DLL from the MATLAB side. You have to modify this path so it matches your system.
  • In the VisualBasic I added the references to INFITF and CATV4IInteropTypeLib. You may have to update this reference so they match you system.
Now let’s start with the actual code.
Please note that this example is extremely trimmed on the shipped example “Robot_ABB_S2-Irbl6_2.CATProduct”.
First of all I like to show you how you can do this in MATLAB without the .NET DLL
%%open and make visible
catia = actxserver('catia.application');
%%get ready to open file
prj_name = 'C:\Program Files (x86)\Dassault Systemes\B19\intel_a\startup\components\arcWeld\Robot_ABB_S2-Irbl6_2.CATProduct';
doc = get(catia,'activedocument');
rootproduct = get(doc,'product');
mass = get(get(rootproduct,'Analyze'),'Mass');
area = get(get(rootproduct,'Analyze'),'WetArea'); %is in mm3
%%Wont work because of the pass by reference
feature('COM_SafeArraySingleDim', 1)
array = {1;2;3};
%%close catia
You see that you don’t get the GravityCenter because the input is passed by reference.
What happens here is:
  1. MATLAB makes a copy of the variable “array”
  2. The copy is passed to GetGravityCenter
  3. The values of the copy are modified
  4. MATLAB doesn’t read the copy back
MATLAB can’t handle this correctly because MATLAB doesn’t know that the input is passed by reference (the interface is not open).
The only way out here is to move to VB.NET.
You make a Class Library written in VB.NET to communicate with CATIA. The code is more readable as in MATLAB and you can work with the dot notations:
Public Class CatiaLinkLibrary
Dim CATIA As INFITF.Application
Dim rootproduct
Sub StartCatia()
CATIA = CreateObject("CATIA.Application")
End Sub
Sub CloseCatia()
End Sub
Sub Visible(ByRef mode As Integer)
If mode = 1 Or mode = 0 Then
CATIA.Visible = mode
End If
End Sub
Sub OpenFile(ByRef filename As String)
rootproduct = CATIA.ActiveDocument.Product()
End Sub
Function GetMass() As Double
Return rootproduct.Analyze.Mass()
End Function
Function GetVolume() As Double
Return rootproduct.Analyze.Volume()
End Function
Function GetArea() As Double
Return rootproduct.Analyze.WetArea()
End Function
Function GetGravityCenter()
Dim gravitycenter(2)
GetGravityCenter = gravitycenter
End Function
Function GetIntertia()
Dim inertia(8)
GetIntertia = inertia
End Function
End Class
What on the MATLAB side was a get,set and invoke becomes a nice dot notation. All the command and how they work can be obtained under the link I post earlier. The hardest part for me was to figure out what command to use since the interface CATIA provides is really complex.
You can compile this into a .NET DLL which you call from MATLAB through the NET.addAssembly command. I wrapped a MATLAB class around it to make easier to use on the MATLAB side. The class looks as follows:
classdef CatiaLink < handle
function obj = CatiaLink()
%modify this path to your .NET DLL
NET.addAssembly('C:\Users\Friedrich\Documents\Visual Studio 2008\Projects\CatiaLinkLibrary\CatiaLinkLibrary\bin\Debug\CatiaLinkLibrary.dll');
obj.catia = CatiaLinkLibrary.CatiaLinkLibrary;
disp('Catia started')
function Visible(obj,mode)
function Quit(obj)
function Open(obj,filename)
function mass = GetMass(obj)
mass = obj.catia.GetMass;
function vol = GetVolume(obj)
vol = obj.catia.GetVolume;
function area = GetArea(obj)
area = obj.catia.GetArea;
function cog = GetCenterOfGravity(obj)
tmp = obj.catia.GetGravityCenter;
cog = [tmp(1),tmp(2),tmp(3)];
function inertia = GetInertia(obj)
tmp = obj.catia.GetIntertia;
inertia = [tmp(1), tmp(2), tmp(3); ...
tmp(4), tmp(5), tmp(6); ...
tmp(7), tmp(8), tmp(9)];
It’s not a good idea to call NET.addAssembly in a constructor of a class, but I assume for the demo purpose its okay.
Once the DLL is loaded you can access the function of that DLL pretty easily. Most of the functions of the MATLAB class are simply wrapper functions. In the last two functions one has to convert the VB.NET data type into a MATLAB data type so you can work with it.
So the main work is to write a nice working .NET DLL
Once you have the DLL and the MATLAB Class you can call all your functions very nicely:
%%create catia
catia = CatiaLink;
prj_name = 'C:\Program Files (x86)\Dassault Systemes\B19\intel_a\startup\components\arcWeld\Robot_ABB_S2-Irbl6_2.CATProduct';
area = catia.GetArea
mass = catia.GetMass
volu = catia.GetVolume
cog = catia.GetCenterOfGravity
inertia = catia.GetInertia
So here a several steps to do but in the end you will have a nice interface on the MATLAB side.
Since the CATIA interface is really complex it’s hard to find a good point to start and the needed functions.
I hope I could clarify the things a bit and I hope this will help you with your project.
farzad on 11 Feb 2014
Dear Friedrich , the link is expired , maybe containing the models , please refresh if possible thank you so much , also in , we use Dim command ? like CATScript ?
Edward Wilson
Edward Wilson on 26 Jul 2019
Hi Friedrich,
I am very interested in this process and can recreate it using the .dll in the files attached to your original answer, however I am having issues compiling my own .dll file from the CatiaLinkLibrary. When I try to compiling it with the Library Compiler in Matlab R2017B it gives me an error saying it has too many entry points and cannot be added. If you could step me through the compilling process or point me to where to find more help I'd appreciate it.

Sign in to comment.

More Answers (8)

Friedrich on 6 Sep 2011
The communication with CATIA is tricky. The automation interface is not open so you won’t be able to see it. Even from Visual Basic you can’t see much. So you have to program blind.
The interface which CATIA provide can be found here:
You have to work with the set,get and invoke command from MATLAB to call these functions/ methods (e.g. set(C,'visbile',1))
But not all methods will work, e.g. GetInertia
The input is a passed by reference and MATLAB won’t recognize this and won’t return the values.
I think the best way here is to use and create a .NET DLL which handles the communication with CATIA. You can use this DLL in MATLAB than. In that way are not limited on the MATLAB side.
farzad on 22 Jan 2014
I am really in search of linking Matlab to Catia to pilot the parameters , or it's better to link MATLAB >> EXCEL >> CATIA ?
Jakob Pettersson
Jakob Pettersson on 7 Mar 2018
I am also searching for a way to change the parameters in Catia through Matlab. I am also thinking about linking Matlab to Excel to Catia like farzad suggested.
Have you learned anything about this topic farzad?

Sign in to comment.

Alessio on 10 Sep 2011
Hi Friedrich! Thanks a lot for your suggests!!They were very usefull!! Now I can use Catia from Matlab. But I have a little problem.... I have to add some components in an assembly. I made a macro with catia and the VB code is this:
Sub CATMain()
Set documents1 = CATIA.Documents
Set productDocument1 = documents1.Add("Product")
Set product1 = productDocument1.Product
Set products1 = product1.Products
Dim arrayOfVariantOfBSTR1(0)
arrayOfVariantOfBSTR1(0) = "C:\Documents and Settings\LELE\Desktop\cilindro.CATPart"
products1.AddComponentsFromFiles arrayOfVariantOfBSTR1, "All"
Dim arrayOfVariantOfBSTR2(0)
arrayOfVariantOfBSTR2(0) = "C:\Documents and Settings\LELE\Desktop\cubo.CATPart"
products1.AddComponentsFromFiles arrayOfVariantOfBSTR2, "All"
Following the the interface which CATIA provide (which you suggested me) I wrote this Matlab code:
but it doesn't work and I don't know you have an idea?

Alessio on 6 Sep 2011
Thank you Friedrich!!! I tried to use get and invoke command but Matlab said me that there are no fields, so I can't use any Catia function, for example
partDocument1 = C.ActiveDocument;
part1 = partDocument1.Part;
and so on.
I'd like to use your suggest to create a .net dll but I'm not so expert....can you be more specific??How can I do to create it? and how can I use it?
Thank's a lot!!!!
  1 Comment
Friedrich on 7 Sep 2011
I will post a small example later (made with CATIA v5). I have to look it up again. It's somewhere on my other PC. So stay tuned ;)

Sign in to comment.

Alessio on 10 Sep 2011
p.s.: The error is:
??? Error: Type mismatch, argument 1
  1 Comment
Friedrich on 12 Sep 2011
why the VB code when you use ML for communicating with CATIA?
Looking at the interface discription of AddComponentsFromFiles it seems you forget an inputargument:
So I would guess it should like this:
In addition you will get troubles with the CATSafeArrayVariant datatype on the CATIA side since "CATSafeArrayVariant are one-dimensional arrays of CATVariants.":
MATLAB passes 2dimensional arrays by default. To get MATLAB passing only one dimensional arrays you have to enable it through:
feature('COM_SafeArraySingleDim', 1)
But all this code I would do in the VB side and not on ML.

Sign in to comment.

Alessio on 12 Sep 2011
hi, sorry for annoying you.... I wrote 'All' in my matlab code...I only forgot to write it in my post... I tried to use feature('COM_SafeArraySingleDim', 1) as they say also here:
but it doesn't gives me the same error.
  1 Comment
Friedrich on 12 Sep 2011
mhhhh, try to cast it into a cell:
I had done this in my ML code above too.

Sign in to comment.

Alessio on 12 Sep 2011
Now, with the brackets, it works!!!
  1 Comment
Friedrich on 13 Sep 2011
So everything works for you? Can you mark it as answered (accept an answer)?

Sign in to comment.

XAVIER on 20 Dec 2013
Edited: XAVIER on 20 Dec 2013
This topic was very useful!
I got a matlab script which sets parameters into CATIA and then saving it. But CATIA doesn't update the parameters before saving. I tried to update the CAD model in MATLAB thanks to :
But that didn't work. Does anyone has an idea? Thanks a lot!

yasmine yas
yasmine yas on 9 May 2016
heloo plllz help me How can i import design in catia to matlab simulink i found programme which is called SANEON but i don't how it does work . Thank you


Find more on Java Package Integration in Help Center and File Exchange


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!