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

ProMdlNameGet fails

hanowski
1-Newbie

ProMdlNameGet fails

Ok, now for the problem I was really trying to address.

This code connects to pro/e ok and gets the handle of the current model
ok. All I want to do is print out the name of it but it's blank. This is
the output:

"Connection to Pro/Engineer established. Yippe!
ProMdlCurrentGet function returned PRO_TK_NO_ERROR
ProMdlNameGet function returned PRO_TK_NO_ERROR
.PRT"

Here is the full code:

#include <stdio.h>

extern "C"{
#include <procore.h>
#include <pronotify.h>
#include <prodimension.h>
#include <proutil.h>
}
int main(void){
ProProcessHandle proe_handle;
ProBoolean random;
ProName current_name;
char current_name_in_c[PRO_NAME_SIZE];
ProMdlType objtype;
ProError err;
ProMdl mdlHandle;

err = ProEngineerConnect(",NULL,NULL,",PRO_B_TRUE, 100, &random,
&proe_handle);
if(err != PRO_TK_NO_ERROR){
printf("%s\n","Error occured while connecting to Pro/Engineer.");
return -1; // failure
}
printf("Connection to Pro/Engineer established. Yippe!\n");

err = ProMdlCurrentGet(&mdlHandle);
if (err == PRO_TK_NO_ERROR)
printf("ProMdlCurrentGet function returned PRO_TK_NO_ERROR\n");
else if (err == PRO_TK_BAD_CONTEXT)
printf("ProMdlCurrentGet function returned PRO_TK_BAD_CONTEXT\n");

err = ProMdlNameGet(mdlHandle, current_name);
if (err == PRO_TK_NO_ERROR)
printf("ProMdlNameGet function returned PRO_TK_NO_ERROR\n");
else if (err == PRO_TK_BAD_INPUTS)
printf("ProMdlNameGet function returned PRO_TK_BAD_INPUTS\n");

ProWstringToString(current_name_in_c,current_name);
printf("%s.%s\n",current_name_in_c,"PRT");

while(1){
ProEventProcess();
}

return(0);
}

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.
2 REPLIES 2

I got this reply from wayne:
"you might check that protoolkit.h is being included as shown below.

it sounds like ProWstringToString is not working correctly.

let us know what you find.

wayne


Wide Strings

Pro/TOOLKIT, like Pro/ENGINEER, has to work in environments where
character strings use codes other than ASCII, and might use a bigger
character set than can be coded into the usual 1-byte char type. The most
important example of this is the Japanese KANJI character set.

For this reason, Pro/TOOLKIT uses the type wchar_t instead of char for all
characters and strings that may be visible to the Pro/ENGINEER user. This
includes all text messages, keyboard input, file names, and names of all
dimensions, parameters, and so on, used within a Pro/ENGINEER object.

Defining wchar_t
Although most platforms supported by Pro/TOOLKIT provide a definition of
wchar_t in a system include file, not all do. Those that do use
definitions of different lengths; some provide definitions that are not
suitable for all the character codes supported by Pro/ENGINEER. Therefore,
Pro/ENGINEER takes considerable care to make sure it uses a suitable
definition of wchar_t on each supported platform.

It is essential to make sure your Pro/TOOLKIT application is using the
same definition of wchar_t as Pro/ENGINEER on each platform your
application supports. To make this easier, Pro/TOOLKIT supplies the
include file pro_wchar_t.h. This file ensures that, if a definition of
wchar_t h has not already been made in an earlier include file, one is
provided that is consistent with the Pro/ENGINEER definition of the type.
Because this file is included by the file ProToolkit.h, you should include
ProToolkit.h as the very first include file in each source file."


Ok, so I added the line #include <protoolkit.h> inside the extern "C"{ block and
recompiled. Same result. I removed it and added it in the main include
area, under <stdio.h> and recompiled. Same result.

I also got a reply from Gerry Champoux. I will reply to that one
shortly...

I got the following reply from Gerry

"Your code look correct to me.
I wonder if the conversion from wide-string to string could be part of the
problem. It's unlikely, but needs to be checked.

Change your last print statement as follows:
printf("%S.%s\n",current_name,"PRT");

If this still produces an empty name, try using ProMdlDataGet, and extract
the model name from the resultant structure.
Example:
ProMdldata model_data ;
err ProMdlDataGet( mdlHandle , &model_data ) ;
printf("%S.%s\n",model_data.name,"PRT");

You use of ProEngineerConnect indicated asynchronous mode, which means
that your toolkit app is the main program, which in turn connects to an
already-running session of Pro/E. Is this your intent? Most Toolkit
applications are synchronous (launched FROM within Pro/E)."

Gerry,

I tried your suggestion:
printf("%S.%s\n",current_name,"PRT");
but same result.

I tried your second suggestion
ProMdldata model_data ;
err = ProMdlDataGet( mdlHandle , &model_data ) ;
printf("%S.%s\n",model_data.name,"PRT");

but same result.

Yes, asynchronous mode is intentional for our purposes.

Nobody here really understands ProToolkit. I started dabbling in it only
last week. I'm not even sure if we have a license for it. Our sysadmin
says we don't but how then do I have the protoolkit folder under proewf
and all the include files? Does PTC allow partial use of protoolkit
allowing you to connect to it but then blocks out some commands?
Announcements
Attention: Creo 7.0 Customers
Please consider upgrading
End of Life announcement here.

NEW Creo+ Topics:
PTC Control Center
Creo+ Portal
Real-time Collaboration