In addition to the typical CATIA part properties such as ‘Part Number’, ‘Revision’, ‘Description’, etc., many companies utilize the “Define other properties” button and add a handful of their own added properties. These show up as “user parameters” but are not very obvious how they can be used in a CATIA script and many people struggle to figure out how to set a string equal to a specific added property.
For this specific example, let’s say we have an added property called “New_ID” and we would like to compare it to the part number. Maybe this fictional company uses SmarTeam for PDM and they let the assigned document number be their part number if it’s a made part. Currently, their problem is that they have to manually copy and paste to make sure that the number is the same in both the SmarTeam Profile Card and the CATIA Document Properties – the SmarTeam ID is mapped to “New_ID” field in the CATIA document added properties. We need to automate the task of matching the New ID to the part number by figuring out how to set a string variable to equal the value of that field.
I wrote a CATIA macro to determine if the “New_ID” string matches the Part Number. This CATScript example works on a single product that only contains CATParts and assumes every part has the NEW_ID property. The code cycles through each part and checks the NEW_ID with the partnumber and displays a message box saying if they match or not.
The entire code for this example is below, but most importantly, I get the Smart Team ID from the Added Properties into a string variable with this line of code:
getNEWID = myParameters.Item(part1.Name & “\Properties\NEW_ID”).ValueAsString |
This same code can be used to access thickness, material, mass, and more.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | ‘-------------------------- ‘begin complete code 'script by Emmett Ross, www.scripting4v5.com Sub CATMain() Dim productDocument1 As Document Dim product1 As Product Dim products1 As Products Set productDocument1 = CATIA.ActiveDocument Set product1 = productDocument1.Product Set products1 = product1.Products 'count the number of CATParts partcount=product1.Products.Count msgbox"CHECK: The number of parts is "&partcount&". Please click OK to continue." 'loop through all parts Dim i As Integer For i=1 to partcount 'apply design mode products1.Item(i).ApplyWorkMode DESIGN_MODE Dim partDoc1 As PartDocument Set partDoc1=products1.Item(i) 'namebody=partDoc1.name Dim partDoc2 As PartDocument Set partDoc2 = partdoc1.GetMasterShapeRepresentation(True) Dim part1 as Part Set part1 = partDoc2.Part Dim myProduct As Product Set myProduct = productDocument1.GetItem(part1.Name) Dim myParameters As Parameters Set myParameters = myProduct.UserRefProperties Dim getThickness,getMaterial, getMass, nom, partName, RealPartNumber As String getThickness = myParameters.Item(part1.Name &"\Properties\Thickness").ValueAsString getMaterial = myParameters.Item(part1.Name&"\Properties\Material").ValueAsString getMass = myParameters.Item(part1.Name & "\Properties\Mass").ValueAsString getNEWID = myParameters.Item(part1.Name & "\Properties\NEW_ID").ValueAsString 'nom=myProduct.Nomenclature 'partName=myProduct.name 'Defy=myProduct.Definition RealPartNumber=myProduct.PartNumber If getNEWID = RealPartNumber Then Msgbox "PartNumber is: " & RealPartNumber & vbNewLine & "NEW_ID is: " &_ getSTID & vbNewLine & "They are a MATCH." Else Msgbox "PartNumber is: " & RealPartNumber & vbNewLine & "NEW_ID is: " &_ getNEWID & vbNewLine & "They are NOT a match." End IF Next 'i End Sub |
hello,
I am trying to write a macro that modifies the default color of the other elements in a sketch. I cannot find the property whose value I need to modify. The property is at Tools – Options – Mechanical Design – Sketcher – Default color of the elements.
What method is used to change the value of the parameter NEW_ID?
Is there a way to get the properties in the SmarTeam Profile card withouth mapping them to the CATIA Part Properties?
Hi Emmett,
I am running this code from the VBA editor. The macro gives me an error of “Run-time error ’13’: Type mismatch at line 27. My CATIA is version 5-6 release 2015. how should I troubleshoot this?
Is it this line: Set partDoc1=products1.Item(i)? Are you running from a CATProduct?
Yes it is, and yes I am. I think I got a fix (or workaround). If I comment out the DIM assignment just before the Set at line 27 (Dim partDoc1 As PartDocumentDim changed to partDoc1 ‘As PartDocument) it works. I added an “On Error Resume Next” before the “get***** =” because the first part may not have any properties.
I have been using your website as a resource for a few years now and would like to thank you for your time and effort.
How to change the part layer number by macro ?
Hi,
how to change the properties of callouts in catia drawing (like arrow length, type etc) using vba
thank you
Angel D
Hi dear
I wanted to update Length In unfold sheet metal by macro az x and y-direction.
tank you
Vahid Karami
hey
it is giving me error as method item failed
at the line of getThickness = myparameters …….
and it is also giving error while using Dim please help me