Message 1 of 8
Ilogic Read values from Excel & update assembly component occurrences
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi Boffins
I am trying to achieve the following from within an Assembly
- For each component occurrence in the assembly (top level assembly, subassemblies, parts) lookup a value in an external excel file (Part Number) that matches the inventor part number
- populate custom properties for the active occurrence which are found in the corresponding excel row
My first stumbling block is an ilogic error message:"Error in rule program format: The rule must contain: Sub Main() ... End Sub" but my code does have these present. I'm sure this is totally simple but I just can't see where the problem lies. Code is below, pieced together with much hair pulling
SyntaxEditor Code Snippet
Sub Main() 'Create variables'set a reference to the assembly component definintion Dim oAssDoc As AssemblyDocument oAssDoc = ThisApplication.ActiveDocument Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition Dim ExcelFullName, FileName As String 'Set Excel database ExcelFullName = ThisDoc.Path & "\" & "Import Files" & "\" & "DB_IMPORT.xlsx" 'Open Excel database GoExcel.Open(ExcelFullName,"Sheet1") 'Iterate through all of the occurrences Dim oOcc As ComponentOccurrence For Each oOcc In oAsmCompDef.Occurrences.AllReferencedOccurrences(oAsmCompDef) Try 'Extract FileName of active occurrence Words = oOcc.FullFileName.Split("\") FileName = Words(UBound(Words)) 'Define Custom property set Dim oPropSet As PropertySet = oDoc.PropertySets.Item("Inventor User Defined Properties") i = GoExcel.FindRow(ExcelFullName, "Sheet1", "Part number", "=", FileName") iProperties.Value("Summary", "Comments") = GoExcel.CurrentRowValue("Comments") GetProperty(oPropSet, "SYBIZ PART No").Value = GoExcel.CurrentRowValue("SYBIZ PART No") GetProperty(oPropSet, "SUPPLYNO").Value = GoExcel.CurrentRowValue("SUPPLYNO") GetProperty(oPropSet, "SUPPLYTYPE").Value = GoExcel.CurrentRowValue("SUPPLYTYPE") GetProperty(oPropSet, "PBLAST").Value = GoExcel.CurrentRowValue("PBLAST") GetProperty(oPropSet, "PPRIME").Value = GoExcel.CurrentRowValue("PPRIME") GetProperty(oPropSet, "PTOPCOAT").Value = GoExcel.CurrentRowValue("PTOPCOAT") GetProperty(oPropSet, "PMACHINE").Value = GoExcel.CurrentRowValue("PMACHINE") GetProperty(oPropSet, "PWELD").Value = GoExcel.CurrentRowValue("PWELD") GetProperty(oPropSet, "PBEND").Value = GoExcel.CurrentRowValue("PBEND") GetProperty(oPropSet, "PINSTALL").Value = GoExcel.CurrentRowValue("PINSTALL") GetProperty(oPropSet, "PASSEMBLE").Value = GoExcel.CurrentRowValue("PASSEMBLE") iLogicVb.UpdateWhenDone = True End Try Next 'Close Excel database GoExcel.Close End Sub 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
Can anyone please help?
Cheers
Bryan