@J_Pfeifer_
See this version of the "chasing" rule. It returns 1 profile... also I updated it to add sketch constraints to be fully constrained.
I'll take a look at the 2nd rule next, but I'd use the chasing method if I were doing this for myself ( for whatever that is worth, since I don't work creating sketches much 🙂)
edit to add: I assume the 2nd version doesn't create a closed profile because there are no sketch constraints (inferred or explicit) placed on the line ends.
Hope that helps.
Sub main
Dim oDoc As PartDocument = ThisApplication.ActiveDocument
Dim oCompDef As PartComponentDefinition = oDoc.ComponentDefinition
Dim oTO As TransientObjects = ThisApplication.TransientObjects
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim Size As Integer = 10 * 2.54
Dim CenterPoint As WorkPoint = oCompDef.WorkPoints.Item("Center Point")
Dim BasePlane As WorkPlane = oCompDef.WorkPlanes.Item("XZ Plane")
Dim oSketch As PlanarSketch = oCompDef.Sketches.Add(BasePlane)
Dim oSketchPoint As SketchPoint = oSketch.AddByProjectingEntity(CenterPoint)
'Use Point2d objects to setup the sketch, or first object.
Dim OriginPoint As Point2d = oTG.CreatePoint2d(0, 0)
Dim BottomRightPoint As Point2d = oTG.CreatePoint2d(OriginPoint.X - Size, OriginPoint.Y)
Dim Line1Bottom As SketchLine = oSketch.SketchLines.AddByTwoPoints(OriginPoint, BottomRightPoint)
'Create the next point
Dim TopRightPoint As Point2d = oTG.CreatePoint2d(Line1Bottom.EndSketchPoint.Geometry.X, Line1Bottom.EndSketchPoint.Geometry.Y - Size)
'Create the second line directly targetting the line object's sketch point.
Dim Line2Right As SketchLine = oSketch.SketchLines.AddByTwoPoints(Line1Bottom.EndSketchPoint, TopRightPoint)
'New point
Dim TopLeftPoint As Point2d = oTG.CreatePoint2d(Line2Right.EndSketchPoint.Geometry.X + Size, Line2Right.EndSketchPoint.Geometry.Y)
'new line targetting pervious end
Dim Line3Top As SketchLine = oSketch.SketchLines.AddByTwoPoints(Line2Right.EndSketchPoint, TopLeftPoint)
'Then finally the last line can target the start point of the first line and the end point of the last line.
Dim Line4Left As SketchLine = oSketch.SketchLines.AddByTwoPoints(Line3Top.EndSketchPoint, Line1Bottom.StartSketchPoint)
'Dimension all the lines
Dim Line1Dim As DimensionConstraint = oSketch.DimensionConstraints.AddTwoPointDistance(Line1Bottom.StartSketchPoint, Line1Bottom.EndSketchPoint, kAlignedDim, oTG.CreatePoint2d(10, 10))
Dim Line2Dim As DimensionConstraint = oSketch.DimensionConstraints.AddTwoPointDistance(Line2Right.StartSketchPoint, Line2Right.EndSketchPoint, kAlignedDim, oTG.CreatePoint2d(20, 20))
oSketch.GeometricConstraints.AddCoincident(oSketchPoint, Line1Bottom.StartSketchPoint)
oSketch.GeometricConstraints.AddHorizontal(Line1Bottom)
oSketch.GeometricConstraints.AddVertical(Line2Right)
oSketch.GeometricConstraints.AddEqualLength(Line1Bottom, Line3Top)
oSketch.GeometricConstraints.AddEqualLength(Line2Right, Line4Left)
'Profile, log and create example extrusion.
Dim SuperProfile As Profile = oSketch.Profiles.AddForSolid
Logger.Info("Profiles within the chasing rule: " & oSketch.Profiles.Count)
Dim ExtrusionExampleDef As ExtrudeDefinition = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(SuperProfile, kNewBodyOperation)
ExtrusionExampleDef.SetDistanceExtent(Size, KnegativeExtentDirection)
Dim ExtrusionExample As ExtrudeFeature = oCompDef.Features.ExtrudeFeatures.Add(ExtrusionExampleDef)
End Sub
