I am working on a macro feature that uses a sketch to to create a kind of custom extrude cut with some extra features but am having trouble with being able get the underlying curves of the sketch. I can do everything I need to use a temporary body to cut the work body except make the body from a sketch
My approach for making the temporary body from a sketch is this:
Get All ISketchSegment of selected sketch
Get ICurve of each ISketchSegment and put into and array
Use a Transfrorm to move the ICurve from sketch coordinates Into model space coordinates
Get ISurface of the IFace2 the selected ISketch is on (or make a copy of it using ISurface::Copy?)
Use ISurface::CreateTrimmedSheet4 to create a sheet body
The problem I am having is that all the curves from sketches are are 2000 meters long for some reason. They are all in the right place though. I am testing it on a simple 86 in. by 36 in. rectangle.I have never used CreateTrimmedSheet4 before but I'm guessing there needs to be closed curves for it to work. I also have no idea how this would behave if there were multiple closed chains in the sketch. The sketch and SurFace are gotten from the regeneration function of the macro feature.
Function CreateCutBody(sketch As SldWorks.sketch, SurFace As SldWorks.Face2) As SldWorks.Body2()
Dim swSurf As SldWorks.SurFace
Dim SktXForm As SldWorks.MathTransform
Dim swSktSeg As SldWorks.SketchSegment
Dim swCurve() As SldWorks.Curve
Dim WrieBody() As SldWorks.Body2
Dim vRetBods As Variant
Dim vSeg As Variant
Dim vCur As Variant
Dim i As Integer
On Error GoTo errH
Set swSurf = SurFace.GetSurface
Set SktXForm = swSketch.ModelToSketchTransform
vSeg = sketch.GetSketchSegments
ReDim swCurve(UBound(vSeg))
ReDim WrieBody(UBound(vSeg))
For i = 0 To (UBound(vSeg))
Set swSktSeg = vSeg(i)
Set swCurve(i) = swSktSeg.GetCurve
swCurve(i).ApplyTransform SktXForm
Set WrieBody(i) = swCurve(i).CreateWireBody
WrieBody(i).Display3 swPart, 255, 1
Next i
Set vRetBods = swSurf.CreateTrimmedSheet4(swCurve, False)
CreateCutBody = vRetBods
Exit Function
errH: Debug.Print "CreateCutBody Error: " & Err.Description
End Function
100% Working!
CutSktFeat is the feature holding the sketch, SelFace is the selected face, and EditBody is the body the cut extrude is being applied to.
The trick to this one is lines 71 and 72. The Extrude depth is an arbitrary 6 meters.