Accessing Inventor Host API from rules

Accessing Inventor Host API from rules

intentdesign
Enthusiast Enthusiast
928 Views
2 Replies
Message 1 of 3

Accessing Inventor Host API from rules

intentdesign
Enthusiast
Enthusiast

Rule WriteItemNumber As String Dim InventorApplication = Autodesk.Intent.IntentAPI.Instance.HostAPI.HostApplication Dim RootPart = InventorApplication.ActiveDocument 'GetHostObject(root) Dim oBom = RootPart.ComponentDefinition.BOM 'Dim oBOMView = oBom.BOMViews[1] '<---That doesn't work Dim oBOMView = oBom.BOMViews.Item("Structured") '<---That doesn't work too Dim i As Integer = 0 oBOM.StructuredViewEnabled = True oBOM.StructuredViewFirstLevelOnly = False oBOM.PartsOnlyViewEnabled = False For Each oBomRow In oBOMView.BOMRows oBomRow.ItemNumber = "Test" i=i+1 Next Return Format("%d ItemNumbers are changed",i) End Rule

 I try to modify the Inventor BOM ItemNumber from Intent rules via API. The attached code doesn't work.

Is it possible to do it in this way?

 

Dieter

Reply
Reply
0 Likes
Accepted solutions (1)
929 Views
2 Replies
Replies (2)
Message 2 of 3

colin.mccoy
Alumni
Alumni
Accepted solution

Try

Dim oBOMView = oBom.BOMViews.get_Item("Structured")

Reply
Reply
0 Likes
Message 3 of 3

intentdesign
Enthusiast
Enthusiast

Hi Colin

Thank's for your answer. You gave me the answer that let me find the following solution which works fine.

 

     <%%Category("Positions_Nr")> _
     Rule WriteItemNumber As Any
          Dim InventorApplication = Autodesk.Intent.IntentAPI.Instance.HostAPI.HostApplication
          Dim RootPart = InventorApplication.ActiveDocument 'GetHostObject(root)
          Dim oBom = RootPart.ComponentDefinition.BOM
          Dim Bauteilnummer As String = ""
          oBOM.StructuredViewEnabled = True
          oBOM.StructuredViewFirstLevelOnly = False
          oBOM.PartsOnlyViewEnabled = False
          Dim oBOMView = oBom.BOMViews.get_Item(2)
          Dim oBOMRows = oBOMView.BOMRows
          Dim iRows As Integer = 0
          For i = 1 To oBOMRows.Count Step 1
                Dim oBOMRow = oBOMRows.get_Item(i)
                Bauteilnummer = oBOMRow.ComponentDefinitions.get_Item(1).Document.PropertySets.get_Item(3).get_Item(2).Value
                oBomRow.ItemNumber = getPosNr(Bauteilnummer,Me.Baugruppe_Pos_Nr)
                Dim oChildRows = oBOMRow.ChildRows
                For j = 1  To oChildRows.Count Step 1
                     Dim oChildRow = oChildRows.get_Item(j)
                     Bauteilnummer = oChildRow.ComponentDefinitions.get_Item(1).Document.PropertySets.get_Item(3).get_Item(2).Value
                     oChildRow.ItemNumber = getPosNr(Bauteilnummer,Me.Stanzteil_Pos_Nr)
                     iRows=iRows+1
                Next
          Next
          Return Format("%d Objekt-Nummern wurden überschrieben!",iRows)
     End Rule

Regards

Dieter

Reply
Reply
0 Likes