Sketch / Open loop / Redundant Points

Sketch / Open loop / Redundant Points

m_baczewski
Advocate Advocate
346 Views
3 Replies
Message 1 of 4

Sketch / Open loop / Redundant Points

m_baczewski
Advocate
Advocate

Hi,

My problem is that when I add a sketch to the drawing, each line in the sketch is separate, and I can't use the "Hatch the region" operation. I can only achieve this after using the sketch doctor and removing excess points. How can I add such a sketch without creating too many excessive points? Each of these lines is a separate object. How can I connect them together?


m_baczewski_0-1725966185029.png

I adding sketch like that:

 

oSketch.SketchLines.AddByTwoPoints(pointA, pointB)
oSketch.SketchLines.AddByTwoPoints(pointB,pointC)
oSketch.SketchLines.AddByTwoPoints(pointC,pointD)
oSketch.SketchLines.AddByTwoPoints(pointD,pointE)
oSketch.SketchLines.AddByTwoPoints(pointE,pointF)
oSketch.SketchLines.AddByTwoPoints(pointF, pointA)

 

0 Likes
Accepted solutions (1)
347 Views
3 Replies
Replies (3)
Message 2 of 4

Michael.Navara
Advisor
Advisor

It is not clear from your sample, but I expect the variables pointX are of type Point2D. SketchLines.AddByTwoPoints Method accepts Point2D or SketchPoint objects as arguments. Use SketchPoints instead and it will work.

0 Likes
Message 3 of 4

Michael.Navara
Advisor
Advisor
Accepted solution

Sample with generic function for creation of closed lines loop

 

Sub Main()

    'Sketch drawing must be active
    Dim sketch As DrawingSketch = ThisApplication.ActiveEditObject

    Dim linesCollection = CreateClosedPolyLine(sketch,
        ThisApplication.TransientGeometry.CreatePoint2d(0, 0),
        ThisApplication.TransientGeometry.CreatePoint2d(0, 1),
        ThisApplication.TransientGeometry.CreatePoint2d(1, 1),
        ThisApplication.TransientGeometry.CreatePoint2d(1, 2),
        ThisApplication.TransientGeometry.CreatePoint2d(2, 2),
        ThisApplication.TransientGeometry.CreatePoint2d(2, 0)
        )

    Dim profile As Profile = sketch.Profiles.AddForSolid(True, linesCollection)
    sketch.SketchHatchRegions.Add(profile)
End Sub

Function CreateClosedPolyLine(sketch As Sketch, ParamArray points() As Point2d) As ObjectCollection
    If points.Length < 3 Then Throw New ArgumentException("At least three points must be provided")

    Dim lines As ObjectCollection = sketch.Application.transientObjects.CreateObjectCollection()

    Dim line As SketchLine = sketch.SketchLines.AddByTwoPoints(points(0), points(1))
    lines.Add(line)

    Dim startPoint As SketchPoint = line.EndSketchPoint
    Dim lastPoint As SketchPoint = line.StartSketchPoint

    For i As Integer = 2 To points.Length - 1
        line = sketch.SketchLines.AddByTwoPoints(startPoint, points(i))
        lines.Add(line)
        startPoint = line.EndSketchPoint
    Next

    line = sketch.SketchLines.AddByTwoPoints(startPoint, lastPoint)
    lines.Add(line)

    Return lines
End Function

 

 

0 Likes
Message 4 of 4

m_baczewski
Advocate
Advocate
Its working very well. Thanks a lot!
0 Likes