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