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

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

How to start a batch with toolkit

eclaassen
7-Bedrock

How to start a batch with toolkit

Hello,

I'm trying to write the application which reads some informations from asm/prt files in a directory and writes them into xml files.

What I can do now is to create an exe-file in VS2012, a prodev.dat and a rbn-file (just did according to the document "Getting Started with Creo Object TOOLKIT C++ 3.0").

If I start creo 3 from the folder containing prodev.dat, then I see the button in the OTK group and can run the application.

 

My Question is, how can I start my application without GUI and the button is automatically pushed (means, my application is automatically executed)?

 

Thank you in advance

Xinyu

ACCEPTED SOLUTION

Accepted Solutions
sully7
14-Alexandrite
(To:eclaassen)

Aaaah okay - sorry, I forgot one additional requirement during my original post. Your additional arguments also need to be prefixed with a "+" or a "-".  (I'll go back and edit the post to include that)

 

The documentation states (page 63-ish of the ProToolkit user guide):

The first command-line argument passed to Creo Parametric TOOLKIT is the
same one seen by Creo Parametric; that is, it is the name of the Creo Parametric
executable. The remaining command-line arguments passed to user_
initialize() are a subset of those given on the command line that invoked
Creo Parametric. The rule is that Creo Parametric passes on to user_
initialize() any command-line argument that starts with a “+”, or with a “-”
followed by an upper-case character.
For example, these command-line arguments will be passed to Creo Parametric
TOOLKIT:
+batch=mybatchfile.txt
-Level=expert

Give that a try - it should work just fine 🙂

 

Thanks, 

James Sullivan

President & Founder
CadActive Technologies - www.cadactive.com

View solution in original post

8 REPLIES 8
sully7
14-Alexandrite
(To:eclaassen)

You'll need to use the windows command prompt to start Creo. You can do this by navigating to the folder for your working directory, opening a command prompt, and running the following command line: 

 

In this example, I have set my creo install path as a windows environment variable, so that I can quickly replace the command for different versions of Creo, etc.

 

call "%CREO_INSTALL_PATH%\Parametric\bin\parametric.exe" -g:no_graphics -batch_mode -i:rpc_input 

 

From there, if you pass OTHER arguments after the last one, they will be also passed into your Toolkit application's "user_initialize" function. Aka, if you use 

 

call "%CREO_INSTALL_PATH%\Parametric\bin\parametric.exe" -g:no_graphics -batch_mode -i:rpc_input -RUN_MY_DESIRED_APPLICATOIN

 

Then you should see a command line pop up, it should load Creo in non-graphical mode, load your toolkit application, and pass the argument "-RUN_MY_DESIRED_APPLICATION" in as one of the values in your "argv" array. 

 

You would then basically write code into your "user_initalize" to look for those arguments, and do the appropriate actions.

 

For more information, there is a section of the ProToolkit documentation called "Using Creo Parametric TOOLKIT to Make a Batch Creo Parametric Session" (located on Page 63-ish, depending on what version of the docs you are looking at). 

 

Hope this helps! Please don't hesitate to reach out if you have any issues.

 

Thanks, 

James Sullivan

james.sullivan@cadactive.com

President & Founder
CadActive Technologies - www.cadactive.com

Hi,

thank you for your reply.

It works almost... And I have some qustions:

1) The user_initialize takes always one argument "proe", whatever I write at end of the command line

2) "wSession->UICreateCommand" does not work as in example, I have to call my callback function directly. Is it OK or there is some replacement for it?

3) How to terminate the program? Now I have to close the console manually.

4) Where can I find the documentation you mentioned? Is it shipped with Creo/Toolkit or can I download it anywhere?

 

Thank you!

Xinyu

PS: I use Creo 3

sully7
14-Alexandrite
(To:eclaassen)

