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

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

Retrieve model in toolkit

Manjunath
13-Aquamarine

Retrieve model in toolkit

Hi all,

I try to retrieve model to assemble. I try to configure the model name in txt file.

ProStringToWstring(MLinkAToAssemble,MdAPart);
err = ProMdlRetrieve(MLinkAToAssemble,(ProMdlType)PRO_MDL_PART,(ProMdl*)&CompSolid);

I use the above code to retrieve model, but I get error PRO_TK_E_NOT_FOUND

whereas if i uses the model name directly I get the model in session

ProStringToWstring(MLinkAToAssemble,"TEST.PRT");
err = ProMdlRetrieve(MLinkAToAssemble,(ProMdlType)PRO_MDL_PART,(ProMdl*)&CompSolid);

Kindly throw some light

 

Regards,

Manjunath S

 

ACCEPTED SOLUTION

Accepted Solutions
Manjunath
13-Aquamarine
(To:Manjunath)

@RPN @Ketan_Lalcheta  thanks for your suggestions

I came across few things in documentation. I would like to share with you

<li>This function accepts only strings only in the active 
    encoding of the Creo Parametric TOOLKIT application. Strings
    from other encodings may not be properly converted.

To handle this refer to UgUnicodeTranscoding.c in installation directory.

View solution in original post

22 REPLIES 22

check with value of variable once (MDApart in your case). It should not have space or something extra characters. Also check once that wide char name holds proper value after conversion from text file variable value.

@Ketan_Lalcheta  I have cross verified, herewith I have attached the image for reference

I presume model is present into current working dir as it works with hard coded string. I have used this API and it works fine. Which Creo version you are having?

 

Additionally try with value as name only without extension once as you have already passed model type as part in second argument. If you don't wanna change value into text file and keep it as .prt only, use second argument as PRO_MDL_UNUSED.

 

HIH

Ketan

while reading value from text file, make sure you are not changing directory. If so, come back to earlier directory where model are present before using mdlretrive.

@Ketan_Lalcheta we use creo 2, moreover file is been retrived from PDM, do i need to set the working dir again? kindly clarify

@Ketan_Lalcheta I used as suggested but still failed to retrieve model

RPN
17-Peridot
17-Peridot
(To:Manjunath)

Get rid of the extension in your string!

Try this:

ProStringToWstring(MLinkAToAssemble,"TEST");

 

ProMdlRetrieve  (ProFamilyName name, 
ProMdlType    type,
                                 ProMdl       *p_handle); 
 
Type is given by ProMdlType!!
 
Windchill should work if you search for and you find it.
Manjunath
13-Aquamarine
(To:RPN)

@RPN  when I enter file name directly i can retrieve the model, but my requirement is model name have to be red from text file.

Manjunath
13-Aquamarine
(To:Manjunath)

@RPN @Ketan_Lalcheta  thanks for your suggestions

I came across few things in documentation. I would like to share with you

<li>This function accepts only strings only in the active 
    encoding of the Creo Parametric TOOLKIT application. Strings
    from other encodings may not be properly converted.

To handle this refer to UgUnicodeTranscoding.c in installation directory.

Doc suggests that file UgUnicodeTranscoding.c is located at <creo_
toolkit_loadpoint>/protk_appls/pt_userguide/ptu_main.

 

But could not find the same with Creo 4.0 M030

@Ketan_Lalcheta  its available in Creo2. 

RPN
17-Peridot
17-Peridot
(To:Manjunath)

I don't believe that this is the problem, because you provide the input string.

 

str_type_table[] =
{
{(char *)"sec", PRO_2DSECTION},
{(char *)"prt", PRO_PART},
{(char *)"asm", PRO_ASSEMBLY},
{(char *)"drw", PRO_DRAWING},
{(char *)"mfg", PRO_MFG},
{(char *)"lay", PRO_LAYOUT},
{(char *)"frm", PRO_DWGFORM},
{(char *)"rep", PRO_REPORT},
{(char *)"mrk", PRO_MARKUP},
{(char *)"dgm", PRO_DIAGRAM},
{(char *)"???", PRO_TYPE_INVALID}
};

 

// You parse your file name

ProFilenameParse(sel_path, def_path, w_name, w_type, &version);

//Get the type (based on table above)

ProWstringToString(str, def_path);

ProUtilConfirmNameType(str, line, &type)

 

//Open the model you may need to change the dir 

ProMdlRetrieve(w_name, (ProMdlType)type, (ProMdl*)&comp);

 

Search at the sample folder.

 

In Tcl this is done in 2 min, check the section Files - Open, save, erase Creo files or the Windchill Section

 

 

Manjunath
13-Aquamarine
(To:RPN)

@RPN  in this case w_name if retrieved from Creo interface there wont be an issue, where as if its been retrieved from any other interface ex. text file then creo shows error. 

RPN
17-Peridot
17-Peridot
(To:Manjunath)

You can’t directly compare the Creo Interface with Toolkit. All model types are handled in one table without the need to have the 4 chars for the extension, instead you have an integer for the type.

Manjunath
13-Aquamarine
(To:RPN)

@RPN  

I have list of files(File Name) to be retrieved in session in a text file.

Now creo have to read the text file and pass it to function ProMdlRetrieve.

I learnt that there should be  conversion using ProNativewstringToWstring

 

 

RPN
17-Peridot
17-Peridot
(To:Manjunath)

How is you input file encoded? UTF? Use notepad and encode as ANSI.

 

If you use 'test.prt' than I can't believe your story, you need only to convert to wchar (2 bytes per char max).

 

Tcl Section Files - Open ...

 

#
# read the file
# 
set fp [open models.txt]
set models [split [read $fp] \n]
close $fp

#
# Open the models in session
# if already in session skip to open the model
#
foreach model $models {
        if {![ps_model exist $model]}
                ps_file open $model
        }
}
Manjunath
13-Aquamarine
(To:RPN)

@RPN  is TCL related to Toolkit.If no, kindly try the same using toolkit. I got the error also I have attached the screen shot of the error message in earlier post.

 

RPN
17-Peridot
17-Peridot
(To:Manjunath)

It is based on Toolkit, how do you thing you can archive this without 🙂

 

 

Manjunath
13-Aquamarine
(To:RPN)

@RPN herewith I have attached the image and the return value for was PRO_TK_E_NOT_FOUND(-4). 

RPN
17-Peridot
17-Peridot
(To:Manjunath)

int
ps_test_Open_File (

)

{
	ProName       		w_modelname;
	ProMdl       		Model;
	ProError			tk_status;

	ProStringToWstring(w_modelname,"TEST");
	tk_status = ProMdlRetrieve(w_modelname,PRO_MDL_PART,&Model);

	return tk_status;

}

Compile and try. It is working for me!

Manjunath
13-Aquamarine
(To:RPN)

@RPN  I believe you have not understood the issue, try retrieving the file name from text file and do the same operation

RPN
17-Peridot
17-Peridot
(To:Manjunath)

I'm doing Toolkit since 15 Years, your error means the model file can't be found.

 

tk_status will be -4 if I change my code to

 

ProStringToWstring(w_modelname,"TESTX");

 

Because this model can't be found. But I will no longer watch this thread now, because you know what to do.

Announcements


Top Tags