09/03/2012

Place iAssembly factory in an Assembly document

The following is the sample code which create the iAssemmbly factory. The sample code creates an iAssembly factory using the API method CreateFactory in the assembly file and adds a data from an Excel sheet.

The sample code expects the Arbor_Press assembly file is open before testing the code. Also, it requires references to Microsoft Excel Type Library.

PublicSub CreateiAssemblyFactory()

Dim oDoc AsAssemblyDocument

oDoc = m_inventorApplication.ActiveDocument

Dim odef AsAssemblyComponentDefinition

odef = oDoc.ComponentDefinition

Dim oFactory AsiAssemblyFactory

oFactory = odef.CreateFactory

Dim oWorkSheet As Microsoft.Office. _

Interop.Excel.Worksheet

oWorkSheet = oFactory.ExcelWorkSheet

Dim oCells As Microsoft.Office. _

Interop.Excel.Range

oCells = oWorkSheet.Cells

' Columns...

oCells.Item(1, 2) = "HANDLE CAP:1:Include/Exclude"

oCells.Item(1, 3) = "HANDLE CAP:2:Include/Exclude"

oCells.Item(1, 4) = "LEVER ARM:1:Include/Exclude"

oCells.Item(1, 5) = "Arbor_Frame:1:Grounding Status"

oCells.Item(1, 6) = "d75"

oCells.Item(1, 7) = "d92"

' Row 1 values...

oCells.Item(2, 1) = "Arbor_Press-01"

oCells.Item(2, 2) = "Include"

oCells.Item(2, 3) = "Include"

oCells.Item(2, 4) = "Include"

oCells.Item(2, 5) = "Grounded"

oCells.Item(2, 6) = "0.0 in"

oCells.Item(2, 7) = "180.00000"

' Row 2 values...

oCells.Item(3, 1) = "Arbor_Press-02"

oCells.Item(3, 2) = "Include"

oCells.Item(3, 3) = "Include"

oCells.Item(3, 4) = "Include"

oCells.Item(3, 5) = "Grounded"

oCells.Item(3, 6) = "0.5 in"

oCells.Item(3, 7) = "90.00000"

' Row 3 values...

oCells.Item(4, 1) = "Arbor_Press-03"

oCells.Item(4, 2) = "Exclude"

oCells.Item(4, 3) = "Exclude"

oCells.Item(4, 4) = "Exclude"

oCells.Item(4, 5) = "Ungrounded"

oCells.Item(4, 6) = "0.0 in"

oCells.Item(4, 7) = "180.00000"

Dim oWB As Microsoft.Office.Interop. _

Excel.WorkBook

oWB = oWorkSheet.Parent

oWB.Save()

oWB.Close()

EndSub

The following code shows how to add the occurrences of the created iAssembly factory in to the assembly. Using AddiAssemblyMember method where we can pass the assembly file and the number of rows and columns to add the iAssembly occurrences in the Assembly file.

Comments

The following is the sample code which create the iAssemmbly factory. The sample code creates an iAssembly factory using the API method CreateFactory in the assembly file and adds a data from an Excel sheet.

The sample code expects the Arbor_Press assembly file is open before testing the code. Also, it requires references to Microsoft Excel Type Library.

PublicSub CreateiAssemblyFactory()

Dim oDoc AsAssemblyDocument

oDoc = m_inventorApplication.ActiveDocument

Dim odef AsAssemblyComponentDefinition

odef = oDoc.ComponentDefinition

Dim oFactory AsiAssemblyFactory

oFactory = odef.CreateFactory

Dim oWorkSheet As Microsoft.Office. _

Interop.Excel.Worksheet

oWorkSheet = oFactory.ExcelWorkSheet

Dim oCells As Microsoft.Office. _

Interop.Excel.Range

oCells = oWorkSheet.Cells

' Columns...

oCells.Item(1, 2) = "HANDLE CAP:1:Include/Exclude"

oCells.Item(1, 3) = "HANDLE CAP:2:Include/Exclude"

oCells.Item(1, 4) = "LEVER ARM:1:Include/Exclude"

oCells.Item(1, 5) = "Arbor_Frame:1:Grounding Status"

oCells.Item(1, 6) = "d75"

oCells.Item(1, 7) = "d92"

' Row 1 values...

oCells.Item(2, 1) = "Arbor_Press-01"

oCells.Item(2, 2) = "Include"

oCells.Item(2, 3) = "Include"

oCells.Item(2, 4) = "Include"

oCells.Item(2, 5) = "Grounded"

oCells.Item(2, 6) = "0.0 in"

oCells.Item(2, 7) = "180.00000"

' Row 2 values...

oCells.Item(3, 1) = "Arbor_Press-02"

oCells.Item(3, 2) = "Include"

oCells.Item(3, 3) = "Include"

oCells.Item(3, 4) = "Include"

oCells.Item(3, 5) = "Grounded"

oCells.Item(3, 6) = "0.5 in"

oCells.Item(3, 7) = "90.00000"

' Row 3 values...

oCells.Item(4, 1) = "Arbor_Press-03"

oCells.Item(4, 2) = "Exclude"

oCells.Item(4, 3) = "Exclude"

oCells.Item(4, 4) = "Exclude"

oCells.Item(4, 5) = "Ungrounded"

oCells.Item(4, 6) = "0.0 in"

oCells.Item(4, 7) = "180.00000"

Dim oWB As Microsoft.Office.Interop. _

Excel.WorkBook

oWB = oWorkSheet.Parent

oWB.Save()

oWB.Close()

EndSub

The following code shows how to add the occurrences of the created iAssembly factory in to the assembly. Using AddiAssemblyMember method where we can pass the assembly file and the number of rows and columns to add the iAssembly occurrences in the Assembly file.