Message 1 of 10
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
inventor 2022
API with Visual Studio
i try to make a HoleFeature with selecting Surface Body.
I have a PartDocument with 2 Bodies.
I want to make the Holes in Surface Body item(2)
I have a Code, and it works with only with 1 SurfaceBody.
When i have 2 Bodies, than a got Error.
This is the Code for 1 Body:
Imports System.Runtime.InteropServices
Imports Inventor
Imports Microsoft.Win32
Module CommandFunctionButton_06
Public Sub CommandFunctionfweButton_06()
Dim oPartDoc As PartDocument = g_inventorApplication.ActiveDocument
Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
Dim oTO As TransientObjects = g_inventorApplication.TransientObjects
Dim oTG As TransientGeometry = g_inventorApplication.TransientGeometry
Dim oRefComponents As ReferenceComponents = oCompDef.ReferenceComponents
Dim oFace As Face = CType(g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick a Face"), Face)
If oFace IsNot Nothing Then
For Each oEdgeloop As EdgeLoop In oFace.EdgeLoops
If Not oEdgeloop.IsOuterEdgeLoop Then
Dim oEdgeColl As EdgeCollection = oTO.CreateEdgeCollection
For Each oEdge In oEdgeloop.Edges
oEdgeColl.Add(oEdge)
Next
Dim oWorkpoint As WorkPoint = oCompDef.WorkPoints.AddAtCentroid(oEdgeColl)
Dim oWorkAxis As WorkAxis = oCompDef.WorkAxes.AddByNormalToSurface(oFace, oWorkpoint, False)
Dim oWorkPlane As WorkPlane = oCompDef.WorkPlanes.AddByNormalToCurve(oWorkAxis, oWorkpoint, False)
Dim oWorkSketch As PlanarSketch = oCompDef.Sketches.AddWithOrientation(oWorkPlane, oWorkAxis, True, True, oWorkpoint, True)
Dim oHoleCenters As ObjectCollection
oHoleCenters = oTO.CreateObjectCollection
oHoleCenters.Add(oWorkSketch.SketchPoints.Add(oTG.CreatePoint2d(0, 0)))
Dim oHoleFeature As HoleFeature
oHoleFeature = oCompDef.Features.HoleFeatures.AddDrilledByDistanceExtent(oHoleCenters, "10", "15", PartFeatureExtentDirectionEnum.kPositiveExtentDirection, True, )
End If
Next
End If
End Sub
End Module
This is the Code for 2 Bodies:
Imports System.Runtime.InteropServices
Imports Inventor
Imports Microsoft.Win32
Module CommandFunctionButton_05
Public Sub CommandFunctionfweButton_05()
Dim oPartDoc As PartDocument = g_inventorApplication.ActiveDocument
Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
Dim oTO As TransientObjects = g_inventorApplication.TransientObjects
Dim oTG As TransientGeometry = g_inventorApplication.TransientGeometry
Dim oRefComponents As ReferenceComponents = oCompDef.ReferenceComponents
Dim oFace As Face = CType(g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Pick a Face"), Face)
If oFace IsNot Nothing Then
For Each oEdgeloop As EdgeLoop In oFace.EdgeLoops
If Not oEdgeloop.IsOuterEdgeLoop Then
Dim oEdgeColl As EdgeCollection = oTO.CreateEdgeCollection
For Each oEdge In oEdgeloop.Edges
oEdgeColl.Add(oEdge)
Next
Dim oWorkpoint As WorkPoint = oCompDef.WorkPoints.AddAtCentroid(oEdgeColl)
Dim oWorkAxis As WorkAxis = oCompDef.WorkAxes.AddByNormalToSurface(oFace, oWorkpoint, False)
Dim oWorkPlane As WorkPlane = oCompDef.WorkPlanes.AddByNormalToCurve(oWorkAxis, oWorkpoint, False)
Dim oWorkSketch As PlanarSketch = oCompDef.Sketches.AddWithOrientation(oWorkPlane, oWorkAxis, True, True, oWorkpoint, True)
Dim oSurfaceBody2 As SurfaceBody
oSurfaceBody2 = oCompDef.SurfaceBodies.Item(2)
Dim oObjectColl As ObjectCollection
oObjectColl = oTO.CreateObjectCollection
oObjectColl.Add(oSurfaceBody2)
Dim oHoleCenters As ObjectCollection
oHoleCenters = oTO.CreateObjectCollection
oHoleCenters.Add(oWorkSketch.SketchPoints.Add(oTG.CreatePoint2d(0, 0)))
Dim oHoleFeature As HoleFeature
oHoleFeature = oCompDef.Features.HoleFeatures.AddDrilledByDistanceExtent(oHoleCenters, "10", "15", PartFeatureExtentDirectionEnum.kPositiveExtentDirection, True, )
Call oHoleFeature.SetAffectedBodies(oObjectColl)
End If
Next
End If
End Sub
End Module
it dont change the Bodies ?
How to use the oHoleFeature.SetAffectedBodies?
Error: Wrong Parameter
Where is the Problem?
Thanks for any Sugestion
Solved! Go to Solution.