43 Replies Latest reply: Apr 28, 2017 4:15 AM by ddhini RSS

    Load a model in a session

    ddhini Bronze

      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?

        • Re: Load a model in a session
          sjuraj Bronze

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

          • Re: Load a model in a session
            pkannan-2 Bronze

            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

              • Re: Load a model in a session
                ddhini Bronze

                Can you please explain it through coding?

                  • Re: Load a model in a session
                    pkannan-2 Bronze

                    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

                • Re: Load a model in a session
                  ddhini Bronze

                  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.

                    • Re: Load a model in a session
                      ddhini Bronze

                      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.

                        • Re: Load a model in a session
                          sjuraj Bronze

                          You have not retrieved the part/asm. This code will open drawing in new activated window.

                           

                          final String modelName = "test";

                          final String path = "c:/users/xxx/desktop/";

                          ModelDescriptor modelMD = pfcModel.ModelDescriptor_CreateFromFileName(

                                  path + modelName + ".prt");

                          ModelDescriptor drwMD = pfcModel.ModelDescriptor_CreateFromFileName(

                                  path + modelName + ".drw");

                          RetrieveModelOptions rmo = pfcSession.RetrieveModelOptions_Create();

                          rmo.SetAskUserAboutReps(false);

                           

                          session.RetrieveModelWithOpts(modelMD, rmo);

                          Drawing drawing = (Drawing) session.RetrieveModelWithOpts(drwMD, rmo);

                          Window drwWin = session.CreateModelWindow(drawing);

                          drawing.Display();

                          drwWin.Activate();

                      • Re: Load a model in a session
                        ddhini Bronze

                        Toolkit error is arising.. but don't know why it is arising.

                          • Re: Load a model in a session
                            sjuraj Bronze

                            Try to solve it. I cant help you more. This works for me.

                              • Re: Load a model in a session
                                ddhini Bronze

                                Thank you so much for your help skvarka juraj

                                  • Re: Load a model in a session
                                    sjuraj Bronze

                                    no problem

                                      • Re: Load a model in a session
                                        ddhini Bronze

                                        Its perfectly working .I failed to load my model thats why error arised.

                                           session = pfcGlobal.GetProESession();

                                            ModelDescriptor md1=null;

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

                                            RetrieveModelOptions rmo1 = pfcSession.RetrieveModelOptions_Create();

                                            rmo1.SetAskUserAboutReps(false);

                                            session.RetrieveModelWithOpts(md1, rmo1);

                                            ModelDescriptor md=null;

                                            md = pfcModel.ModelDescriptor_CreateFromFileName("C:\\Users\\350\\Desktop\\Mastermodels\\xxxx.drw");

                                            RetrieveModelOptions rmo = pfcSession.RetrieveModelOptions_Create();

                                            rmo.SetAskUserAboutReps(false);

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

                                            draw.Display();

                                           Window window = session.GetModelWindow(draw);

                                            window.Activate();

                                        • Re: Load a model in a session
                                          ddhini Bronze

                                          Hi ,I have a doubt.I want to open a drawing file and as well as its model file in a same session.Is it possible using Jlink.I did something but the file load in a single window only.Can you please guide me ?

                                            • Re: Load a model in a session
                                              sjuraj Bronze

                                              Create new window for model (part/asm) too and display the model. Then activate the window you want to be activated.

                                                • Re: Load a model in a session
                                                  ddhini Bronze

                                                  Sorry ,I can't able to create a new window.

                                                  Window window=session.createmodelWindow(Model mod);

                                                  window .activate();

                                                  It loads the model in the existing window.

                                                  • Re: Load a model in a session
                                                    ddhini Bronze

                                                    ModelDescriptor md1=null;

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

                                                      RetrieveModelOptions rmo1 = pfcSession.RetrieveModelOptions_Create();

                                                         rmo1.SetAskUserAboutReps(false);

                                                      Model mdl=session.RetrieveModelWithOpts(md1, rmo1);

                                                      mdl.Display();

                                                      Window window= session.CreateModelWindow(mdl);

                                                      window.Activate();

                                                     

                                                      ModelDescriptor md=null;

                                                      md = pfcModel.ModelDescriptor_CreateFromFileName("C:\\Users\\350\\Desktop\\Mastermodels\\xxxx.drw");

                                                      RetrieveModelOptions rmo = pfcSession.RetrieveModelOptions_Create();

                                                      rmo.SetAskUserAboutReps(false);

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

                                                      draw.Display();

                                                      Window window1 = session.CreateModelWindow(draw);

                                                      window1.Activate();

                                                      • Re: Load a model in a session
                                                        sjuraj Bronze

                                                        Your code works for me well. You should use try-catch blocks to identify your problems. The exceptions are explained in HTML documentation.

                                                          • Re: Load a model in a session
                                                            ddhini Bronze

                                                            Thank you.....

                                                            • Re: Load a model in a session
                                                              ddhini Bronze

                                                              Here I want open the drawing file.not a part file .I tried something.Thanks for your valuable time.and Sorry to disturb you,

                                                              DrawingCreateOptions sd = com.ptc.pfc.pfcDrawing.DrawingCreateOptions.create();

                                                                ModelDescriptor md1=null;

                                                                md1 = pfcModel.ModelDescriptor_CreateFromFileName("C:\\Users\\350154\\Desktop\\Mastermodels\\xxxx.drw");

                                                                RetrieveModelOptions rmo1 = pfcSession.RetrieveModelOptions_Create();

                                                                 rmo1.SetAskUserAboutReps(false);

                                                                Model mdl=session.RetrieveModelWithOpts(md1, rmo1);

                                                                ModelDescriptor md=null;

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

                                                                draw.Display();

                                                                Drawing drawingfile=session.CreateDrawingFromTemplate("New", null, md, sd);

                                                              Window win=session.CreateModelWindow(drawingfile);

                                                                drawingfile.Display();

                                                                • Re: Load a model in a session
                                                                  sjuraj Bronze

                                                                  You have not specitied template. You cant pass null as argument. You have to set DrawingCreateOption too. There is also example of using this method in doc example directory. Name of example file: pfcDrawingExamples.