Sie sind auf Seite 1von 4

FindPartnumber.

vb How to find a partnumber in an Autodesk Inventor Assembly VBA, forms Option Explicit Private Sub cmdExit_Click() Call FormExit End Sub Private Sub FormExit() Me.Hide Unload Me End Sub Private Function isExistingPartNum(pn) As Boolean isExistingPartNum = Not isExistingPartNum End Function Private Sub cmdFind_Click() If txtPartNum.Value = "" Then MsgBox ("Entern number first") Exit Sub End If MsgBox ThisApplication.ActiveDocument.SelectSet.Count ThisApplication.ActiveDocument.SelectSet.Clear Dim oSF As Variant oSF = "509.016.7.2.147-A_Tube1_Left:1" MsgBox ThisApplication.ActiveDocument.SelectSet.Count ThisApplication.ActiveDocument.SelectSet.Select (oSF) MsgBox ThisApplication.ActiveDocument.SelectSet.Count Call FormExit cbxFoundParts.Clear Call BOMQuery1 If cbxFoundParts.ListCount <> 0 Then cmdOpen.Enabled = True cbxFoundParts.Value = cbxFoundParts.List(0) End If End Sub Private Sub cmdOpen_Click() Dim oOccurrence As ComponentOccurrence Set oOccurrence = ThisApplication.ActiveDocument.SelectSet.Select Set oOccurrence = ThisApplication.ActiveDocument.SelectSet.Item Dim oControlDef As ControlDefinition Set oControlDef = ThisApplication.CommandManager.ControlDefinitions.Item("AppFindInBrowserCtxCmd") oControlDef.Execute End Sub Private Sub txtPartNum_Change() If isExistingPartNum(txtPartNum.Value) Then txtPartNum.BackColor = RGB(255, 128, 128) Else txtPartNum.BackColor = vbWindowBackground End If End Sub Private Sub UserForm_Initialize() cmdEdit.Enabled = False cmdOpen.Enabled = False txtPartNum.SetFocus txtAssembly.Value = ThisApplication.ActiveDocument.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value End Sub Public Sub BOMQuery1() ' Set a reference to the assembly document. Pagina 1

FindPartnumber.vb ' This assumes an assembly document is active. Dim oDoc As AssemblyDocument Set oDoc = ThisApplication.ActiveDocument ' Set a reference to the BOM Dim oBOM As BOM Set oBOM = oDoc.ComponentDefinition.BOM ' search in whole assy oBOM.StructuredViewFirstLevelOnly = False ' Make sure that the structured view is enabled. oBOM.StructuredViewEnabled = True 'Set a reference to the "Structured" BOMView Dim oBOMView As BOMView Set oBOMView = oBOM.BOMViews.Item("Structured") 'Initialize the tab for ItemNumber Call QueryBOMRowProperties1(oBOMView.BOMRows) End Sub Private Sub QueryBOMRowProperties1(oBOMRows As BOMRowsEnumerator) ' Iterate through the contents of the BOM Rows. Dim i As Long For i = 1 To oBOMRows.Count ' Get the current row. Dim oRow As BOMRow Set oRow = oBOMRows.Item(i) 'Set a reference to the primary ComponentDefinition of the row Dim oCompDef As ComponentDefinition Set oCompDef = oRow.ComponentDefinitions.Item(1) Dim oPartNumProperty As Property Dim oDescripProperty As Property If TypeOf oCompDef Is VirtualComponentDefinition Then 'Get the file property that contains the "Part Number" 'The file property is obtained from the virtual component definition Set oPartNumProperty = oCompDef.PropertySets _ .Item("Design Tracking Properties").Item("Part Number") 'Get the file property that contains the "Description" Set oDescripProperty = oCompDef.PropertySets _ .Item("Design Tracking Properties").Item("Description") If InStr(oPartNumProperty.Value, txtPartNum.Value) <> 0 Then Debug.Print oPartNumProperty.Value cbxFoundParts.AddItem oPartNumProperty.Value 'oPartNumProperty.Parent.Parent End If ' Tab(30); ' ' Else 'Debug.Print Tab(3); oRow.ItemNumber; Tab(17); oRow.ItemQuantity; _ oPartNumProperty.Value; Tab(70); oDescripProperty.Value Debug.Print oPartNumProperty.Value 'Get the file property that contains the "Part Number" 'The file property is obtained from the parent 'document of the associated ComponentDefinition. Set oPartNumProperty = oCompDef.Document.PropertySets _ .Item("Design Tracking Properties").Item("Part Number") 'SelectSet.Select oCompDef.Document Pagina 2

FindPartnumber.vb 'Get the file property that contains the "Description" Set oDescripProperty = oCompDef.Document.PropertySets _ .Item("Design Tracking Properties").Item("Description") If InStr(oPartNumProperty.Value, txtPartNum.Value) <> 0 Then Debug.Print oPartNumProperty.Value cbxFoundParts.AddItem oPartNumProperty.Value End If ' Tab(30); ' ' 'Debug.Print Tab(3); oRow.ItemNumber; Tab(17); oRow.ItemQuantity; _ oPartNumProperty.Value; Tab(70); oDescripProperty.Value Debug.Print oPartNumProperty.Value

'Recursively iterate child rows if present. If Not oRow.ChildRows Is Nothing Then Call QueryBOMRowProperties1(oRow.ChildRows) End If End If Next End Sub

Sub FindInBrowser() End Sub Dim oControlDef As ControlDefinition Set oControlDef = ThisApplication.CommandManager.ControlDefinitions.Item("AppFindInBrowserCtxC md") oControlDef.Execute End Sub Sub testParam() Dim oDoc As PartDocument Set oDoc = ThisApplication.ActiveDocument Dim oDef As PartComponentDefinition Set oDef = oDoc.ComponentDefinition Dim oFeature As PartFeature Dim oParam As Parameter Dim isOKFeature As Boolean For Each oFeature In oDef.Features isOKFeature = False For Each oParam In oFeature.Parameters Dim oObj As Object For Each oObj In oParam.DrivenBy If TypeOf oObj Is Parameter Then Dim oDrivenParam As Parameter Set oDrivenParam = oObj If oDrivenParam.Name = "myP" Then isOKFeature = True End If End If Next Next If isOKFeature Then MsgBox "this feature is what i need " Pagina 3

FindPartnumber.vb Else MsgBox "this feature is not what i need " End If Next

Pagina 4

Das könnte Ihnen auch gefallen