Message 1 of 15
hooked on programming - hiding and arraying parts

Not applicable
06-01-2017
07:34 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
See below... I have the parts hiding from my spreadsheet, and I have array working, but I can't figure out how to array the part I just hid, which is probably the best way to do this.
I need to find a book or resource so I better understand these commands and variables, esp. those that apply specifically to running the native inventor tools, vs. just trying different combinations to see what works.
TIA for any assistance
James
Sub BOOM2() Dim oApp As Application Set oApp = ThisApplication Dim oDoc As Document Set oDoc = oApp.ActiveDocument ' Check if user is in part or assembly If oDoc Is Nothing Or TypeOf oDoc Is DrawingDocument Then Exit Sub End If Dim oCompDef As ComponentDefinition ' Get component definition Set oCompDef = oDoc.ComponentDefinition Dim oAssyDef As AssemblyComponentDefinition Set oAssyDef = oDoc.ComponentDefinition 'don't need this? 'Dim oParams As Parameters 'Dim oParam As Parameter ' Get parameters object 'Set oParams = oCompDef.Parameters ' define wsheet variable, etc Dim exapp As Excel.Application Dim wsheet As Excel.WorkSheet Dim part As Excel.Range Dim parts As Excel.Range 'need qty as an integer for now 'Dim qty As Excel.Range Dim qty As Integer Dim qtys As Excel.Range 'could just put "1" straight in, but an artifact of the old code: Dim no_x_rect As Integer no_x_rect = 1 Dim XAxis As WorkAxis Dim YAxis As WorkAxis Dim Zaxis As WorkAxis With oAssyDef Set XAxis = .WorkAxes(1) Set YAxis = .WorkAxes(2) Set Zaxis = .WorkAxes(3) End With 'Dim hider As String Dim pt(2) As Double 'Dim qt(2) As Double Set exapp = CreateObject("Excel.Application") 'this actually works to set the path: Dim sFilePath sFilePath = exapp.GetOpenFilename(FileFilter:="Excel Files (*.xls*),*.xls*", Title:="Select Work Order") 'pop open excel visibly so I know I have the right file and workbook open (for now...) exapp.Visible = True exapp.Workbooks.Open sFilePath Set wsheet = exapp.ActiveSheet 'Selecting ranges - this will get smarter Set parts = wsheet.Range("E2:E87") Set qtys = wsheet.Range("C2:C87") 'temporarily set quantity to get array working automatically qty = 10 parts.Select pt(0) = 0: pt(1) = 0: pt(2) = 0 For Each part In parts 'trying to concatonate, still using a formula in excel to process "K123456" into "123456*". 'hider = "part" & "*" 'this works Call SetVisibility(oDoc.ComponentDefinition.Occurrences, part.Text, False) 'very possible that wildcards will not work to select items for pattern. Also the transientobjects, etc... does not select the 'correct part to array. It's currently part.Text, so the call function needs to be modified so it just arrays what is already set. 'Dim objCol As ObjectCollection ' Set objCol = ThisApplication.TransientObjects.CreateObjectCollection 'objCol.Add oAssyDef.Occurrences.Item(1) Call oAssyDef.OccurrencePatterns.AddRectangularPattern(part.Text, XAxis, True, 10, no_x_rect, YAxis, True, 10, qty) 'I don't understand what this does, seems to be incrementing the for loop to the next cell in the range I created above. 'pt(0) becomes pt(1), 1 becomes 2, and it steps along like that. But how does it know what "pt" is, I did not define it. pt(0) = pt(0) + 1 pt(1) = pt(1) + 1 Next part ' This is a second loop that would pattern random stuff to impressive useless effect... I am trying to incorporate it above. 'qtys.Select 'qt(0) = 0: qt(1) = 0: qt(2) = 0 'For Each qty In qtys 'makes a collection of whatever is in the assembly - I think the first couple of things. Maybe 0, 1. I think changing (1) to (2) 'lets you pick the third item and pattern it, yeah... 'Dim objCol As ObjectCollection ' Set objCol = ThisApplication.TransientObjects.CreateObjectCollection 'objCol.Add oAssyDef.Occurrences.Item(1) 'Call oAssyDef.OccurrencePatterns.AddRectangularPattern(part.Text, XAxis, True, 10, no_x_rect, YAxis, True, 10, qty) 'qt(0) = qt(0) + 1 'qt(1) = qt(1) + 1 'Next qty End Sub ' I believe I need to add what is below in above inside the loop to find subassemblies below the top level to hide or pattern. Private Sub SetVisibility(Occurrences As ComponentOccurrences, SearchName As String, VisibilityOn As Boolean) ' Iterate through each of the occurrences in the collection provided. Dim oOccurrence As ComponentOccurrence For Each oOccurrence In Occurrences ' Check to see if the occurrence name matches the search name. ' The strings are converted to upper case to remove context sensitivity. If UCase(oOccurrence.Name) Like UCase(SearchName) Then ' Check to see if the visibility is different than the specified visiblity. If oOccurrence.Visible <> VisibilityOn Then ' Set the visibility of the occurrence. oOccurrence.Visible = VisibilityOn End If End If ' If this occurrence is a subassembly, recursively call this ' function to traverse through the subassembly. If oOccurrence.DefinitionDocumentType = kAssemblyDocumentObject Then Call SetVisibility(oOccurrence.SubOccurrences, SearchName, VisibilityOn) End If Next End Sub