Boundary patch in 2008

Boundary patch in 2008

Anonymous
Not applicable
395 Views
4 Replies
Message 1 of 5

Boundary patch in 2008

Anonymous
Not applicable
I need to create a boundary patch on 3 enclosed lines. (3D Sketch)
Can I do it & does anyone have any code?
0 Likes
396 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
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
0 Likes
Message 3 of 5

Anonymous
Not applicable
Superb!

Many thanks for your help Brian...
0 Likes
Message 4 of 5

Anonymous
Not applicable
Brian,

I tried your sub FacetedCone(), but it fails in my IV2008.


When we try to add the work surface associated with the boundary patch to a collection of all work surfaces VBA generates an error: Undefined function GetWorkSurface:

Call oPatches.Add(GetWorkSurface(oBoundaryPatch))

May you post the code of this function?

ALink
0 Likes
Message 5 of 5

Anonymous
Not applicable
I forgot to include this with the original posting. Here it is.

' Given a feature returns the work surface the feature is part of.
' If it's not part of a work surface it returns Nothing. This is a
' utility function used by the FacetedCone macro.
Private Function GetWorkSurface(Feature As PartFeature) As WorkSurface
' Get the body the feature is part of.
Dim oFeatureBody As SurfaceBody
Set oFeatureBody = Feature.SurfaceBody

' Get the part compdef.
Dim oPartDef As PartComponentDefinition
Set oPartDef = Feature.Parent

' Iterate through the work surfaces to see if any of them define this
body.
Dim oWorkSurface As WorkSurface
For Each oWorkSurface In oPartDef.WorkSurfaces
If oWorkSurface.SurfaceBodies.Item(1) Is oFeatureBody Then
Set GetWorkSurface = oWorkSurface
Exit Function
End If
Next

' No match was found.
Set GetWorkSurface = Nothing
End Function

--
Brian Ekins
Autodesk Inventor API
0 Likes