Continue to Site

Welcome to MCAD Central

Join our MCAD Central community forums, the largest resource for MCAD (Mechanical Computer-Aided Design) professionals, including files, forums, jobs, articles, calendar, and more.

Creo VB api example:ADD Button to creo

Lourens

New member
Hi I havea vb program connecting to Creo Session.I use this program to update Creo Session parameters. I would like to add a button to Creo interface so that I could launch my vb program. I've tried the Add Button function in VB API Example installed with Creo. When I click the "Add Button" button I get an pfcException::XToolkitNotFound error. Basically it fails here:


'=========================================================== ===========


'Command is created which will be associated with the button. The class


'implementing the actionlistener must be given as input.


'=========================================================== ===========


buttonListener = New GatherInputListener()


inputCommand = aC.Session.UICreateCommand("INPUT", buttonListener)





I have installed the the Creo Toolkit with Creo so I don't think that is the problem. Can anybody maybe help me to try an create a listener button in Creo for opening my vb Program?


Thanks
 
You will need to make sure text directory pth is specfied while connecting to the ProE session.Also given name(INPUT) is specified in the text file.Failed to find either of this exception will be thrown similar to what you are getting.
 
Thanks but I'm not realy sure what you mean with text directory pth?Where do you set it?


The problem seems to be at the following line of code:


sessions.UIAddMenu("VB-Async", "Windows", "pfcAsynchronousModeExamples.txt", Nothing)


I've found the text file "pfcAsynchronousModeExamples.txt" but how does Sub UIAddMenu know where pfcAsynchronousModeExamples.txt is located? should I place it in the text folder? How do I specify the name(Input) in the textfile "pfcAsynchronousModeExamples.txt"?


Thanks for the help
 
Text directory should have the .txt file , this text file
contains messages ,name of menu items etc...
While connecting to existing ProE session using VB API ,
text directory path should be provided as a input argument
to the Session.Connect() API.
 
Hi thanks milindb . Think I'm getting there.


The following is in place:


txtWD.Text = "C:\Program Files\PTC\Creo 1.0\Common Files\M020\text"


pfcAsynchronousModeExamples.txt is inside the text directory


The Following exists in the pfcAsynchronousModeExamples.txt file: #
#
VB-Async
VB-Async
#
#
USER#Async#App
Async Button
#
#
USER#Async#Help
Button added via Async Application
#
#
USER#Exit#Listener
Exit


VB Listener
#
#
USER#Exit#Help
Button added to exit Session Listener.
#
#
USER Error: %0s of code %1s at %2s
Error: %0s of code


%1s at %2s
#
#


How do I specify name(INPUT) on this text file?


Hopefully this is the last outstanding issue. Thanks for the help
 
Append following lines to the text file..


INPUT


Enter Input


#


#


Forum Editor is adding multiple spaces in between , this shoudl be continues text each of them on new line.
Edited by: milindb
 
My Text file looks like this now but I still get the Tookit error at sessions.UIAddMenu("VB-Async", "Windows", "pfcAsynchronousModeExamples.txt", Nothing).:


#
#
VB-Async
VB-Async
#
#
USER#Async#App
Async Button
#


INPUT


Enter Input


#
#
USER#Async#Help
Button added via Async Application
#
#
USER#Exit#Listener
Exit VB Listener
#
#
USER#Exit#Help
Button added to exit Session Listener.
#
#
USER Error: %0s of code %1s at %2s
Error: %0s of code %1s at %2s
#
#


could you please verify that the text file correct?





Thanks
 
exePath is the following:


"C:\Program Files\PTC\Creo 1.0\Parametric\bin\parametric.exe"


workDir is the following:


"C:\Program Files\PTC\Creo 1.0\Common Files\M020\text"


When I run the following Sub Procedure ProE Starts up fine via startProE(exePath, workDir).


Private Sub startProE(ByVal exePath As String, ByVal workDir As String)


asyncConnection = (New CCpfcAsyncConnection).Start(exePath, "C:\Program Files\PTC\Creo 1.0\Common Files\M020\text")


