cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

How to connect to a Creo session from two available session | VBAPI

Ketan_Lalcheta
19-Tanzanite

How to connect to a Creo session from two available session | VBAPI

Hello

 

As we know CCpfcAsyncConnection.Connect would give ambiguity exception if there are more than one Creo session is there. In such case, GetConnectionId will help us to connect to specific Creo session. To get connection ID, we have option to get so by API GetConnectionId. I am having confusion of usage of this API GetConnectionId , i.e. how to use this same API to identify two or three different connection string based on number of active sessions. 

 

Any thought would be helpful as I would like to give option to use end application based on session model name his / her application is going to get connected for automation purpose.

 

Thanks and Regards

KEtan

11 REPLIES 11

extern ProError ProEngineerConnect( char *proe_session_id, char *display,
char *user, char *textpath,
ProBoolean allow_random,
unsigned int timeout_sec,
ProBoolean *random_choice,
ProProcessHandle *p_handle );

I don’t get your point, here you can use the session ID on connect. 

Ketan_Lalcheta
19-Tanzanite
(To:RPN)

Hi

 

We used to pass null string as session ID and it connects to Creo session if there is only one Creo running...

 

However, it fails to connect of there are more than one session. How to know session ID before connecting is my concern.

I know its not much since you most likely know all that is mentioned here, but some info can be found here:

https://creocustomization.com/get-creo-connection-id-using-vb-api/

Not much help to your original question though.

Yeah I tried to get id also from a single Creo session earlier and find what connection string represent... But could not figure out how to create one as required

Because you pass <NULL>, if you pass NULL it will try to connect on the local machine only.

 

You can't expect a Genius if you pass NULL, or you allow random session, then it will connect, but this is random 🙂

 

If everything happen on one machine, write the id on user init to a file, and delete on terminate.

I would write a small socket Server

 

  1. Client ask the Server for a session
  2. Server starts Creo or use running one
  3. Server send the ID back to the Client

It is not that complicated if you do this by writing the data to a file share.

 

 

Ketan_Lalcheta
19-Tanzanite
(To:RPN)

Yeah that is what it should be when we use null as connection id..

 

Yes we have requirement on local machine... But I don't get what you mentioned... I am as a programmer not opening Creo session... It has been opened by application end user without running application... He / she has manually open two sessions before execution of application... So, application don't have connection id of user opened sessions. Now how to connect to one session as we don't have id with us.

MurphyMin
12-Amethyst
(To:RPN)

Hello , i wrote a function via VBA and java, VB  also has the simliar method

 

the process you need to do is records the first Creo's ID, and write it to somewhere, then connect with session by ID, no matter how many Creos you open after that recording, the connection would be right

 

below is the method to write the ID to a file

Public Function writeConnIdInfo(ConnIdInfoPath As String)
 
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set connIdTxt = fso.CreateTextFile(ConnIdInfoPath, True)
    Set asyncConnection = connWithCurCreo()
    externalRep = asyncConnection.GetConnectionId.externalRep
    connIdTxt.WriteLine (externalRep)
    connIdTxt.Close
    Set fso = Nothing
   
End Function

 

 

FV
17-Peridot
17-Peridot
(To:Ketan_Lalcheta)

hi all,

Ketan,

in pro/toolkit - the common way dealing with connection handles is to run a sync app (with auto start) which does nothing other than having user_init(...) writing the connection string (which is an output of ProEngineerConnectIdGet(...)) to a text file at some known location and writing whatever info an async app would use to identify this pro/e session as one which the async app would need to connect to. In the async app, the first order of business would be to scan the known location for files containing a connection string, do some logic to extract the wanted connection string, and to connect to pro/e session with ProEngineerConnect(...) using the extracted connection string as the first argument and using PRO_B_FALSE to disable random connections.

 

The combo ProEngineerConnect(...) -> ProEngineerConnectIdExtract(...) is used in cases when an async app would connect at random Pro/E session at first , do whatever, disconnect and than would need to connect to the same session again. In that scenario the ProProcessHandle output argument would be processed by ProEngineerConnectIdExtract(...) and the connection string would be stored for future use.

HIH.

FV.

 

Ketan_Lalcheta
19-Tanzanite
(To:FV)

This seems good... We do have toolkit license and can be implemented like what you have mentioned... I believe the id fetched from toolkit api and written into text file would work if used by VBAPI session connect... If this is perfect, we are done it seems... 

 

Additionally , if one has no toolkit license and only vbapi is there, is it not at all possible to connect to one session provided more than one session are running by end user before app got started..?

FV
17-Peridot
17-Peridot
(To:Ketan_Lalcheta)

don't know about VB. In case of no pro/toolkit license I would use JLink ( free java otk) for a sync app.

If you don’t care, allow random select. If the app is unlocked you don’t need to take about a TK Lizenz. On top you can execute a remote dll call on the connect session or run a MK, because you run asyn. Just take care that the event loop is not locked by the user. 

Announcements


Top Tags