Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
Im trying to pick certain edges on certain faces that crosses with yz plane. I will chamfer this certain edge. While struggling with codes I asked to gpt for help and we shaped this code together.
Sub Main()
Dim oPDoc As PartDocument = ThisApplication.ActiveDocument
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
Dim Highlighter As HighlightSet = oPDoc.CreateHighlightSet()
Dim foundFace As Face = Nothing
Dim yzPlane As WorkPlane = oPDef.WorkPlanes.Item(2)
For Each oFace As Face In oPDef.SurfaceBodies.Item(1).Faces
Dim faceNormal As UnitVector = oFace.Evaluator.GetNormalAtPoint(oFace.PointOnFace)
If Math.Abs(faceNormal.X) < 0.001 AndAlso Math.Abs(faceNormal.Y) < 0.001 Then
For Each oEdge As Edge In oFace.Edges
Dim startX As Double = oEdge.StartVertex.Point.X
Dim stopX As Double = oEdge.StopVertex.Point.X
If (startX < 0 And stopX > 0) Or (startX > 0 And stopX < 0) Or Math.Abs(startX) < 0.001 Or Math.Abs(stopX) < 0.001 Then
foundFace = oFace
Exit For
End If
Next
If foundFace IsNot Nothing Then Exit For
End If
Next
If foundFace IsNot Nothing Then
Highlighter.AddItem(foundFace)
MsgBox("Face crossing the YZ plane and parallel to the Z-axis found and highlighted.")
Dim topBottomEdges As EdgeCollection = ThisApplication.TransientObjects.CreateEdgeCollection()
For Each oEdge As Edge In foundFace.Edges
Dim zStart As Double = oEdge.StartVertex.Point.Z
Dim zStop As Double = oEdge.StopVertex.Point.Z
If Math.Abs(zStart - zStop) > 0.001 Then
topBottomEdges.Add(oEdge)
End If
Next
If topBottomEdges.Count > 0 Then
Dim chamferDistance As Parameter = oPDef.Parameters.Item("Length_1")
Dim chamferValue As Double = chamferDistance._Value
oPDef.Features.ChamferFeatures.AddUsingDistance(topBottomEdges, chamferValue, False, False, False)
Else
MsgBox("No valid edges found for chamfering.")
End If
Else
MsgBox("No face parallel to the Z-axis and crossing the YZ plane found.")
End If
End Sub
But GPT keeps offering line
Dim faceNormal As UnitVector = oFace.Evaluator.GetNormalAtPoint(oFace.PointOnFace)
However, ilogic gives me error on this line. Probably types didnt match. İs there any solution offer available ? Also is there any other way to chamfer always same edge that crosses with yz plane showed below ?
Solved! Go to Solution.