asyncConnection.Session.ChangeDirectory(System.Environment.C urrentDirectory)


End Sub


The addTerminationListener() procedure alsoe executes fine


The problem is in addMenuAndButton() where my code fails at sessions.UIAddMenu("VB-Async", "Windows", "pfcAsynchronousModeExamples.txt", Nothing)


Public Sub New(ByVal exePath As String, ByVal workDir As String)


Try


startProE(exePath, workDir)


addTerminationListener()


addMenuAndButton()


asyncConnection.WaitForEvents()


Catch ex As Exception


MsgBox(ex.Message.ToString + Chr(13) + ex.StackTrace.ToString)


Finally


If Not asyncConnection Is Nothing AndAlso asyncConnection.IsRunning Then


asyncConnection.End()


End If


End Try


End Sub
 
Laurens,


The VB API can only create Asynchronous applications (either simple or full asynchronous). This means that the external VB program is using Pro/ENGINEER as a "tool". Pro/ENGINEER cannot communicate to your VB program to initiate any functionality. It's a one way communication channel from VB to Pro/ENGINEER. The use case you are trying to accomplish is called a synchronous application which the VB API cannot support. Read the documentation about asynchronous applications and it will tell you how it works. Hope it helps...
 
williaps,


Hi I'm Trying to establish Full Assync connection.


Definition of Assync connection:The term asynchronous is usually used to describe communications in which data can be transmitted intermittently rather than in a steady stream. For example, a telephone conversation is asynchronous because both parties can talk whenever they like.


So basically I want ProE to start the communication by launching my VB API application.


I've been successfull in making the connection to Creo but only when starting out with Vb API and then connecting to Creo via Vb API. I would like to launch a VB IPA with an action listener from Creo interface.


About your statement of only one way communication:Why would have the option to add action listeners to creo if only one way communication is possible(According to you only from Vb API to CREO?)?


I think milindb is getting me on the right track? I have a simple question for milindb: Is it possible via VB script to add action listener button to Creo UI that would, when clicked, launch a vb Application that would connect to current Creo Session?
 
Laurens,


Yes , it is very much possible to create action listners via VB API. PTC has demonstrated it in various example. Please refer VB API example vbparam under vbapi installation directory to get more details.


HTH
Edited by: milindb
 
williaps,Thanks I'm working through the VB API examples. It's helped a lot and I've learned a lot. But I can not connect in Full Assync mode. Please refer to beginning of previous posts where I explain my problem. When selectin the "Full Async" button I get errors.This is where my posts stared previously but please refer to the posts. Thanks for the attention:


Hi I have a vb program connecting to Creo Session.I use this program to update Creo Session parameters. I would like to add a button to Creo interface so that I could launch my vb program. I've tried the Add Button function in VB API Example installed with Creo. When I click the "Add Button" button I get an pfcException::XToolkitNotFound error. Basically it fails here:


'=========================================================== ===========


'Command is created which will be associated with the button. The class


'implementing the actionlistener must be given as input.


'=========================================================== ===========


buttonListener = New GatherInputListener()


inputCommand = aC.Session.UICreateCommand("INPUT", buttonListener)



I have installed the the Creo Toolkit with Creo so I don't think that is the problem. Can anybody maybe help me to try an create a listener button in Creo for opening my vb Program?


Thanks
 
Hi can somebody please help my to program a Button in Visual basic created in VisualStudiothat will create new part in CREO that will look as follows:


Type: Part


Sub-Type: Solid


Name: Part001


Common Name: thisPart


If I can get this to work I would like to go further with adding Combo boxes to my API where I can select the TYPE, Subtype,New name and New Common name.


I would appreciate any response.


Thanks
 
hi,

has anybody a working sample where a button is added in creo?

I dont get it to work, i always get a pfcExceptions::XToolkitNotFound

Thanks!
 
path for pfcAsynchronousModeExamples.txt is "C:\\Program Files\\PTC\\Creo 4.0\\M060\\Common Files\\vbapi\\vbapi_examples\\text"

only making this change in the sample file will create the button, i tested and it is working
 

Sponsor

Articles From 3DCAD World

Back
Top