To answer your questions: 

 

  1. I like to write my user initialize as something along these lines:
    int user_initialize(int argc,  char *argv[],  char *version,  char *build,  wchar_t errbuf[80]);
    With no arguments entered in the command line, I believe you see "argc=1", and "proe" (as you stated).
    If you do pass arguments via the command line, you should see a "argc = 2" (or more, as entered into the command line), being the "number of arguments", and the n'th address of "argv" being the argument itself.

  2. That is correct. If you are running in batch mode, you do not "need" to register a command. Simply include the header for the class or method that you are trying to execute, and run it. One of the things that I like to do personally is add one argument for the "method that I want to run" and one argument for "an input file" being the "things I want to do"... but you can really architect this however you want. 

    So... for example, I like to do something like this (note: I haven't actually compiled or tested this... I just typed it up in the post just now haha, so please excuse if there are any errors):

    /*! @brief Do batch mode stuff
    */
    ProError EvaluateBatchMode(const std::string &app, const std::string &input) { 
        if (app.empty() || input.empty()) { return PRO_TK_BAD_INPUTS; } // to be safe
        ProError err = PRO_TK_NO_ERROR;
    
        // how you run your application depends entirely on you and how you architect your code and classes. 
        // This example will show a ProToolkit example
        if (app == "MY_DESIRED_APPLICATION_1") {
          err = RunMyApplication1();
    } else if (app == "MY_DESIRED_APPLICATION") { MyApplication2 app; // Do my application here err = app.Execute(); // again, depends on your classes and code } return err; } /*! @brief The startup for Toolkit */ int user_initialize(int argc, char *argv[], char *version, char *build, wchar_t errbuf[80]) { ProError err = PRO_TK_NO_ERROR; // Some setup stuff // Check for Batch Mode if (argc > 2) { std::string desired_app = argv[1]; std::string input = argv[2]; err = EvaluateBatchMode(desired_app, input); ProEngineerEnd(); return (int)err; // or whatever you want } // Some other stuff you may do if you AREN'T in batch mode return 0; }
  3. The method "ProEngineerEnd" will terminate the application.

  4. The documentation is shipped with Toolkit - typically located here (You mentined that you use Creo 3... but this path will obviously change depending on where you installed Creo as well as depending on the datecode of creo installed)
    - the ProToolkit user guide - "C:\Program Files\PTC\Creo 3.0\M110\Common Files\protoolkit\tkuse.pdf". 
    - there is an OTK equivalent located here - "C:\Program Files\PTC\Creo 3.0\M110\Common Files\otk_cpp_doc\otkug.pdf".

Hope this helps! 

 

Cheers,

James Sullivan

President & Founder
CadActive Technologies - www.cadactive.com

Hi,

I simplified my code as following:

 

#include "wfcSession.h"
#include <pfcGlobal.h>
#include <pfcCommand.h>
#include <pfcUI.h>
#include <pfcExceptions.h>
#include <wfcClient.h>

extern "C" int user_initialize(
	int argc,
	char *argv[],
	char *version,
	char *build,
	wchar_t errbuf[80])
{  
	cout << "Number of arguments: " << argc << endl;
	try
	{
		pfcSession_ptr		Session = pfcGetProESession ();
		wfcWSession_ptr wSession = wfcWSession::cast (Session);
		int x;
		cin >> x;
		wSession->EndSession();
		return (wfcTK_NO_ERROR);
	}
	xcatchbegin
		xcatchcip (Ex)
		cout << "Exception:\n" << Ex << endl;
	return (wfcTK_NO_ERROR);
	xcatchend
}
extern "C" void user_terminate()
{
	cout << "OTK application terminated successfully.\n";
}

I'm using "Creo Object TOOLKIT C++" and trying to run the example "otk_install.zip". The code above is modified from this example.

 

But if I run it in batch:

 

"%CREO_INSTALL_PATH%\Parametric\bin\parametric.exe" -g:no_graphics -batch_mode -i:rpc_input XXX YYY

the argc is always 1.

 

With EndSession or ProEngineerEnd I can terminate the process but user_terminate is not called.

 

Maybe the user_initialize and user_terminate are just for interactive purpose?

 

Thank you,

Xinyu

 

sully7
14-Alexandrite
(To:eclaassen)

Aaaah okay - sorry, I forgot one additional requirement during my original post. Your additional arguments also need to be prefixed with a "+" or a "-".  (I'll go back and edit the post to include that)

 

The documentation states (page 63-ish of the ProToolkit user guide):

The first command-line argument passed to Creo Parametric TOOLKIT is the
same one seen by Creo Parametric; that is, it is the name of the Creo Parametric
executable. The remaining command-line arguments passed to user_
initialize() are a subset of those given on the command line that invoked
Creo Parametric. The rule is that Creo Parametric passes on to user_
initialize() any command-line argument that starts with a “+”, or with a “-”
followed by an upper-case character.
For example, these command-line arguments will be passed to Creo Parametric
TOOLKIT:
+batch=mybatchfile.txt
-Level=expert

Give that a try - it should work just fine 🙂

 

Thanks, 

James Sullivan

President & Founder
CadActive Technologies - www.cadactive.com

Yes, it works!

Thank you!

Does J-Link work in same way, Any idea please help me

Hi

 

I have started Creo from command prompt with arguments. I am doing nothing inside user_initialize except closing Creo. Doing so, ProEngineerEnd() API either hangs or Crashes Creo. 

 

Is this issue for Creo 4.0 M030? I have already done same with Creo 2.0 and Creo 3.0 in past.

 

Can anyone let me know what could be issue or next step to analyze the issue for Creo 4.0?

Announcements


Top Tags