You may follow this order to create up to surface extrusion
- Find the sketch regions in the active sketch: ISketch::GetSketchRegions
- Create a planar surface body as the profile of your extrusion. You need to use the curves (sketch segments) of the region as the trimming curve for the planar surface.
- Fin the surface which will intersect with your extrusion (up to surface) through the 2012 SOLIDWORKS API Help - RayIntersections Method (IModelDoc2) unless you need to specify this explicitly.
- Extrude the planar surface: 2015 SOLIDWORKS API Help - Create Temporary Extruded Body Example (VBA)
- Intersect the body with surface via 2012 SOLIDWORKS API Help - Operations2 Method (IBody2) (there are some examples available for this method).
I used this macro as a basis to derive the sketch elements and for each create a trimmed curve:
The process is very very slow though !!!
The scanning of the sketch entity is through iSketch :: GetSketchRegions, to have a continuous loop of entities.
It 'just this way? How can I speed up?
You do not need to traverse all segments rather traverse regions. Just call ISketch::GetSketchRegions
I took your advice, but I do not work the code.
The problem is on CreateTrimmedSheet4 at the end of the code.
Would you help me undestand where I'm wrong?
This is my VB.NET 2010 (sw2015) code:
swApp = CreateObject("SldWorks.Application")
swModelDocExt = swModel.Extension
swPart = swApp.ActiveDoc
swMathUtil = swApp.GetMathUtility
swModeler = swApp.GetModeler
Dim vSketchSeg As Object
DimswSketch As Sketch
swSelMgr = swModel.SelectionManager
swFeat = swSelMgr.GetSelectedObject6(1,-1)
swSketch = swFeat.GetSpecificFeature2
vSketchSeg = swSketch.GetSketchSegments
Dim swSkLine As SketchLine
Dim swSkArc As SketchArc
Dim Myarray As New ArrayList
Dim contourCount As Integer
Dim vSkContours As Object
Dim skContour As SketchContour
Dim closed As Boolean, closedString As String
Dim i As Integer, j As Integer, k As Integer
Dim skSegCount As Long
Dim vSkSegments As Object
Dim skSegment As SketchSegment
Dim skSegType As Long, skSegTypesString As String
vSkContours = swSketch.GetSketchContours()
contourCount = UBound(vSkContours) - LBound(vSkContours) + 1
Debug.Print(contourCount & " Contours in sketch " & swFeat.Name)
Dim regionCount As Integer
Dim vSkRegions As Object
Dim skRegion As SketchRegion
Dim myLoop As Loop2
If Not swSketch Is Nothing Then
regionCount = swSketch.GetSketchRegionCount()
Debug.Print(regionCount & " regions in sketch " & swFeat.Name)
vSkRegions = swSketch.GetSketchRegions()
For i = LBound(vSkRegions) To UBound(vSkRegions)
skRegion = vSkRegions(i)
If Not skRegion Is Nothing Then
Dim startArr(2) As Double
Dim endArr(2) As Double
Dim ptArr(2) As Double
Dim dirArr(2) As Double
ptArr(0) = 0.0#
ptArr(1) = 0.0#
ptArr(2) = 0.0#
dirArr(0) = 0.0#
dirArr(1) = 0.0#
dirArr(2) = 1.0#
startArr(0) = 1.0#
startArr(1) = 0.0#
startArr(2) = 0.0#
swPart = swApp.ActiveDoc
Dim RetVal As Integer
planeSurf = swModeler.CreatePlanarSurface2((ptArr), (dirArr), (startArr))
Dim profileBody As Body2
'HERE THE PROBLEM!!!!
profileBody = planeSurf.CreateTrimmedSheet4((skRegion), False)
RetVal = profileBody.Display3(swPart, 255, swTempBodySelectOptions_e.swTempBodySelectable)
CreateTrimmedSheet4 expects the array of curves (not regions). You need to create this array via the following sequence SketchRegion::GetEdges->IEdge::GetCurve
I have tried to evaluate the curves, but without success. If there are lines and arcs in my sketch is the same thing?
I enclose a 2016 version file to understand how it can be my sketch.
I can not build a loop to create an array of curves trimmed to cut my area.
Thank you very much who can help me.