Inventor Engineer-to-Order

Inventor Engineer-to-Order

Reply
Contributor
intentdesign
Posts: 13
Registered: ‎10-06-2012
Message 1 of 3 (258 Views)
Accepted Solution

Accessing Inventor Host API from rules

258 Views, 2 Replies
10-06-2012 02:45 AM

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

Try

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

Employee
colin.mccoy
Posts: 11
Registered: ‎11-03-2011
Message 2 of 3 (252 Views)

Re: Accessing Inventor Host API from rules

10-06-2012 02:30 PM in reply to: intentdesign

Try

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

Contributor
intentdesign
Posts: 13
Registered: ‎10-06-2012
Message 3 of 3 (240 Views)

Re: Accessing Inventor Host API from rules

10-08-2012 03:57 AM 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

Announcements
Manufacturing Community
The Manufacturing Community provides additional access to tips, tutorials, blogs and networking with peers.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.