Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

Dimension reference

Status
Not open for further replies.

Santa123

Mechanical
Joined
Oct 2, 2006
Messages
80
Location
PL
Hello,

Could you give me some tips, how can I get to know if dimension (in sketch) is referenced from H or V axis.

Respect
Santa
 
Hi Santa123.

It seems to be able to judge by checking the typename of Constraint.GetConstraintElement (1-3) .Parent.Parent.
In my testing, if there is only one "Axis2D", it is referring to H or V.

Here is the sample code.
(Please try it in the sketch)
Code:
'vba

Option Explicit

Sub CATMain()
    
    Dim selMsg As String
    selMsg = "select dimension"
    
    Dim constraint_obj As constraint
    Dim resultMsg As String
    
    Do
        ' Select Constraint
        Set constraint_obj = SelectItem(selMsg, Array("Constraint"))
        If constraint_obj Is Nothing Then Exit Do
        
        If isReferenced_HorV(constraint_obj) Then
            resultMsg = "Yes"
        Else
            resultMsg = "No"
        End If
        
        MsgBox "referenced from H or V : " & resultMsg
    Loop
    
End Sub

Private Function isReferenced_HorV( _
    ByVal con As constraint) As Boolean
    
    Dim i As Long, ref As Reference
    Dim parenAxis2DCount As Long
    parenAxis2DCount = 0
    
    For i = 1 To 3
        On Error Resume Next
        Set ref = con.GetConstraintElement(i)
        On Error GoTo 0
        If ref Is Nothing Then GoTo continue
        
        If typename(ref.Parent.Parent) = "Axis2D" Then
            parenAxis2DCount = parenAxis2DCount + 1
        End If
continue:
    Next
    
    isReferenced_HorV = IIf(parenAxis2DCount = 1, True, False)

End Function

Private Function SelectItem( _
    ByVal msg$, _
    ByVal filter As Variant) _
    As AnyObject
    
    Dim sel As Variant
    Set sel = CATIA.ActiveDocument.selection
    
    sel.Clear
    Select Case sel.SelectElement2(filter, msg, False)
        Case "Cancel", "Undo", "Redo"
            Exit Function
    End Select
    
    Set SelectItem = sel.Item(1).Value
    sel.Clear
    
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top