Added Properties Catia Macro: Getnewid Myparameters Name Amp Properties New
Added Properties Catia Macro: Getnewid Myparameters Name Amp Properties New
Added Properties Catia Macro: Getnewid Myparameters Name Amp Properties New
ADDED PROPERTIES CATIA MACRO
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:
1 getNEWID = myParameters.Item(part1.Name &; “\Properties\NEW_ID”
This same code can be used to access thickness, material, mass, and more.
1 ‘
2 ‘begin complete code
3
4 'script by Emmett Ross, www.scripting4v5.com
5 Sub CATMain()
6
7 Dim productDocument1 As Document
8 Dim product1 As Product
9 Dim products1 As Products
10
11 Set productDocument1 = CATIA.ActiveDocument
12 Set product1 = productDocument1.Product
13 Set products1 = product1.Products
14
15 'count the number of CATParts
16 partcount=product1.Products.Count
17 msgbox"CHECK: The number of parts is "&;partcount&;". Please click OK to continue."
18
19 'loop through all parts
20 Dim i As Integer
21 For i=1 to partcount
22
data:text/html;charset=utf8,%3Cheader%20style%3D%22margin%3A%200px%200px%2010px%3B%20padding%3A%200px%3B%20border%3A%200px… 1/2
29/09/2015 Added Properties CATIA Macro VB Scripting for CATIA V5
23 'apply design mode
24 products1.Item(i).ApplyWorkMode DESIGN_MODE
25
26 Dim partDoc1 As PartDocument
27 Set partDoc1=products1.Item(i)
28
29 'namebody=partDoc1.name
30
31 Dim partDoc2 As PartDocument
32 Set partDoc2 = partdoc1.GetMasterShapeRepresentation(True)
33
34 Dim part1 as Part
35 Set part1 = partDoc2.Part
36
37 Dim myProduct As Product
38 Set myProduct = productDocument1.GetItem(part1.Name)
39
40 Dim myParameters As Parameters
41 Set myParameters = myProduct.UserRefProperties
42
43 Dim getThickness,getMaterial, getMass, nom, partName, RealPartNumber
44
45 getThickness = myParameters.Item(part1.Name &;"\Properties\Thickness"
46 getMaterial = myParameters.Item(part1.Name&;"\Properties\Material"
47 getMass = myParameters.Item(part1.Name &; "\Properties\Mass").
48 getNEWID = myParameters.Item(part1.Name &; "\Properties\NEW_ID"
49
50 'nom=myProduct.Nomenclature
51 'partName=myProduct.name
52 'Defy=myProduct.Definition
53
54 RealPartNumber=myProduct.PartNumber
55
56 If getNEWID = RealPartNumber Then
57
58 Msgbox "PartNumber is: " &; RealPartNumber &; vbNewLine &
59
60 Else
61
62 Msgbox "PartNumber is: " &; RealPartNumber &; vbNewLine &
63
64 End IF
65
66 Next 'i
67
68 End Sub
data:text/html;charset=utf8,%3Cheader%20style%3D%22margin%3A%200px%200px%2010px%3B%20padding%3A%200px%3B%20border%3A%200px… 2/2