Inventor Engineer-To-Order (Read-Only)
Welcome to Autodesk’s Inventor ETO Forums. Share your knowledge, ask questions, and explore popular Inventor ETO topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Accessing Inventor Host API from rules

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
intentdesign
696 Views, 2 Replies

Accessing Inventor Host API from rules


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

2 REPLIES 2
Message 2 of 3
colin.mccoy
in reply to: intentdesign

Try

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

Message 3 of 3
intentdesign
in reply to: colin.mccoy

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report