×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Macro to read value dimension associate at Baloon

Macro to read value dimension associate at Baloon

Macro to read value dimension associate at Baloon

(OP)
Hi all,
I am trying to write a macro with CATScript language that will read and print dimensional values associated with baloons;
attached is the starting situation and I want to get a msgbox that says: Baloon1 Value 50; Baloon2 Value 100; Baloon3 Value Ø25.69
I try to wirte this, but doesn't work:

Sub CATMain()

Dim drawingDocument1 As DrawingDocument
Dim drawingView1 As DrawingView
Dim drawingDimensions1 As DrawingDimensions
Dim drawingDimension1 As DrawingDimension
Dim DrawingDimValue1 As DrawingDimValue
Dim Selection1 As Object
Dim SavedLockStatus As Boolean

Set drawingDocument1 = CATIA.ActiveDocument
Set Selection1 = drawingDocument1.Selection
'Selection1.Search "CATDrwSearch.DrwDimension,all"
Selection1.Search "CATDrwSearch.DrwBalloon,all"

For i = 1 To Selection1.Count2
Set drawingDimension1 = Selection1.Item2(i).Value
Set drawingDimensions1 = drawingDimension1.Parent
Set DrawingDimValue1 = drawingDimension1.GetValue
msgbox DrawingDimValue1.Value
Next
Selection1.Clear

End Sub
Replies continue below

Recommended for you

RE: Macro to read value dimension associate at Baloon

Time has passed, but it looked like fun, so I gave it a try.
Running the following macro will display balloon information referencing the dimensions in the active sheet.

CODE --> vba

'vba

Option Explicit

Private Const tolerance = 0.001

Sub CATMain()

    Dim dDoc As DrawingDocument
    Set dDoc = CATIA.ActiveDocument

    Dim balloon_infos
    balloon_infos = get_balloon_info_referring_dimensions( _
        dDoc, _
        tolerance _
    )

    Dim msg As String
    If IsEmpty(balloon_infos) Then
        msg = "There are no applicable balloons."
    Else
        msg = "Balloon Text : Dimension Values" & _
            vbCrLf & _
            Join(balloon_infos, vbCrLf)
    End If
    
    Debug.Print msg
    MsgBox msg

End Sub


Private Function get_balloon_info_referring_dimensions( _
    ByVal drawDoc As DrawingDocument, _
    ByVal tolerance As Double) _
    As Variant

    get_balloon_info_referring_dimensions = Empty

    Dim balloons As Collection
    Set balloons = get_balloons()
    
    If balloons Is Nothing Then
        Exit Function
    End If

    Dim infos As Collection
    Set infos = New Collection

    Dim balloon As DrawingText
    For Each balloon In balloons

        Dim dims As Collection
        Set dims = get_target_dimensions(balloon)
        If dims Is Nothing Then
            GoTo continue
        End If

        Dim msg As String
        msg = balloon.text & " : "
        msg = msg & get_values_by_dimensions(dims, tolerance)

        infos.Add msg
continue:
    Next

    get_balloon_info_referring_dimensions = lst2ary(infos)

End Function


Private Function get_values_by_dimensions( _
    ByVal dims As Collection, _
    ByVal tolerance As Double) _
    As String

    Dim lst As Collection
    Set lst = New Collection
    
    Dim dimension As DrawingDimension
    For Each dimension In dims
        lst.Add Round(dimension.GetValue().value, tolerance)
    Next

    get_values_by_dimensions = Join(lst2ary(lst), ",")

End Function


Private Function lst2ary( _
    lst As Collection) _
    As Variant

    If lst.count < 1 Then
        lst2ary = Empty
        Exit Function
    End If

    Dim ary() As Variant
    ReDim ary(lst.count - 1)
    
    Dim i As Long
    For i = 1 To lst.count
        ary(i - 1) = lst.Item(i)
    Next

    lst2ary = ary

End Function


Private Function get_target_dimensions( _
    ByVal balloon As DrawingText) _
    As Collection

    If balloon.leaders.count < 1 Then
        Set get_target_dimensions = Nothing
        Exit Function
    End If

    Dim dims As Collection
    Set dims = New Collection

    Dim leader As DrawingLeader
    Dim target As AnyObject
    For Each leader In balloon.leaders
        
        On Error Resume Next
            Set target = leader.HeadTarget
            If target Is Nothing Then
                GoTo continue
            End If
        On Error GoTo 0

        If Not TypeName(target) = "DrawingDimension" Then
            GoTo continue
        End If

        dims.Add target

continue:
    Next
    
    If dims.count < 1 Then
        Set get_target_dimensions = Nothing
    Else
        Set get_target_dimensions = dims
    End If

End Function


Private Function get_balloons() _
    As Collection

    Dim dDoc As DrawingDocument
    Set dDoc = CATIA.ActiveDocument
    
    Dim sel As Selection
    Set sel = dDoc.Selection
    
    CATIA.HSOSynchronized = False
    
    sel.Clear
    sel.Add dDoc.sheets.ActiveSheet
    
    sel.Search "(CAT2DLSearch.DrwBalloon + CATDrwSearch.DrwBalloon),sel"

    If sel.Count2 < 1 Then
        Set get_balloons = Nothing
        Exit Function
    End If

    Dim balloons As Collection
    Set balloons = New Collection
    
    Dim i As Long
    For i = 1 To sel.Count2
        balloons.Add sel.Item(i).value
    Next

    sel.Clear

    CATIA.HSOSynchronized = True

    Set get_balloons = balloons

End Function 

This is the result when the macro is executed.


There is a limit to the number of characters that can be displayed in the MsgBox, so if you have a large number of balloons, it may not be possible to display all of them.

RE: Macro to read value dimension associate at Baloon

(OP)
Thanks a lot for the answer.
However I need the CATScript, but starting from VBA I can also trace the CATScript code.

Thank you very much, great job.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login



News


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close