Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Current Selection in View Properties 1

Status
Not open for further replies.
Replies continue below

Recommended for you

Hello sriram99,
I think your only option is to use window automation. You can use Microsoft UI Automation framework which gives you programmatic access to most UI elements on the desktop. Here you can find an example of how to connect to a Graph tree reordering window and to simulate user interaction:


However, it is important to access CATIA V5 from an external application like Excel or VB.NET, because if you try to do it from built-in VBA editor, the application becomes unresponsive.


Tesak
- Play Tetris in CATIA V5 drawing
 
Hi Tesak,

Thank you for the suggestion.

My intention is to get the "ViewMakeUp.** of a particular view. ViewMakeUp.** will change for each view.

If I know the ViewMakeUp.** I will use it in text attribute links.

Is there any other way to get it using VBA.



Thnaks,
Sriram
 
Hello sriram99,
I do not know any other way, but maybe others will help you.

To get "current selection" text you can use this code:

Code:
Option Explicit

Sub Main()
    Dim CATIA
    Set CATIA = GetObject(, "CATIA.Application")    ' get CATIA Application
    
    Dim doc
    Set doc = CATIA.ActiveDocument
    
    Dim sel
    Set sel = doc.Selection
    sel.Clear
    sel.Add doc.Sheets.ActiveSheet.Views.ActiveView
    
    CATIA.StartCommand "Properties"
    
    Dim winAutomation As CUIAutomation
    Set winAutomation = New CUIAutomation
    
    Dim desktop As IUIAutomationElement
    ' get reference to the root element (desktop)
    Set desktop = winAutomation.GetRootElement
    
    Dim allWindowsCond As IUIAutomationCondition
    ' retrieves a predefined condition that selects all elements
    Set allWindowsCond = winAutomation.CreateTrueCondition
    
    Dim childs As IUIAutomationElementArray
    ' find all elements & put them into element array
    Set childs = desktop.FindAll(TreeScope_Children, allWindowsCond)
    
    Dim i As Long, currChild As IUIAutomationElement
    Dim catiaWindow As IUIAutomationElement
    
    ' loop through all element and find CATIA by window name which contains "CATIA V5" string
    For i = 0 To childs.Length - 1
        Set currChild = childs.GetElement(i)
        
        If InStr(currChild.CurrentName, "CATIA V5") Then
            Set catiaWindow = currChild ' set main catia window
        End If
        
'        Debug.Print currChild.CurrentName, currChild.CurrentClassName
    Next
    
    Dim propWinCond As IUIAutomationCondition
    Set propWinCond = winAutomation.CreatePropertyCondition(UIA_NamePropertyId, "Properties")
    
    Dim propWin As IUIAutomationElement
    'wait for Graph window to open and get it
    Do
        Set propWin = catiaWindow.FindFirst(TreeScope_Children, propWinCond)
        
        ' do not freeze application in case of infinite loop
        DoEvents
    Loop While propWin Is Nothing
    
    Dim comboCond As IUIAutomationCondition
    Set comboCond = winAutomation.CreatePropertyCondition(UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_ComboBoxControlTypeId)
    
    Dim comboElem As IUIAutomationElement
    Set comboElem = propWin.FindFirst(TreeScope_Descendants, comboCond)
    
    MsgBox comboElem.GetCurrentPropertyValue(UIA_PropertyIds.UIA_ValueValuePropertyId)
End Sub

You have to call it from an external application (e.g. Excel VBA) and you have to reference UIAutomationClient library.

Tesak
- Play Tetris in CATIA V5 drawing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top