Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X
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
Solved! Go to Solution.
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
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
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
To answer your questions:
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).
/*! @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; }
Hope this helps!
Cheers,
James Sullivan
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
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
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?