Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
'vba
Option Explicit
Sub CATMain()
Dim partDoc As PartDocument
Set partDoc = CATIA.ActiveDocument
Dim pt As Part
Set pt = partDoc.Part
Dim edges As Collection
Set edges = get_vertical_edges(pt)
Dim sel As Selection
Set sel = partDoc.Selection
sel.Clear
Dim edge As Reference
For Each edge In edges
sel.Add edge
Next
MsgBox "Done"
End Sub
Private Function get_vertical_edges( _
ByVal pt As Part _
) As Collection
Dim edges As Collection
Set edges = get_all_edges(pt)
If edges.count < 1 Then
Set get_vertical_edges = edges
Exit Function
End If
Dim meas As Measurable
Set meas = getMeasurable( _
pt, _
pt.OriginElements.PlaneXY _
)
Dim verticalEdges As Collection
Set verticalEdges = New Collection
Dim edge As Reference
For Each edge In edges
If meas.GetAngleBetween(edge) = 90 Then
verticalEdges.Add edge
End If
Next
Set get_vertical_edges = verticalEdges
End Function
Private Function get_all_edges( _
ByVal pt As Part _
) As Collection
Dim partDoc As PartDocument
Set partDoc = pt.Parent
Dim sel As Selection
Set sel = partDoc.Selection
sel.Search "Topology.CGMEdge,all" ',scr"
Dim edges As Collection
Set edges = New Collection
Dim i As Long
For i = 1 To sel.Count2
edges.Add sel.Item2(i).Reference
Next
Set get_all_edges = edges
End Function
Private Function getMeasurable( _
ByVal pt As Part, _
ByVal entity _
) As Measurable
Dim wb, meas As Measurable
Set wb = pt.Parent.GetWorkbench("SPAWorkbench")
Set getMeasurable = wb.getMeasurable(entity)
End Function
'vba
Option Explicit
Private Const TOLERANCE = 0.001
Sub CATMain()
Dim partDoc As PartDocument
Set partDoc = CATIA.ActiveDocument
Dim pt As Part
Set pt = partDoc.Part
Dim msg As String
msg = "Select a plane as a reference plane : ESC key Exit"
Dim planeRef As Reference
Set planeRef = select_item_reference(msg, Array("PlanarFace"))
If planeRef Is Nothing Then Exit Sub
Dim edges As Collection
Set edges = get_vertical_edges(pt, planeRef)
Dim sel As Selection
Set sel = partDoc.Selection
sel.Clear
Dim edge As Reference
For Each edge In edges
sel.Add edge
Next
MsgBox "Done"
End Sub
Private Function get_vertical_edges( _
ByVal pt As Part, _
ByVal planeRef As Reference _
) As Collection
Dim edges As Collection
Set edges = get_all_edges(pt)
If edges.count < 1 Then
Set get_vertical_edges = edges
Exit Function
End If
Dim meas As Measurable
Set meas = get_measurable( _
pt, _
planeRef _
)
Dim verticalEdges As Collection
Set verticalEdges = New Collection
Dim edge As Reference
For Each edge In edges
' Debug.Print (meas.GetAngleBetween(edge))
If Abs(meas.GetAngleBetween(edge) - 90) < TOLERANCE Then
verticalEdges.Add edge
End If
Next
Set get_vertical_edges = verticalEdges
End Function
Private Function get_all_edges( _
ByVal pt As Part _
) As Collection
Dim partDoc As PartDocument
Set partDoc = pt.Parent
Dim sel As Selection
Set sel = partDoc.Selection
sel.Search "Topology.CGMEdge,all" ',scr"
Dim edges As Collection
Set edges = New Collection
Dim i As Long
For i = 1 To sel.Count2
edges.Add sel.Item2(i).Reference
Next
Set get_all_edges = edges
End Function
Private Function get_measurable( _
ByVal pt As Part, _
ByVal ref As Reference _
) As Measurable
Dim wb, meas As Measurable
Set wb = pt.Parent.GetWorkbench("SPAWorkbench")
Set get_measurable = wb.getMeasurable(ref)
End Function
Function select_item_reference( _
ByVal msg As String, _
ByVal filter As Variant _
) As AnyObject
Set select_item_reference = Nothing
Dim sel As Variant 'Selection
Set sel = CATIA.ActiveDocument.Selection
sel.Clear
Select Case sel.SelectElement2(filter, msg, False)
Case "Cancel", "Undo", "Redo"
Exit Function
End Select
Set select_item_reference = sel.Item2(1).Reference
End Function
NaWin55 said:but only few are selecting as vertical edges not all
Vertical for me is Z direction ... or -Z direction that is why you're checking angle with XY plan... you're code is good for this definition.NaWin55 said:Vertical edges in any orientation
NaWin55 said:this edge is vertical wrt axis