我一直试图在草图中的两条线之间创建一个角落,但我找不到任何命令。
有没有办法在两行之间创建一个角落?
提前致谢!!
答案 0 :(得分:0)
接受挑战!!!
语言= vb.net
假设线不交叉(但可以相互接触)
假设oPart已定义为
部分假设hb1已定义为GeometricalSet
假设BasePlane已经定义为草图平面
假设oSel已选择已定义的ActiveDocument
假设spa已经定义为SPAWorkbench = CATIA.ActiveDocument.GetWorkbench(" SPAWorkbench")
Public Sub Test()
Dim oSke As Sketch = hb1.HybridSketches.Add(BasePlane)
Dim f2D As Factory2D = oSke.OpenEdition()
Try
Dim lc1 As Line2D = f2D.CreateLine(0, 0, 0, 10)
Dim lc2 As Line2D = f2D.CreateLine(20, 0, 10, 10)
DrawCornerWithoutTrim(oSke, f2D, lc1, lc2, 5)
Catch ex As Exception
Debug.Print(ex.ToString())
Finally
oSke.CloseEdition()
End Try
oPart.UpdateObject(oSke)
End Sub
Public Sub DrawCornerWithoutTrim(oSke As Sketch, f2D As Factory2D,
Line1 As Line2D, Line2 As Line2D,
Radius As Double)
Dim c1(1), c2(1)
Dim b1(1), b2(1)
Dim vRef = spa.GetMeasurable(Line1).GetMinimumDistance(Line2)
Dim refPoint1 As Point2D
Dim refPoint2 As Point2D
Dim C As Constraint
Line1.StartPoint.GetCoordinates(c1)
Line1.EndPoint.GetCoordinates(c2)
Line2.StartPoint.GetCoordinates(b1)
Line2.EndPoint.GetCoordinates(b2)
If Math.Round(spa.GetMeasurable(Line1.StartPoint).GetMinimumDistance(Line2.StartPoint) - vRef, 4) = 0 Then
refPoint1 = Line1.StartPoint
refPoint2 = Line2.StartPoint
ElseIf Math.Round(spa.GetMeasurable(Line1.StartPoint).GetMinimumDistance(Line2.EndPoint) - vRef, 4) = 0 Then
refPoint1 = Line1.StartPoint
refPoint2 = Line2.EndPoint
ElseIf Math.Round(spa.GetMeasurable(Line1.EndPoint).GetMinimumDistance(Line2.StartPoint) - vRef, 4) = 0 Then
refPoint1 = Line1.EndPoint
refPoint2 = Line2.StartPoint
ElseIf Math.Round(spa.GetMeasurable(Line1.EndPoint).GetMinimumDistance(Line2.EndPoint) - vRef, 4) = 0 Then
refPoint1 = Line1.EndPoint
refPoint2 = Line2.EndPoint
End If
c1(0) = (c1(0) + b1(0) + c2(0) + b2(0)) / 4
c1(1) = (c1(1) + b1(1) + c2(1) + b2(1)) / 4
Dim Fix1 As Constraint = oSke.Constraints.AddMonoEltCst(catCstTypeReference, Line1)
Dim Fix2 As Constraint = oSke.Constraints.AddMonoEltCst(catCstTypeReference, Line2)
Dim CenterPoint As Point2D = f2D.CreatePoint(c1(0), c1(1))
CenterPoint.Construction = True
C = oSke.Constraints.AddBiEltCst(catCstTypeDistance, CenterPoint, Line1)
C.Dimension.Value = Radius
C = oSke.Constraints.AddBiEltCst(catCstTypeDistance, CenterPoint, Line2)
C.Dimension.Value = Radius
CenterPoint.GetCoordinates(c1)
Dim Arc As Circle2D = f2D.CreateCircle(c1(0), c1(1), Radius, 0, 1)
C = oSke.Constraints.AddMonoEltCst(catCstTypeRadius, Arc)
C.Dimension.Value = Radius
C = oSke.Constraints.AddBiEltCst(catCstTypeTangency, Arc, Line1)
C = oSke.Constraints.AddBiEltCst(catCstTypeTangency, Arc, Line2)
Dim ct1 As Constraint = oSke.Constraints.AddBiEltCst(catCstTypeOn, Arc.StartPoint, Line1)
Dim ct2 As Constraint = oSke.Constraints.AddBiEltCst(catCstTypeOn, Arc.EndPoint, Line2)
If spa.GetMeasurable(Arc).Length > 3.14 * Radius Then
Change = True
osel.Clear()
osel.Add(ct1)
osel.Add(ct2)
osel.Delete()
ct1 = oSke.Constraints.AddBiEltCst(catCstTypeOn, Arc.EndPoint, Line1)
ct2 = oSke.Constraints.AddBiEltCst(catCstTypeOn, Arc.StartPoint, Line2)
End If
osel.Clear()
osel.Add(Fix1)
osel.Add(Fix2)
osel.Delete()
End Sub