Message 1 of 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, i've modify this iLogic macro for my use.
Now the macro compare from an excel file the value of part number in my assembly.
If part match, it write a custom iProp. All works.
But it work on a file name. I need to do it with part number and not the file name. But i don't find the value to get this param.
Can someone help me? Thanks in advance
Sub Main () 'Create variables'set a reference to the assembly component definintion Dim oAssDoc As AssemblyDocument = ThisApplication.ActiveDocument Dim ExcelFullName As String Dim FileName As String Dim oFileDlg As Inventor.FileDialog = Nothing InventorVb.Application.CreateFileDialog(oFileDlg) oFileDlg.InitialDirectory = oOrigRefName oFileDlg.CancelError = True oFileDlg.ShowOpen() If Err.Number <> 0 Then Return ElseIf oFileDlg.FileName <> "" Then ExcelFullName = oFileDlg.FileName End If 'Open Excel database GoExcel.Open(ExcelFullName,"DISTINTA BASE") 'Iterate through each referenced document'Dim oOcc As ComponentOccurrence For Each oDoc As Document In oAssDoc.AllReferencedDocuments ErHa = "Start" Try 'Extract Part Number of active occurrence Dim oPropSet As PropertySet = oDoc.PropertySets.Item("Inventor User Defined Properties") oPartNumber = Left(oDoc.DisplayName, Len(oDoc.DisplayName) - 4) '(Left(oDoc.DisplayName) -4) 'MessageBox.Show(oPartNumber) ErHa = "Define custom property collection" Parameter.UpdateAfterChange = True i = GoExcel.FindRow(ExcelFullName, "DISTINTA BASE", "Part Number", "=", oPartNumber) If i = "-1" GoTo PROSSIMO End If Dim COSTO As String = GoExcel.CurrentRowValue("Unit price €") If String.IsNullOrEmpty(COSTO) Then GetProperty(oPropSet, "Costo").Value = "" Else GetProperty(oPropSet, "Costo").Value = COSTO GetProperty(oPropSet, "Tipo ricambio").Value = "C" End If ErHa = "Update the file" iLogicVb.UpdateWhenDone = True Catch ex As Exception MsgBox("Part: " & oDoc.DisplayName & vbLf & "Code-Part: " & ErHa & vbLf & "Error: " & ex.Message) End Try PROSSIMO: Next 'Close Excel database GoExcel.Close End Sub Private ErHa As String = vbNullString Function GetProperty(oPropset As PropertySet, iProName As String) As Inventor.Property ErHa = "GetProperty: " & iProName Dim iPro As Inventor.Property Try 'Attempt to get the iProperty from the document iPro = oPropset.Item(iProName) Catch 'Assume error means not found, so create it iPro = oPropset.Add("", iProName) End Try Return iPro End Function
This is the function
'Extract Part Number of active occurrence Dim oPropSet As PropertySet = oDoc.PropertySets.Item("Inventor User Defined Properties") oPartNumber = Left(oDoc.DisplayName, Len(oDoc.DisplayName) - 4) '(Left(oDoc.DisplayName) -4)
Danilo "DannyGi" G.
Mechanical design engineer and product developer
Mechanical design engineer and product developer
Solved! Go to Solution.