Hi Rikard,
Please find a sample code to stitch a component.
Public Sub StitchFeatureCreate()
' Create a new part document, using the default part template.
Dim oPartDoc As PartDocument
oPartDoc = mApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject,
mApp.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject))
' Set a reference to the component definition.
Dim oCompDef As PartComponentDefinition
oCompDef = oPartDoc.ComponentDefinition
' Create a new sketch on the X-Y work plane. Dim oSketch As PlanarSketch
Dim oSketch As PlanarSketch
oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes(3))
' Set a reference to the transient geometry object.
Dim oTransGeom As TransientGeometry
oTransGeom = mApp.TransientGeometry
' Draw two sketch lines that will be used as the
' open profiles for creating work surfaces.
Dim oLineOne As SketchLine
oLineOne = oSketch.SketchLines.AddByTwoPoints(
oTransGeom.CreatePoint2d(0, 0),
oTransGeom.CreatePoint2d(2, -2))
Dim oLineTwo As SketchLine
oLineTwo = oSketch.SketchLines.AddByTwoPoints(
oTransGeom.CreatePoint2d(0, 0),
oTransGeom.CreatePoint2d(-2, -2))
' Create a profile for the first extrude.
Dim oProfileOne As Profile
oProfileOne = oSketch.Profiles.AddForSurface(oLineOne)
' Create an surface extrusion 2 cm thick.
Dim oExtrudeDef As ExtrudeDefinition
oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfileOne, PartFeatureOperationEnum.kSurfaceOperation)
Call oExtrudeDef.SetDistanceExtent(2, PartFeatureExtentDirectionEnum.kNegativeExtentDirection)
Dim oExtrudeOne As ExtrudeFeature
oExtrudeOne = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef)
' Create a profile for the second extrude.
Dim oProfileTwo As Profile
oProfileTwo = oSketch.Profiles.AddForSurface(oLineTwo)
' Create an extrusion 2 cm thick.
oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfileTwo, PartFeatureOperationEnum.kSurfaceOperation)
Call oExtrudeDef.SetDistanceExtent(2, PartFeatureExtentDirectionEnum.kNegativeExtentDirection)
Dim oExtrudeTwo As ExtrudeFeature
oExtrudeTwo = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef)
Dim oSurfaces As ObjectCollection
oSurfaces = mApp.TransientObjects.CreateObjectCollection
' Since we know that the only work surfaces in the document
' are those created by the above extrusions, use those.
oSurfaces.Add(oCompDef.WorkSurfaces.Item(1))
oSurfaces.Add(oCompDef.WorkSurfaces.Item(2))
' Create a stitch (knit) feature by stitching
' together the two work surfaces created above.
Dim oKnitFeature As KnitFeature
oKnitFeature = oCompDef.Features.KnitFeatures.Add(oSurfaces)
End Sub
In order to add a knitfeature, "Add" method requires object collection of surfaces. But in attached sample assembly, surfaces are solidbody surfaces. It fails to stitch the surfaces.
Manually, I tried to stitch surfaces on main part(CopyObject1). unable to select either of (CopyObject2_1) or (CopyObject2_2).
Thanks and regards,
CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network