Managing windows in a session by VBA from excel
I am new in VBA API and so to related it'e objects.
As final result I need to run some mapkey macro in a Model by starting the Macro in an OLE excel fiel inside a Drawing.
For now I need to manage the asynchronous session window as first step.
Solved this problem I need to manage the relation and write some parameters.
So passing directly to the first step, this is my Code to start the asyncConnection (Is there some unnecessary code be patient) :
The first problem is in BOLD.
Public Sub Macro1()
Dim asyncConnection As New pfcls.CCpfcAsyncConnection
Dim cAC As pfcls.IpfcAsyncConnection
Dim session As pfcls.IpfcBaseSession
'Dim descModel As IpfcModelDescriptor
'Dim descModelCreate As CCpfcModelDescriptor
'Dim model As IpfcModel
Dim workDir As String
Dim position As Integer
'Dim Appli As String
Dim mdlname
Dim drwname
Dim a
On Error GoTo RunError
'Get asyncConnection
'======================================================================
Set cAC = asyncConnection.Connect(dbnull, dbnull, dbnull, dbnull)
Set session = cAC.session
'======================================================================
'Get current directory
'Set it as working directory
'======================================================================
workDir = ActiveWorkbook.FullName
position = InStrRev(workDir, "\")
workDir = Left(workDir, position)
session.ChangeDirectory (workDir)
drwname = session.CurrentModel.Filename
MsgBox ("Name: " & drwname)
'======================================================================
'Mapkey to focus on model of the drawing
'======================================================================
session.RunMacro ("mapkey $F9 ~ FocusIn `main_dlg_cur` `proe_win`;" + "mapkey(continued) ~ Select `main_dlg_cur` `PHTLeft.AssyTree` 1 `node0`;" + "mapkey(continued) ~ Trail `UI Desktop` `UI Desktop` `PREVIEW_POPUP_TIMER`" _
+ "mapkey(continued) `main_dlg_w1:PHTLeft.AssyTree:<NULL>`;" + "mapkey(continued) ~ RButtonArm `main_dlg_cur` `PHTLeft.AssyTree` `node0`;" + "mapkey(continued) ~ PopupOver `main_dlg_cur` `ActionMenu` 1 `PHTLeft.AssyTree`;" _
+ "mapkey(continued) ~ Open `main_dlg_cur` `ActionMenu`;~ Close `main_dlg_cur` `ActionMenu`;" + "mapkey(continued) ~ Activate `main_dlg_cur` `OpenModel`;" + "mapkey(continued) ~ Trail `UI Desktop` `UI Desktop` `PREVIEW_POPUP_TIMER` " _
+ "mapkey(continued) `main_dlg_w2:PHTLeft.AssyTree:<NULL>`;~ Command `ProCmdEnvShadedEdges` 1;")
mdlname = session.CurrentModel.Filename
MsgBox ("Name: " & mdlname)
session.RunMacro ("mapkey $F8 @MAPKEY_LABELOFF_H;~ FocusIn `main_dlg_cur` `proe_win`;" + "mapkey(continued) ~ Command `ProCmdDToolsOptim` ;~ Activate `optimization` `OpenStudyTB`;" + "mapkey(continued) ~ Select `seldstudy` `DesignStudyList` 1 `OPTI_OFF_H_1`;" + "mapkey(continued) ~ Activate `seldstudy` `OKButton`;~ Open `optimization` `GoalParameters`;" _
+ "mapkey(continued) ~ Close `optimization` `GoalParameters`;" _
+ "mapkey(continued) ~ Select `optimization` `GoalParameters` 1 `PROJ_DISTANCE:43379`;" _
+ "mapkey(continued) @MANUAL_PAUSENow you mast imput the desidered OFF_H value;" + "mapkey(continued) ~ Arm `optimization` `ConstrTable` 2 `PROJ_DISTANCE:43379 (12)` `Value`;" _
+ "mapkey(continued) ~ Select `optimization` `ConstrTable` 2 `PROJ_DISTANCE:43379 (12)` `Value`;" + "mapkey(continued) @MANUAL_PAUSEOFF_H_1 ?;" _
+ "mapkey(continued) ~ Arm `optimization` `ConstrTable` 2 `PROJ_DISTANCE:43380 (13)` `Value`;" + "mapkey(continued) ~ Select `optimization` `ConstrTable` 2 `PROJ_DISTANCE:43380 (13)` `Value`;" _
+ "mapkey(continued) @MANUAL_PAUSEOFF_H2;" + "mapkey(continued) ~ Arm `optimization` `ConstrTable` 2 `PROJ_DISTANCE:43381 (14)` `Value`;" _
+ "mapkey(continued) ~ Select `optimization` `ConstrTable` 2 `PROJ_DISTANCE:43381 (14)` `Value`;" + "mapkey(continued) @MANUAL_PAUSEOFF_H_3;" _
+ "mapkey(continued) ~ Arm `optimization` `ConstrTable` 2 `PROJ_DISTANCE:43382 (15)` `Value`;" _
+ "mapkey(continued) ~ Select `optimization` `ConstrTable` 2 `PROJ_DISTANCE:43382 (15)` `Value`;" _
+ "mapkey(continued) @MANUAL_PAUSEOFF_H_4;" + "mapkey(continued) ~ Arm `optimization` `ConstrTable` 2 `PROJ_DISTANCE:43383 (16)` `Value`;" + "mapkey(continued) ~ Select `optimization` `ConstrTable` 2 `PROJ_DISTANCE:43383 (16)` `Value`;" + "mapkey(continued) @MANUAL_PAUSEOFF_H_5;" + "mapkey(continued) ~ Arm `optimization` `ConstrTable` 2 `PROJ_DISTANCE:43384 (17)` `Value`;" + "mapkey(continued) ~ Select `optimization` `ConstrTable` 2 `PROJ_DISTANCE:43384 (17)` `Value`;" + "mapkey(continued) @MANUAL_PAUSEOFF_H_6;" + "mapkey(continued) @MANUAL_PAUSENow the calculation is starting, it take about 15 seconds, be " + "mapkey(continued) patient.;~ Activate `optimization` `ComputeTB`;" + "mapkey(continued) ~ Open `optimization` `GoalParameters`;" + "mapkey(continued) ~ Close `optimization` `GoalParameters`;" + "mapkey(continued) ~ Select `optimization` `GoalParameters` 1 `PROJ_DISTANCE:43380`;" _
+ "mapkey(continued) ~ Activate `optimization` `ComputeTB`;~ Open `optimization` `GoalParameters`;" _
+ "mapkey(continued) ~ Close `optimization` `GoalParameters`;" _
+ "mapkey(continued) ~ Select `optimization` `GoalParameters` 1 `PROJ_DISTANCE:43381`;" _
+ "mapkey(continued) ~ Activate `optimization` `ComputeTB`;~ Open `optimization` `GoalParameters`;" _
+ "mapkey(continued) ~ Close `optimization` `GoalParameters`;" _
+ "mapkey(continued) ~ Select `optimization` `GoalParameters` 1 `PROJ_DISTANCE:43382`;" _
+ "mapkey(continued) ~ Activate `optimization` `ComputeTB`;~ Open `optimization` `GoalParameters`;" _
+ "mapkey(continued) ~ Close `optimization` `GoalParameters`;" _
+ "mapkey(continued) ~ Select `optimization` `GoalParameters` 1 `PROJ_DISTANCE:43383`;" _
+ "mapkey(continued) ~ Activate `optimization` `ComputeTB`;~ Open `optimization` `GoalParameters`;" _
+ "mapkey(continued) ~ Close `optimization` `GoalParameters`;" _
+ "mapkey(continued) ~ Select `optimization` `GoalParameters` 1 `PROJ_DISTANCE:43384`;" _
+ "mapkey(continued) ~ Activate `optimization` `ComputeTB`;~ Close `graph_wnd` `graph_wnd`;" _
+ "mapkey(continued) ~ Activate `optimization` `CloseButton`;~ Activate `ds_exit` `OKButton`;")
'======================================================================
'Now I should go back to drawing and disconnect but I am unable to manage in any way the Focus/Activation of any session window.
'======================================================================
a = session.ListWindows()
MsgBox ("Name: " & a)
'======================================================================
'End the Creo Parametric session when done
'======================================================================
RunError:
If Err.Number <> 0 Then
MsgBox "Process Failed : Unknown error occurred." + Chr(13) + _
"Error No: " + CStr(Err.Number) + Chr(13) + _
"Error: " + Err.Description, vbCritical, "Error"
If Not conn Is Nothing Then
If conn.IsRunning Then
conn.Disconnect (2)
End If
End If
End If
End Sub
This thread is inactive and closed by the PTC Community Management Team. If you would like to provide a reply and re-open this thread, please notify the moderator and reference the thread. You may also use "Start a topic" button to ask a new question. Please be sure to include what version of the PTC product you are using so another community member knowledgeable about your version may be able to assist.

