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

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

Load a model in a session

ddhini
14-Alexandrite

Load a model in a session

I have a Model and i stored in my computer.Ex(C:\Desktop\load.prt)

In my proE session i involved a GUI.Where user can do some works.Here what i want is,I want to load a model that stored in C:\Desktop\load.prt  when user clicks the button .Can please any one tell me how to do this?

1 ACCEPTED SOLUTION

Accepted Solutions
sjuraj
13-Aquamarine
(To:ddhini)

RetrieveModel only puts model into session. However RetrieveModel ignores path. You have to use RetrieveModelWithOpts method instead. Note to use right path to your file. There is no such path as c:/desktop/xxx.prt. Path to desktop is always c:/<user_name>/desktop. This code will load model from path to session and than displays it in the new created window.

ModelDescriptor md = pfcModel.ModelDescriptor_CreateFromFileName("c:/users/<user_name>/desktop/xxx.prt");

RetrieveModelOptions rmo = pfcSession.RetrieveModelOptions_Create();

rmo.SetAskUserAboutReps(false);

Model model = session.RetrieveModelWithOpts(md, rmo);

Window window = session.CreateModelWindow(model);

model.Display();

window.Activate();

View solution in original post

43 REPLIES 43
sjuraj
13-Aquamarine
(To:ddhini)

You can simply run macro and replace model name in macro string using method session.RunMacro

PARTHIBAN_K
15-Moonstone
(To:ddhini)

Use Retrieve model function to load the model in session

Use Model Descriptor to set the file name

You have to set the location as working directory

Parthiban Kannan

href="https://www.linkedin.com/in/parthiban-kannan/" target="_blank"
ddhini
14-Alexandrite
(To:PARTHIBAN_K)

Can you please explain it through coding?

PARTHIBAN_K
15-Moonstone
(To:ddhini)

Models char* _ProMdlRetrieve(wchar_t* FileName, int Type)

{

       char* msg;

       ProError Magizchi;

       ProMdlType modelType;

       switch(Type)

       {

       case 0:

              modelType = PRO_TYPE_UNUSED;

              break;

       case 1:

              modelType = PRO_ASSEMBLY;

              break;

       case 2:

              modelType = PRO_PART;

              break;

       case 3:

              modelType = PRO_DRAWING;

              break;

       case 4:

              modelType = PRO_MDL_3DSECTION;

              break;

       case 5:

              modelType = PRO_2DSECTION;

              break;

       case 6:

              modelType = PRO_LAYOUT;

       case 7:

              modelType = PRO_DWGFORM;

              break;

       case 8:

              modelType = PRO_MFG;

              break;

       case 9:

              modelType = PRO_REPORT;

              break;

       case 10:

              modelType = PRO_MARKUP;

              break;

       case  11:

              modelType = PRO_DIAGRAM;

              break;

       }

       ProMdl p_model;

       Magizchi = ProMdlRetrieve(FileName, modelType, &p_model);

       switch(Magizchi)

       {

       case PRO_TK_NO_ERROR:

              msg = "Model Retrieved";

              break;

       case PRO_TK_BAD_INPUTS:

              msg = "One or more of the input arguments are invalid";

              break;

       case PRO_TK_E_NOT_FOUND:

              msg = "The model was not found in the current directory";

              break;

       case PRO_TK_NO_PERMISSION:

              msg = "The function does not have permission to handle this model";

              break;

       }

       return msg;

}

Now call the method

_ProMdlRetrieve(FileName(wchar_t*), FileType(int))


You can also use out to hold the model data

Parthiban Kannan

href="https://www.linkedin.com/in/parthiban-kannan/" target="_blank"
ddhini
14-Alexandrite
(To:PARTHIBAN_K)

ModelDescriptor modeldesc = pfcModel.ModelDescriptor_Create(ModelType.MDL_PART, "C:\\Desktop\\xxxx.prt",null);

  Model model = session.RetrieveModel(modeldesc);

i coded something like this.

PARTHIBAN_K
15-Moonstone
(To:ddhini)

The method you have mentioned works in vb api & j-link.

I have mentioned toolkit. What is the error you'e getting?

Parthiban Kannan

href="https://www.linkedin.com/in/parthiban-kannan/" target="_blank"
sjuraj
13-Aquamarine
(To:ddhini)

RetrieveModel only puts model into session. However RetrieveModel ignores path. You have to use RetrieveModelWithOpts method instead. Note to use right path to your file. There is no such path as c:/desktop/xxx.prt. Path to desktop is always c:/<user_name>/desktop. This code will load model from path to session and than displays it in the new created window.

ModelDescriptor md = pfcModel.ModelDescriptor_CreateFromFileName("c:/users/<user_name>/desktop/xxx.prt");

RetrieveModelOptions rmo = pfcSession.RetrieveModelOptions_Create();

rmo.SetAskUserAboutReps(false);

Model model = session.RetrieveModelWithOpts(md, rmo);

Window window = session.CreateModelWindow(model);

model.Display();

window.Activate();

PARTHIBAN_K
15-Moonstone
(To:sjuraj)

Hi skvarka juraj

Retrieve Model does not ignore the path.

It loads the model to the session based on model descriptor.

If you have mentioned the path as pfcModelDescriptor.setPath = "Path Name"

then it considers the mentioned path otherwise it checks the model from workspace or working directory.

Retrieve Model With Options only used to ask User customized representation selection at the time of retrieval.

