I've found some codes and i try to mod.
But there is an error when i run the rule
"Impossible to run cast of object type "System.string" on type "Inventor.Propertyset"
How i can fix it?
Thanks
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
'Set Excel database
'present a File Selection dialog
'Dim oFileDlg As Inventor.FileDialog = Nothing
'InventorVb.Application.CreateFileDialog(oFileDlg)
'oFileDlg.InitialDirectory = oOrigRefName
'oFileDlg.CancelError = True
''On Error Resume Next
'oFileDlg.ShowOpen()
'If Err.Number <> 0 Then
'Return
'ElseIf oFileDlg.FileName <> "" Then
'ExcelFullName = oFileDlg.FileName
'End If
ExcelFullName = "C:\Users\danny\Desktop\consumabili.xlsx"
'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 = iProperties.Value("Project", "Part number")
'oSC = oPropSet.Item("Part Number")
'oPN = oPropSet.Item("PART NO")
'oPartNumber = oSC.Value ' & "-" & oPN.Value
'MessageBox.Show(oPartNumber, "Title")
ErHa = "Define custom property collection"
Parameter.UpdateAfterChange = True
i = GoExcel.FindRow(ExcelFullName, "DISTINTA BASE", "Part Number", "=", oPropSet)
Dim PREZZO As String = GoExcel.CurrentRowValue("Unit price €")
If String.IsNullOrEmpty(PREZZO) Then
GetProperty(oPropSet, "Estimated Cost").Value = ""
Else
GetProperty(oPropSet, "Estimated Cost").Value = PREZZO
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
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
Danilo "DannyGi" G.
Mechanical design engineer and product developer