Will programming knowledge in CATIA v5 translate to V6?

One question I am getting asked more and more is if CATIA V5 macro programming skills are going to be applicable in CATIA V6? My answer is the majority of the macros you write in V5 will not be able to be used in V6 as is. But the skills and knowledge required to write the codes in V5 will transfer to V6 and other programming languages as well. Learn more by reading on.

Quick Introduction to CATIA V6

The biggest difference between CATIA V6 and CATIA V5 is that it is server based, therefore it is required to search for a part or product before you can open it.

catia v6 automation

The second most noticeable difference is the silver layer. Simply put, it is a new environment that is accessed when you choose to “Explore” a product instead of opening it directly from the search window. It allows you see 3D thumbnails of the parts in a sort of turntable organized by the hierarchy. The main purpose of this layer is to allow you to visually choose and open a part, but it can also be used to open specific part(s) within a product that you want for very large assemblies. It has many other applications but to be concise those are the main two.

differences between catia v5 and v6

The environment where the product is opened is called the “Blue Layer”, basically the place where we are used to work in V5. The “3D Part” is equivalent to the CATProduct and CATPart we are used to. The “3D Shape” is what we call the Representation Reference or “Rep. Ref.” for short. Similar to V5 in the blue layer. Although, the measure tool and the constraints/mechanism creation are different.

catia v6 macros

CATIA V6 Macro Example

The following code is a CATIA V6 macro that will open parts using a txt file on the desktop. Notice how it is the same yet different to a code written for V5?

Sub CATMain ()
Dim partNumbers(100) As String
ReadFile partNumbers
For i = 1 to 100
If partNumbers(i) <> "" Then
OpenProduct left(partNumbers(i), 15), right(partNumbers(i), 1)
Else
Exit For
End If
Next
End Sub
Sub ReadFile(partNumbers)
Dim oFile As File
Set oFile = CATIA.FileSystem.GetFile ("C:\Users\yOuRnAmE\Desktop\PartNumbersTextFile.txt")    Dim iStream As TextStream
Set iStream = oFile.OpenAsTextStream ("ForReading")For i = 1 to 100
partNumbers(i) = iStream.ReadLine
If iStream.AtEndOfStream = True Then Exit For
NextiStream.Close
End SubSub OpenProduct (partNumber, version)
Set oSearchService = CATIA.GetSessionService ("PLMSearch")
Set oPLMSearch = oSearchService.Searches.Add
oPLMSearch.Type = "ProductDS" 'can be different for your company
oPLMSearch.AddAttributeCriteria "PLM_ExternalID", partNumber
oPLMSearch.AddAttributeCriteria "V_version", version
oPLMSearch.SearchDim cPLMEntities As PLMEntities
Set cPLMEntities = oPLMSearch.EditedContentDim oOpenService As PLMOpenService
Set oOpenService = CATIA.GetSessionService ("PLMOpenService")
Dim oEditor As Editor
oOpenService.PLMOpen cPLMEntities.Item(1), oEditor
Set OpenProductAndgetEditor = oEditor
End Sub

 

Final Thoughts

I believe one of the best ways to learn something is to throw yourself into it head first. One way I believe you can learn more about writing VBA macros is to actually learn how to program in another language, such as Java. Why? When you learn multiple programming languages (or even spoken languages), you can’t help but identify similarities between them and in turn understand the foundations on which they’re built. I was about to create a simple Android application even though I have never taken a class or read a book about Java due to my CATIA programming knowledge. Even if you know you’re going to be moving on to CATIA V6 soon, it is still very beneficial to learn how to program in CATIA V5 first.

So yes, the actual code itself is different but the concepts and syntax are the same and can be applied not only to V6 but to any programming job.

Special thanks to Luca Lafera for the help with this post and for providing the example V6 code!