Message 1 of 17
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, I have been working on this code for some days now. Been through many forum posts to get me this far and I am nearly there. The last part of the puzzle i am missing is to get the code to ONLY add the virtual components of the files not found in the component.add part of the code. I know i need some kind of if file not found then....and then i also need to change up the part of the code where it is adding the virtual components but i just cant figure it out. I'd be very grateful for any help.
StartRule : ProjectNo = iProperties.Value("Project", "Project") If Trim(ProjectNo) = "" Then 'get value from user and write it to the project iproperty ProjectNo = InputBox("Enter the Project Number", "iLogic", ProjectNo) Else End If Dim sFile As String = "C:\VaultWorkspace\Designs\PROJ Skiold\Personlige\KPK\" & CStr(iProperties.Value("Project", "Project")) & " DK250S Config.xlsx" GoExcel.Open(sFile, "Test") Dim oPNcol = "A" Dim oQTYcol = "B" Dim FirstRow = "2" Dim prevComp, newComp As ManagedComponentOccurrence ' Insert Loop For i As Integer = 0 To 999 Dim Total As Integer Dim val As String = CStr(GoExcel.CellValue(sFile, "Test", oPNcol & (FirstRow + i))) Dim oQTY As String = CStr(GoExcel.CellValue(sFile, "Test", oQTYcol & (FirstRow + i))) Total = oQTY For X = 1 To Total Try 'Dim newComp = Components.Add("", "CO_D" & val & ".ipt", position := Nothing, grounded := False, visible := True, appearance := Nothing) newComp = Components.Add("", "CO_D" & val & ".ipt", position := Nothing, grounded := False, visible := True, appearance := Nothing) Catch VirturalComp = MessageBox.Show("No dummy found for this part, create virtual component? " & CStr(val), "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) If VirturalComp = vbYes Then 'define assembly Dim asmDoc As AssemblyDocument asmDoc = ThisApplication.ActiveDocument 'define assembly Component Definition Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition Dim occs As ComponentOccurrences occs = asmDoc.ComponentDefinition.Occurrences Dim identity As Matrix identity = ThisApplication.TransientGeometry.CreateMatrix Dim MyArrayList As New ArrayList MyArrayList = GoExcel.CellValues(sFile, "Test", "A2", "A200") Dim sVirtPart As String 'get info from the XLS file For MyRow = 2 To 200 'index row 2 through 200 iQTY = GoExcel.CellValue("B" & MyRow) oProp1 = GoExcel.CellValue("A" & MyRow) sVirtPart = oProp1 'defines the virtual part name 'Iterate through all of the occurrences in the assembly Dim asmOcc As ComponentOccurrence For Each asmOcc In oAsmCompDef.Occurrences 'get name of occurence only (sees only everything left of the colon) Dim oOcc As Object oOcc = asmOcc.Name.Split(":")(0) 'look at only virtual components If TypeOf asmOcc.Definition Is VirtualComponentDefinition Then 'compare name selected from list to the 'existing virtual parts If oOcc = sVirtPart Then 'delete existing virtual parts if name matches asmOcc.Delete End If End If Next 'create first instance of the virtual part Dim virtOcc As ComponentOccurrence If iQTY >= 1 Then virtOcc = occs.AddVirtual(sVirtPart, identity) Try iProperties.Value(sVirtPart & ":1", "Project", "Description") = oProp1 Catch 'catch error when oProp1 = nothing End Try Try iProperties.Value(sVirtPart & ":1", "Project", "Part Number") = oProp1 Catch 'catch error when oProp2 = nothing End Try End If 'add next instance starting at instance2 (if applicable) Dim index As Integer index = 2 Do While index <= iQTY occs.AddByComponentDefinition(virtOcc.Definition, identity) index += 1 Loop Next End If End Try Next Next ThisApplication.ActiveView.Fit
Solved! Go to Solution.