Parthiban Kannan

href="https://www.linkedin.com/in/parthiban-kannan/" target="_blank"
sjuraj
13-Aquamarine
(To:PARTHIBAN_K)

I tryed it. RetrieveModel works only for working dir only. From the J-link guide:

guide.PNG

PARTHIBAN_K
15-Moonstone
(To:sjuraj)

Thank you skvarka juraj‌, till days I  wrongly understood this one. Thank you so much.

Parthiban Kannan

href="https://www.linkedin.com/in/parthiban-kannan/" target="_blank"
sjuraj
13-Aquamarine
(To:PARTHIBAN_K)

No problem

ddhini
14-Alexandrite
(To:sjuraj)

Thanku ,Its working fine...

ddhini
14-Alexandrite
(To:sjuraj)

Hi, Actually your reply working perfectly.But i had some error in my session.

When I am using

String loc="C:\\Users\\354\\Desktop\\xxxx.prt"

ModelDescriptor md = pfcModel.ModelDescriptor_CreateFromFileName(loc);

it's perfectly working..

But when i change the loc into

String loc="C:\\Users\\354\\Desktop\\javaGUI\\modelgen\\dist\\mastermodels\\xxxx.prt";

ModelDescriptor md = pfcModel.ModelDescriptor_CreateFromFileName(loc);

when i use this error is populating....

Error:com.ptc.pfc.Implementaion.pfcException X String Too Long

Please help me to solve this....

ddhini
14-Alexandrite
(To:ddhini)

I know its due to the X String too long.But how to write a exception ?

sjuraj
13-Aquamarine
(To:ddhini)

The exception is thrown because of long part/asm name. There is 32 chars limitation for all creo files. Path to file should not cause problems.

ddhini
14-Alexandrite
(To:sjuraj)

Thank you..And i have one more doubt.When i load the modeldescriptor from proE then it will open a model in a proE session.But its not in a modelling mode.When I press Ctrl+ A  ,after that only it will change to model mode.

Session.createmodelwindow(model model); but it does'nt work.

sjuraj
13-Aquamarine
(To:ddhini)

You have to activate the window.

Window window = session.CreateModelWindow(model);

model.Display();

window.Activate();


window.Activate() actualy does the same as Ctrl+A

ddhini
14-Alexandrite
(To:sjuraj)

Thankuskvarka

ddhini
14-Alexandrite
(To:sjuraj)

I want to open a drawing file for the model . same procedure  that you mentioned suits for this?

sjuraj
13-Aquamarine
(To:ddhini)

Try and you will see. Just use .drw instead of .prt in your file name.

ddhini
14-Alexandrite
(To:sjuraj)

Its not working.

Session sess=pfcGlobal.GetProESession();

  ModelDescriptor proeModelDescriptor=pfcModel.ModelDescriptor_CreateFromFileName("C:\\Users\\354\\Desktop\\javaGUI\\dist\\mastemodels\\xxxxdr.drw");

  Drawing drw = (Drawing) sess.RetrieveModelWithOpts(proeModelDescriptor,pfcSession.RetrieveModelOptions_Create());

  drw.Display();

sjuraj
13-Aquamarine
(To:ddhini)

You need part/asm to display its drawing

ddhini
14-Alexandrite
(To:sjuraj)

Yea,But i dont know how to do this?Already i load my model by modeldescriptor and its appended sucessfully in my session .I want the drawing also?

sjuraj
13-Aquamarine
(To:ddhini)

You have to load both.

ddhini
14-Alexandrite
(To:sjuraj)

Hi skvarka juraj

You told There is 32 chars limitation for all creo files. Path to file should not cause problems.

But thats only my problem.When i load my model

ModelDescriptor md1 = pfcModel.ModelDescriptor_CreateFromFileName("C:\\Users\\354\\Desktop\\Mastermodels\\xxxx.prt");  with this code its simply working.

But slight changes

ModelDescriptor md1 = pfcModel.ModelDescriptor_CreateFromFileName("C:\\Users\\354\\Desktop\\DToolmaker\\Mastermodels\\xxxx.prt");

this cause XString too long error .Whats the specific reason for this problem

sjuraj
13-Aquamarine
(To:ddhini)

There must be mistake somewhere in the file name. I tryed to retrieve model with this path:

c:/users/xxxxx/desktop/this/is/really/very/long/path/to/the/part/model/123456789abcdefghijklm.prt

and it worked correctly.

Maybed you have used wrong model descriptor.

ddhini
14-Alexandrite
(To:sjuraj)

Actually am doing in a right way but still the error is arising.I crosscheck it once again.Thanks for your help

ddhini
14-Alexandrite
(To:ddhini)

But how to load the both drawing and model ? I load the master model into my session by the above code that you suggested.I have a master drawing file also.But i can't able to load it in a new session.

ddhini
14-Alexandrite
(To:ddhini)

ModelDescriptor md = pfcModel.ModelDescriptor_CreateFromFileName("C:\\Users\\350154\\Desktop\\javaGUI\\modelgen\\dist\\mastemodels\\xxxx.drw");

  RetrieveModelOptions rmo = pfcSession.RetrieveModelOptions_Create();

  rmo.SetAskUserAboutReps(false);

  Drawing drw = (Drawing) session.RetrieveModelWithOpts(md, rmo);

  Window window = session.CreateModelWindow(drw);

  drw.Display();

  window.Activate();

But its failed to load the drawing file.

Top Tags