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.
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.
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 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.
Dear sir,
I need help according to VBS script tutorials videos.
Hi there! You can learn CATIA scripting by watching some of my video tutorials. They’re part of my all-in package. Details here: http://www.vbpdf.website
Thank you,sir
I’m trying to figure out how to create a new “3D Part”
Would you know how to do this..? Thx for your V5 Support.. 🙂
What do you mean create a new 3D part – by programming or manually? In V5 or V6? Thanks for the clarification.
Sorry Emmett,
I’m working on a macro that creates a “3D Part” and/or other objects in 3D Experience 2015x.
What i have learned so far is something that goes like this:
————————-
‘ Get the PLMNewService
Dim oNewService As PLMNewService
Set oNewService = CATIA.GetSessionService(“PLMNewService”)
‘ Create And Edit entity
Dim oEditor As Editor
Set oEditor = oNewService.PLMCreate(“3DShape”)
——————————–
But it does not work.. 🙁
Then i tried to do it a bit different:
—————–
‘1- Retrieves the service object to create a new PLM object
Dim oNewService As PLMNewService
Set oNewService = CATIA.GetSessionService(“PLMNewService”)
‘2- Creates a new 3DShape
Dim oEditor3DShape As Editor
oNewService.PLMCreate “3DShape”, oEditor3DShape
————–
Still not working.. 🙁
Can’t it stand alone..?
Best Regards
Michael
Instead of 3DShape – try VPMRefernece, it will work
Hi
Thank for your website and email tutorial. They help me a a lot.
Now I am having a problem with my CATIA V6 macro to insert a new 3D Part under a Product. Maybe because the database of V6 is different V5. I follow example in CATIA V6 Automation Document, but code doesn’t work. I create a new 3D Part then instant under a product. Here is my code:
Sub Macro()
Dim ActiveEditor1 As Editor
Set ActiveEditor1 = CATIA.ActiveEditor
Dim oProductRootService As PLMProductService
Set oProductRootService = ActiveEditor1.GetService(“PLMProductService”)
Dim oVPMRootOccOnRoot As VPMRootOccurrence
Set oVPMRootOccOnRoot = oProductRootService.RootOccurrence
Dim oVPMRoot As VPMReference
Set oVPMRoot = oVPMRootOccOnRoot.ReferenceRootOccurrenceOf
Dim cListInstances As VPMInstances
Set cListInstances = oVPMRoot.Instances
Dim My3DPartService As PLMNewService
Set My3DPartService = CATIA.GetSessionService(“PLMNewService”)
Dim MyEditor3DShape As Editor
My3DPartService.PLMCreate “3DPart”, MyEditor3DShape
Dim MyEditor As Part
Set MyEditor = MyEditor3DShape.ActiveObject
Dim MyVPMRepRef As VPMRepReference
Set MyVPMRepRef = MyEditor.Parent
Dim MyRootRef As VPMReference
Set MyRootRef = MyVPMRepRef.Father
‘Dim cListInstances As VPMInstances
‘Set cListInstances = oVPMRoot.Instances
Dim oNewProdInst As VPMInstance
cListInstances.Add MyRootRef, oNewProdInst
When new 3D Part is created, active window changed, error: Add method fail, I don’t know why???
Please help me to fix my problem
Thank you very much!
i took this part of the code and wrote a macro in CATIA V6:
Set oSearchService = CATIA.GetSessionService (“PLMSearch”)
Set oPLMSearch = oSearchService.Searches.Add
oPLMSearch.Type = “ProductDS”
it immediately crashes on the last line with the following message:
“Run-time error ‘-2147467259 (80004005)’:
The method Type failed
any idea what may be the issue?
How to measure distance between two points in your macro How do you create a second “SPAWORKBENCH METHOD” in CATIA macro in V6 3D EXPERIENCE?
Hello
Among the functions of the assembly, the macro that functions as an Existing Component in V5 “AddComponentsFromFiles ” in V6
ex>
Sub CATMain ()
Set productDocument1 = CATIA.ActiveDocument
Set product1 = productDocument1.Product
Set products1 = product1.Products
Dim arrayOfVariantOfBSTR1 (0)
arrayOfVariantOfBSTR1 (0) = “CATPart Directory”
products1.AddComponentsFromFiles arrayOfVariantOfBSTR1, “All”
End Sub
Try This..
‘1- Retrieves the service object to create a new PLM object
Dim oNewService As PLMNewService2
Set oNewService = CATIA.GetSessionService(“PLMNewService2”)
‘2- Creates a new Product
Dim oEditor3DShape As Editor
‘oNewService.SetAttributeValue “V_description”, “Mynewdescription”
oNewService.SetAttributeValue “E_Name”, “SampleName”
oNewService.PLMCreate “Product”, oEditor3DShape
Thanks for your feedback!
Hi~~~!
How do I know the “Type information” in the Reference Tab?
Hi,
If you are using 3DExperience platform then try this.
Dim oNewService As PLMNewService
Set oNewService = CATIA.GetSessionService(“PLMNewService”)
Dim oEditor3DShape As Editor
oNewService.PLMCreate “3DShape”, oEditor3DShape
‘ Sometimes instead of 3DShape you can use ‘VPMReference’to create a physical product.
Hope this will help!
How to let user to select a point? In V5, I can use this command:
status = selection.SelectElement2(InputObjectType, “select a point”, False)
But I don’t know how to use it in Catia V6.
Can you help me?
hello:
For some reason,I have no rights to create a macro liabrary in catia v6 ,and also can’t record macro.Now I create a macro in excel vba editor.And write a simple macro,it can connect to caita.Like below.The catia window was hide by the macro.
Could I use excel vba editor to do other things for catia v6?And defined any object as “object”,like the program below?
sub test()
dim ocatia as object
set ocatia=createobject(“Catia.application”)
ocatia.visible=false
end sub
Insert a Part in a current Product :
Sub catmain()
‘ Get root product
Dim oVPMRefOnRoot As VPMRootOccurrence
Set oVPMRefOnRoot = CATIA.ActiveEditor.ActiveObject
‘ Get instances collection
Dim oVPMInsts As VPMInstances
Set oVPMInsts = oVPMRefOnRoot.ReferenceRootOccurrenceOf.Instances
‘ Create 3DPart
Dim oNewService As PLMNewService
Set oNewService = CATIA.GetSessionService(“PLMNewService”)
Dim oEditor3DShape As Editor
oNewService.PLMCreate “3DPart”, oEditor3DShape
‘ Get Part from Editor
Dim oPart3D As Part
Set oPart3D = oEditor3DShape.ActiveObject
‘ Get VPMRepReference
Dim oVPMRepRef As VPMRepReference
Set oVPMRepRef = oPart3D.Parent
‘ Get VPMReference
Dim oVPMRef As VPMReference
Set oVPMRef = oVPMRepRef.Father
‘ Get window of initial 3dpart creation
Dim oMy3DPartWindowToClose As Window
Set oMy3DPartWindowToClose = CATIA.ActiveWindow
‘ Insert 3DPart Under root product
Dim oVPMInst As VPMInstance
oVPMInsts.Add oVPMRef, oVPMInst
‘ Close 3DPart window
oMy3DPartWindowToClose.Close
End Sub
Regards
Hi!
I’m not very used in using VBA and I’m new in this type of forums so i’ll try to do it my best.
These weeks i’ve been trying to import a .dxf File from my desktop and get it under the active Part (or Product, preferibly Part).
I tried to do it by StrService, but I don’t really finish understanding how it works.
I’ve tried using this Code:
Sub Importar_dxf()
Dim FiletoImport As String
FiletoImport = “C:\Users\User\Desktop\Prueba.dxf”
Dim Documento As File
Set Documento = CATIA.FileSystem.GetFile(FiletoImport)
Dim oEditor As Editor
Set oEditor = CATIA.ActiveEditor
Dim Selection1 As Selection
Set Selection1 = oEditor.Selection
Dim RootOc As VPMRootOccurrence
Set RootOc = oEditor.ActiveObject
Dim VPMOccurrences1 As VPMOccurrences
Set VPMOccurrences1 = RootOc.Occurrences
Dim strService1 As StrService
Set strService1 = CATIA.GetSessionService(“StrService”)
Dim Usage As String
Usage = “DraftingRepresentation”
strService1.Import Usage, Nothing, Documento, Nothing, RootOc, 1
End Sub
If Anyone could help me with the issue i’ll be very grateful.
thanks for all beforehand.
Regards
Hello
I want to export a Physical Product (3DShape/3DPart) to other neutral format.
In V5 this was possible with CATIA. Documents.ExportTo or SaveAs
I could not find silmilar option in V6.
Please help.
Also, is there an automation APT to delete an object from database? Manually we can do it from Collaborative Lifecycle App.
Vishal
After I originally left a comment I seem to have clicked on the -Notify me
when new comments are added- checkbox and now whenever a comment is added I
receive four emails with the same comment. Is there a way you can remove me from
that service? Appreciate it!
Can you include some EKL and CAA exapmles
Can you give a little brief with example on VPM reference. Product Occurrence and VPM Instance
How to create a front view of the part in CATIA V6 using a VBA ?
How do I find the PLM file?
How to select edge in in 3d experience
Macro
How to select edge in in 3d experience VBA
Macro
Bonjour,
Je souhaite créer une macro permettant d’extraire vers Excel les propriétés d’un des PDD et ATT.
En espérant une réponse de votre part.
Cordialement,
Hello,
I wish to create a macro to extract the properties of a PDD and ATT to Excel.
Hoping for a response from you.
Sincerely,
Hello everyone,
I am seeking assistance with developing a VBA macro for CATIA V6 that can export properties of PDD and ATT files based on a specific filter. I need to extract the following properties via excel file:
For PDDs:
PLM ID (idPLM)
Designation in both French and English
Version
Maturity
For ATTs:
Ref PA
Designation in both French and English
ECO
Technical Attribute
If anyone has experience with similar macros or can guide me on how to start writing this VBA script, I would greatly appreciate your help. I am specifically looking to understand how to access these properties programmatically within CATIA V6.
Thank you in advance for your assistance!
Best regards,