Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Collect only vertical edges

Status
Not open for further replies.

NaWin55

Mechanical
Mar 21, 2020
97
Hello all

i need to collect only vertical edges from surfaces like this (below image)
Capture_j6uyjt.jpg


i tried one method it worked like 60% but i need to collect only vertical edges regardless of any axis orientation

Thanks
 
Replies continue below

Recommended for you

so by "vertical" you mean... ?...
horizontal/vertical do imply an orientation... ?...

regards,
LWolf
 
only vertical
it is difficult to identify vertical edges regardless of orientation of axis
it it possible to identify edges using Direction vectors or something?
 
Try this.

Code:
'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
 
@kantoku
Thank you for the reply
will try this.
 
@kantoku
i have tried your code it works for default axis orientation
what if axis is rotated in any orientation and edges are in random direction
is there anything i can adjust in your code
please let me know

Thanks
 
this code is not based on any axis orientation but with plan XY as reference.

2023-04-10_17-19-31_fgwvv7.png


You can move the axis, delete it, create few more, this will have no impact on the result.

Eric N.
indocti discant et ament meminisse periti
 
Code:
'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
 
@kantoku
i have tried the new code also but i am not getting proper results
her eis the image
in this i need to select all the vertical edges
new code only worked for some surfaces but not all edges are collecting
Image_kvu5vt.jpg
 
Was the surface created in CATIA?

Why don't you increase the value of "TOLERANCE"?
 
Yes the surfaces are created in catia

i will try increasing the TOLERANCE value
 
0.001 for an angle is very very (very) small.

Remember: default angle unit is degree and default CATIA tolerance to consider 2 lines parallel is 0.5 degree. You can measure angle value at 0.01 or even 0.001 but catia will consider those element parallel.

please adjust your value.

Eric N.
indocti discant et ament meminisse periti
 
i have adjusted the value between 0.01 to 5 but only few are selecting as vertical edges not all

Edges_ogxdov.jpg
 
Without seeing the actual data, it is unlikely that we will be able to determine the cause.
 
what data your referring to
its just in a surface with 4 edges i just want collect Vertical edges in any orientation
i think it is difficult to find out only vertical edges
have to get the orientation of the main axis first and then according to that the vertical edges can be isolated
if the edge is in any orientation then direction vectors will be different for each edge and sorting will become difficult
 
NaWin55 said:
but only few are selecting as vertical edges not all

only few: should i read only the edges with 5deg or less along main Z direction?

not all: this is OK not all edges have angle within the tolerance.

Can you share your file and help us understand which edges you expect to be identified.

NaWin55 said:
Vertical edges in any orientation
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.

Eric N.
indocti discant et ament meminisse periti
 
I will share the reference file soon
I'm traveling now

In simple words if there are surfaces with 4 edges in it then select vertical edges
How to identify particularly this edge is vertical wrt axis is the challenge
 
NaWin55 said:
this edge is vertical wrt axis

This is not what your code is doing now.

If you want to use a given axis, then you have to manage that in your code. From the axis you can get the direction of X, Y or Z using AxisSytem.GetXAxis() that return a [X,Y,Z] of the axis X vector, you create a line using this "vector", then check the angle with your edge...



Eric N.
indocti discant et ament meminisse periti
 
Based on the sample, are you just looking for the longest edges? Could be a different way to filter.
 
what is your definition of vertical?

Eric N.
indocti discant et ament meminisse periti
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor