Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X
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?
Solved! Go to Solution.
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();
You can simply run macro and replace model name in macro string using method session.RunMacro
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
Can you please explain it through coding?
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
ModelDescriptor modeldesc = pfcModel.ModelDescriptor_Create(ModelType.MDL_PART, "C:\\Desktop\\xxxx.prt",null);
Model model = session.RetrieveModel(modeldesc);
i coded something like this.
The method you have mentioned works in vb api & j-link.
I have mentioned toolkit. What is the error you'e getting?
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();
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.
I tryed it. RetrieveModel works only for working dir only. From the J-link guide:
Thank you skvarka juraj, till days I wrongly understood this one. Thank you so much.
No problem
Thanku ,Its working fine...
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....
I know its due to the X String too long.But how to write a exception ?
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.
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.
You have to activate the window.
Window window = session.CreateModelWindow(model);
model.Display();
window.Activate();
window.Activate() actualy does the same as Ctrl+A
I want to open a drawing file for the model . same procedure that you mentioned suits for this?
Try and you will see. Just use .drw instead of .prt in your file name.
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();
You need part/asm to display its drawing
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?
You have to load both.
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
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.
Actually am doing in a right way but still the error is arising.I crosscheck it once again.Thanks for your help
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.
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.