To make a part into an iPart, you use the CreateFactory method of the PartComponentDefinition. The iPartFactory returned by the call to CreateFactory does have a TableRows collection but it does not have an Add method and the way to add the rows that you need for your iPart, may not be obvious.
My colleague Philippe Leefsma has this example that shows what needs to be done. It uses the Excel Spreadsheet returned from the ExcelWorkSheet property of the iPartFactory to create the table used to define the functionality of the iPart. In this visual studio project you will find the CreateiPart Sub Procedure and a couple of other procedures. One adds a new row to the iPart and the other prints the contents of the table to the immediate window.
Public Sub CreateiPart()
Dim oPartDoc As PartDocument
oPartDoc = _InvApplication.Documents.Add _
(DocumentTypeEnum.kPartDocumentObject, _
_InvApplication.FileManager.GetTemplateFile _
(DocumentTypeEnum.kPartDocumentObject), _
True)
oPartDoc.SaveAs _
("c:\Temp\iPart_By_API.ipt", False)
Dim oTG As TransientGeometry
oTG = _InvApplication.TransientGeometry
Dim oCompDef As PartComponentDefinition
oCompDef = oPartDoc.ComponentDefinition
Dim oPoints(3) As Point2d
oPoints(0) = oTG.CreatePoint2d(0, 0)
oPoints(1) = oTG.CreatePoint2d(5, 0)
oPoints(2) = oTG.CreatePoint2d(5, 5)
oPoints(3) = oTG.CreatePoint2d(0, 5)
Dim oSketch As PlanarSketch
oSketch = oCompDef.Sketches.Add _
(oCompDef.WorkPlanes(1))
Dim oLines(3) As SketchLine
oLines(0) = _
oSketch.SketchLines.AddByTwoPoints _
(oPoints(0), oPoints(1))
oLines(1) = _
oSketch.SketchLines.AddByTwoPoints _
(oLines(0).EndSketchPoint, oPoints(2))
oLines(2) = _
oSketch.SketchLines.AddByTwoPoints _
(oLines(1).EndSketchPoint, oPoints(3))
oLines(3) = _
oSketch.SketchLines.AddByTwoPoints _
(oLines(2).EndSketchPoint, _
oLines(0).StartSketchPoint)
Dim oProfile As Profile
oProfile = oSketch.Profiles.AddForSolid
Dim oExtrude As ExtrudeFeature
oExtrude = oCompDef.Features. _
ExtrudeFeatures.AddByDistanceExtent _
(oProfile, 15, _
PartFeatureExtentDirectionEnum. _
kPositiveExtentDirection, _
PartFeatureOperationEnum. _
kNewBodyOperation, 0)
oExtrude.FeatureDimensions(1). _
Parameter.Name = "Length"
oExtrude.FeatureDimensions(2). _
Parameter.Name = "TaperAngle"
Dim oFactory As iPartFactory
oFactory = oCompDef.CreateFactory
Dim oWS As _
Microsoft.Office.Interop.Excel.Worksheet
oWS = oFactory.ExcelWorkSheet
oWS.Cells(1, 1) = _
"Member<defaultRow>1</defaultRow><filename></filename>"
oWS.Cells(1, 2) = "Part Number [Project]"
oWS.Cells(1, 3) = "Length<free>150 mm</free>"
oWS.Cells(1, 4) = "TaperAngle"
oWS.Cells(2, 1) = "iPart_By_API-01"
oWS.Cells(2, 2) = "iPart_By_API-01"
oWS.Cells(2, 3) = "150 mm"
oWS.Cells(2, 4) = "0 deg"
oWS.Cells(3, 1) = "iPart_By_API-02"
oWS.Cells(3, 2) = "iPart_By_API-02"
oWS.Cells(3, 3) = "100 mm"
oWS.Cells(3, 4) = "5 deg"
oWS.Cells(4, 1) = "iPart_By_API-03"
oWS.Cells(4, 2) = "iPart_By_API-03"
oWS.Cells(4, 3) = "50 mm"
oWS.Cells(4, 4) = "10 deg"
Dim oWB As _
Microsoft.Office.Interop.Excel.Workbook
oWB = oWS.Parent
oWB.Save()
oWB.Close()
oPartDoc.Update()
oPartDoc.Save()
End Sub
Wayne Brill


Subscribe