Hello all,
Here's a challenge that I have been stuck on for quite some time. I am creating a macro to do the following:
1. Blank User form is shown
2. Search and select all spec tree's assemblies.
3. Count total assemblies in selection and creates a "PART NUMBER" parameter property is none exist.
4. If text box for "PART NUMBER" does not exist in user form then create one and name the textbox with the part number.
5. Edits to the part number can be made on the user form. NOTE: The code/user forms also keep track of the order when transferring back into CATIA.
6. Another blank user form is shown which is used for testing and ensuring parts will match will new selection of assemblies.
7. Search and select all spec tree's assemblies.
8. Count total assemblies, If text box for "PART NUMBER" does not exist in user form then create one and name the textbox with the part number.
9. Transfer data based on user form one to CATIA spec tree.
I am having problems with #3; It does not populate all the searched assemblies in the loop with the new parameter property "PART NUMBER". Yields the same results every time with different spec tree's.
Similarly, I am having problems with #9, it transfers most of the data from user form's (form 1) text boxes but has the same issue as #3 with transferring to the property parameters in the spec tree.
I appreciate it everyone's input, this is not the most effective code and not complete but trying to get a starting put going :
Option Explicit
'Declare global variables
Dim productDocument1 As ProductDocument
Dim product1 As Product
Dim documents1 As Documents
Dim selection1 As Selection
Dim iAssy As Integer
Dim oAssy As Integer
Dim spacing1 As Integer
Dim textBoxNameAssy As String
Dim createTextBox As Control
Dim parameters1 As Parameters
Dim strName As StrParam
Dim tempAssyFileName As String
Dim tempAssyFileNameShort As String
Sub CatiaDataIn()
'Show form
SpecTree1.Show
'Define global variables
Set documents1 = CATIA.Documents
Set productDocument1 = CATIA.ActiveDocument
Set selection1 = productDocument1.Selection
spacing1 = 20
'***************************************************************************************************************************************************************
'FROM CATIA TO USER FORM
'Search for all assemblies
selection1.Search "CATAsmSearch.Assembly,all"
For iAssy = 1 To selection1.Count
'On Error Resume Next
tempAssyFileName = selection1.Item(iAssy).Value.PartNumber & ".CATProduct"
tempAssyFileNameShort = selection1.Item(iAssy).Value.PartNumber
Set productDocument1 = documents1.Item(tempAssyFileName)
Set product1 = productDocument1.GetItem(tempAssyFileNameShort)
Set parameters1 = product1.UserRefProperties
If product1.Parameters.Item("Properties\PART NUMBER").Name = "" Then
Set strName = parameters1.CreateString("PART NUMBER", "")
strName.ValuateFromString ""
End If
'If text box named with part number does not exist then create new text box with part number
If SpecTree1.Controls(tempAssyFileNameShort) <> tempAssyFileNameShort Then
'Create text box
Set createTextBox = SpecTree1.Controls.Add("Forms.Textbox.1")
With createTextBox
.Name = tempAssyFileNameShort
.Left = 5
.Top = 5 + spacing1
.Width = 140
.Text = tempAssyFileNameShort
End With
spacing1 = spacing1 + 20
End If
Next iAssy
'Clear Selection
selection1.Selection.Clear
'***************************************************************************************************************************************************************
'Search for all parts
'selection1.Search "CATAsmSearch.Part,all"
'MsgBox (selection1.Count)
'Clear Selection
'selection1.Selection.Clear
End Sub
Sub CatiaDataOut()
'Show form
SpecTree2.Show
'Define global variables
Set documents1 = CATIA.Documents
Set productDocument1 = CATIA.ActiveDocument
Set selection1 = productDocument1.Selection
spacing1 = 20
'***************************************************************************************************************************************************************
'FROM USER FORM TO CATIA
'Search for all assemblies
selection1.Search "CATAsmSearch.Assembly,all"
For oAssy = 1 To selection1.Count
'On Error Resume Next
tempAssyFileName = selection1.Item(oAssy).Value.PartNumber & ".CATProduct"
tempAssyFileNameShort = selection1.Item(oAssy).Value.PartNumber
Set productDocument1 = documents1.Item(tempAssyFileName)
Set product1 = productDocument1.GetItem(tempAssyFileNameShort)
'If text box named with part number does not exist then create new text box with part number
If SpecTree2.Controls(tempAssyFileNameShort) <> tempAssyFileNameShort Then
'Create text box
Set createTextBox = SpecTree2.Controls.Add("Forms.Textbox.1")
With createTextBox
.Name = tempAssyFileNameShort
.Left = 5
.Top = 5 + spacing1
.Width = 140
.Text = tempAssyFileNameShort
End With
spacing1 = spacing1 + 20
product1.Parameters.Item("Properties\PART NUMBER").Value = SpecTree1.Controls(tempAssyFileNameShort).Value
End If
Next oAssy
'Clear Selection
selection1.Selection.Clear
End Sub
Here's a challenge that I have been stuck on for quite some time. I am creating a macro to do the following:
1. Blank User form is shown
2. Search and select all spec tree's assemblies.
3. Count total assemblies in selection and creates a "PART NUMBER" parameter property is none exist.
4. If text box for "PART NUMBER" does not exist in user form then create one and name the textbox with the part number.
5. Edits to the part number can be made on the user form. NOTE: The code/user forms also keep track of the order when transferring back into CATIA.
6. Another blank user form is shown which is used for testing and ensuring parts will match will new selection of assemblies.
7. Search and select all spec tree's assemblies.
8. Count total assemblies, If text box for "PART NUMBER" does not exist in user form then create one and name the textbox with the part number.
9. Transfer data based on user form one to CATIA spec tree.
I am having problems with #3; It does not populate all the searched assemblies in the loop with the new parameter property "PART NUMBER". Yields the same results every time with different spec tree's.
Similarly, I am having problems with #9, it transfers most of the data from user form's (form 1) text boxes but has the same issue as #3 with transferring to the property parameters in the spec tree.
I appreciate it everyone's input, this is not the most effective code and not complete but trying to get a starting put going :
Option Explicit
'Declare global variables
Dim productDocument1 As ProductDocument
Dim product1 As Product
Dim documents1 As Documents
Dim selection1 As Selection
Dim iAssy As Integer
Dim oAssy As Integer
Dim spacing1 As Integer
Dim textBoxNameAssy As String
Dim createTextBox As Control
Dim parameters1 As Parameters
Dim strName As StrParam
Dim tempAssyFileName As String
Dim tempAssyFileNameShort As String
Sub CatiaDataIn()
'Show form
SpecTree1.Show
'Define global variables
Set documents1 = CATIA.Documents
Set productDocument1 = CATIA.ActiveDocument
Set selection1 = productDocument1.Selection
spacing1 = 20
'***************************************************************************************************************************************************************
'FROM CATIA TO USER FORM
'Search for all assemblies
selection1.Search "CATAsmSearch.Assembly,all"
For iAssy = 1 To selection1.Count
'On Error Resume Next
tempAssyFileName = selection1.Item(iAssy).Value.PartNumber & ".CATProduct"
tempAssyFileNameShort = selection1.Item(iAssy).Value.PartNumber
Set productDocument1 = documents1.Item(tempAssyFileName)
Set product1 = productDocument1.GetItem(tempAssyFileNameShort)
Set parameters1 = product1.UserRefProperties
If product1.Parameters.Item("Properties\PART NUMBER").Name = "" Then
Set strName = parameters1.CreateString("PART NUMBER", "")
strName.ValuateFromString ""
End If
'If text box named with part number does not exist then create new text box with part number
If SpecTree1.Controls(tempAssyFileNameShort) <> tempAssyFileNameShort Then
'Create text box
Set createTextBox = SpecTree1.Controls.Add("Forms.Textbox.1")
With createTextBox
.Name = tempAssyFileNameShort
.Left = 5
.Top = 5 + spacing1
.Width = 140
.Text = tempAssyFileNameShort
End With
spacing1 = spacing1 + 20
End If
Next iAssy
'Clear Selection
selection1.Selection.Clear
'***************************************************************************************************************************************************************
'Search for all parts
'selection1.Search "CATAsmSearch.Part,all"
'MsgBox (selection1.Count)
'Clear Selection
'selection1.Selection.Clear
End Sub
Sub CatiaDataOut()
'Show form
SpecTree2.Show
'Define global variables
Set documents1 = CATIA.Documents
Set productDocument1 = CATIA.ActiveDocument
Set selection1 = productDocument1.Selection
spacing1 = 20
'***************************************************************************************************************************************************************
'FROM USER FORM TO CATIA
'Search for all assemblies
selection1.Search "CATAsmSearch.Assembly,all"
For oAssy = 1 To selection1.Count
'On Error Resume Next
tempAssyFileName = selection1.Item(oAssy).Value.PartNumber & ".CATProduct"
tempAssyFileNameShort = selection1.Item(oAssy).Value.PartNumber
Set productDocument1 = documents1.Item(tempAssyFileName)
Set product1 = productDocument1.GetItem(tempAssyFileNameShort)
'If text box named with part number does not exist then create new text box with part number
If SpecTree2.Controls(tempAssyFileNameShort) <> tempAssyFileNameShort Then
'Create text box
Set createTextBox = SpecTree2.Controls.Add("Forms.Textbox.1")
With createTextBox
.Name = tempAssyFileNameShort
.Left = 5
.Top = 5 + spacing1
.Width = 140
.Text = tempAssyFileNameShort
End With
spacing1 = spacing1 + 20
product1.Parameters.Item("Properties\PART NUMBER").Value = SpecTree1.Controls(tempAssyFileNameShort).Value
End If
Next oAssy
'Clear Selection
selection1.Selection.Clear
End Sub