Here's a program that creates several boundary patches, some of them
triangular, to create a faceted representation of a cone. This is for
Inventor 2008
Public Sub FacetedCone()
' Create a new part document, using the default part template.
Dim oPartDoc As PartDocument
Set oPartDoc = ThisApplication.Documents.Add(kPartDocumentObject, _
ThisApplication.FileManager.GetTemplateFile(kPartDocumentObject))
' Set a reference to the component definition.
Dim oCompDef As PartComponentDefinition
Set oCompDef = oPartDoc.ComponentDefinition
' Create a 3D sketch.
Dim oSketch As Sketch3D
Set oSketch = oCompDef.Sketches3D.Add
' Intialize the variables that control the size of the cone.
Dim dHeight As Double
Dim dRadius As Double
Dim iNumFacets As Integer
dHeight = 6
dRadius = 3
iNumFacets = 12
Dim dPi As Double
dPi = 4 * Atn(1)
Dim oTG As TransientGeometry
Set oTG = ThisApplication.TransientGeometry
' Construct the lines around the based of the cone.
Dim oBaseLines As ObjectCollection
Set oBaseLines = ThisApplication.TransientObjects.CreateObjectCollection
Dim oStartPoint As Object
Dim oNextPoint As Object
Dim i As Integer
For i = 1 To iNumFacets
' Special case for the first point.
If i = 1 Then
Set oStartPoint = oTG.CreatePoint(dRadius, 0, 0)
End If
If i <> iNumFacets Then
' Calculate the next point around the perimeter.
Dim dAngle As Double
dAngle = i * ((dPi * 2) / iNumFacets)
Set oNextPoint = oTG.CreatePoint(dRadius * Cos(dAngle), dRadius
* Sin(dAngle), 0)
Else
' Special case for the last line so it connects to the first
line.
Set oNextPoint = oBaseLines.Item(1).StartSketchPoint
End If
' Create the line and add it to the collection.
Call
oBaseLines.Add(oSketch.SketchLines3D.AddByTwoPoints(oStartPoint, oNextPoint,
False))
' Use the end point of the line just created for the start point of
the next line.
Set oStartPoint = oBaseLines.Item(i).EndSketchPoint
Next
' Draw the apex point.
Dim oApex As SketchPoint3D
Set oApex = oSketch.SketchPoints3D.Add(oTG.CreatePoint(0, 0, dHeight))
' Draw the lines extending from the perimeter to the apex.
Dim oSideLines As ObjectCollection
Set oSideLines = ThisApplication.TransientObjects.CreateObjectCollection
For i = 1 To iNumFacets
Call oSideLines.Add(oSketch.SketchLines3D.AddByTwoPoints(oApex,
oBaseLines.Item(i).StartSketchPoint, False))
Next
' Create a boundary patch for the base.
Dim oPatchDef As BoundaryPatchDefinition
Set oPatchDef =
oCompDef.Features.BoundaryPatchFeatures.CreateBoundaryPatchDefinition
Dim oPatchLoop As BoundaryPatchLoop
Set oPatchLoop = oPatchDef.BoundaryPatchLoops.Add(oBaseLines)
Dim oBoundaryPatch As BoundaryPatchFeature
Set oBoundaryPatch =
oCompDef.Features.BoundaryPatchFeatures.Add(oPatchDef)
' Get the work surface associated with the boundary patch and add it to
a collection
' of all work surfaces.
Dim oPatches As ObjectCollection
Set oPatches = ThisApplication.TransientObjects.CreateObjectCollection
Call oPatches.Add(GetWorkSurface(oBoundaryPatch))
' Create a boundary patch for each triangle around the side.
For i = 1 To iNumFacets
Dim oTriangleLines As ObjectCollection
Set oTriangleLines =
ThisApplication.TransientObjects.CreateObjectCollection
Call oTriangleLines.Add(oBaseLines.Item(i))
Call oTriangleLines.Add(oSideLines.Item(i))
' Special case for the last line.
If i = iNumFacets Then
Call oTriangleLines.Add(oSideLines.Item(1))
Else
Call oTriangleLines.Add(oSideLines.Item(i + 1))
End If
' Create a boundary patch for the triangle.
Set oPatchDef =
oCompDef.Features.BoundaryPatchFeatures.CreateBoundaryPatchDefinition
Set oPatchLoop = oPatchDef.BoundaryPatchLoops.Add(oTriangleLines)
Set oBoundaryPatch =
oCompDef.Features.BoundaryPatchFeatures.Add(oPatchDef)
' Get the work surface associated with the boundary patch and add it
to a collection
' of all work surfaces.
Call oPatches.Add(GetWorkSurface(oBoundaryPatch))
Next
' Create a stitched solid from the surface.
Dim oKnitFeature As KnitFeature
Set oKnitFeature = oCompDef.Features.KnitFeatures.Add(oPatches)
oKnitFeature.Name = "Faceted Cone"
End Sub
--
Brian Ekins
Autodesk Inventor API