Skip to main content
12-Amethyst
April 9, 2018
Question

Finding the right object

  • April 9, 2018
  • 4 replies
  • 6114 views

I will like to then I have a drawing open then I start my script, be able to open the part on the drawing orient part in default view and then export a TIFF file of the part.

 

I can open the part and export the TIFF file, but I can't orient the part.

 

If I run "window.GetModel().RetrieveView("Front");" there I start my script from a part it works,

but then I call this then I have a drawing open:

 

  private static void OrientPart(Session MySession, Model model) throws jxthrowable {

    // MySession is the current session
    // model is the drawing there the Jlink is started
    Drawing drawing = (Drawing) model;                     
    String FileType = "";
    Models solids = drawing.ListModels ();
    Solid solid = (Solid)solids.get (0); // first model on the drawing
    
    // finding the type of the model on the drawing
    if (solid.GetType() == ModelType.MDL_DRAWING) FileType = ".drw";
    else if (solid.GetType() == ModelType.MDL_PART) FileType = ".prt";
    else if (solid.GetType() == ModelType.MDL_ASSEMBLY) FileType = ".asm";

    // opening the model
    Window window = MySession.OpenFile(pfcModel.ModelDescriptor_CreateFromFileName(model.GetFullName() + FileType));

    /* tring to turn the model to the "Default Orientation"
       it works if the function is started from a part without opening it
       but then runned like here I can compile the code, and Creo run it, but nothing happens.
    */
    window.GetModel().RetrieveView("Front");
//    solid.RetrieveView("Front");
  }

 

notting happens, no errors.

 

I think I don't have the part object.

 

Can anybody help?

 

Allan Kok

 

 

 

 

4 replies

RPN
18-Opal
June 5, 2018

Creating Drawing Views
Method Introduced:
• pfcModel2D.Model2D.CreateView
The method pfcModel2D.Model2D.CreateView creates a new view in the drawing. Before calling this method, the drawing must be displayed in a window.
The pfcView2D.View2DCreateInstructions contains details on how to create the view. The types of drawing views supported for creation are:
• DRAWVIEW_GENERAL—General drawing views
• DRAWVIEW_PROJECTION—Projected drawing views

 

i hope this gives you a clue 

akok12-AmethystAuthor
12-Amethyst
June 6, 2018

My problem is, it is in part or assembly mode.

Then I start my j-link app then the part/assembly is open it works, but then I have something else open then I start my app, and the app then opens part/assembly.

I want my j-link app to from a drawing:

- open the part/assembly - works

- to reorient it to a saved view - notthing happens.

 

Allan

RPN
18-Opal
June 13, 2018

I’m not sure to understand your target. If you want export a TIFF from a drawing.

  1. Assuming mynumber.prt is in session
  2. copy a template temp.drw to my mynumber.drw
  3. load this into session from disk (there is a Toolkit API for this, create from template)
  4. open a new window and assign the drawing
  5. add mynumber.prt to this drawing
  6. create a drawing 2D view based on a 3D view in your 3D model
  7. export the drawing to TIFF
21-Topaz I
June 6, 2018

Hi Allan,

 

I had a similar issue with a drawing. There was an issue where the code was not working in drawing mode when the drawing was opened from  J-Link but it was working when the drawing was the current model.

In Toolkit we can solved the  when we play the mapkey "Windows activate -> Crtl-A" but in J-Link is this not possible because we do not have functionality corresponding to the Toolkit function ProMacroExecute() - which synchronize the mapkey executed Session.runMacro() will load only the mapkey in the Creo  Program stack and the mapkey will be executed first when the focus is back to UI. Ok there is the dirty solution that mapkey will call a button which continue the program but is not worth to discuss it here further.

So in my case I used some code like this:

public class TryBody

{
public TryBody(Session inSession) {
 ////////////////////////////////////////////////
Drawing drw=null;
String LOG_FILE = "test_log.txt";
Logger l = new Logger( LOG_FILE );
String MOD_NAME="test_dawing.drw";
l.write("===============================================");
l.write("======== TEST LOGGER FILE Issue =======");
l.write("===============================================");
 
 	 try {

 inSession.GetCurrentWindow().Activate();
 ModelDescriptor proeModelDescriptor=pfcModel.ModelDescriptor_CreateFromFileName(MOD_NAME);
 
 proeModelDescriptor.SetPath(".\\data");

 	
 			 drw=(Drawing) inSession.GetCurrentModel();
 			 if(drw==null)
 {
					 Log.write("WARNING Error no current model:" );

 				 drw=(Drawing) inSession.RetrieveModelWithOpts(proeModelDescriptor,pfcSession.RetrieveModelOptions_Create());
 				 drw.Display();
					 //Make sure that the drawing is displayed...
 Thread.sleep(1000);
				 }
 if(drw !=null)
 {
 l.write("========testDrawingIssue will start ==================");

 testDrawingIssue((Model) drw,l);
 l.write("======= testDrawingIssue() finished ==================");
 					 }


 			 } catch (jxthrowable x)

 			 {
 			 // TODO Auto-generated catch block
 			 x.printStackTrace();
 			 
 			 } catch (Exception e)
 			 {
 			 // TODO Auto-generated catch block
 			 e.printStackTrace();
 			 
 		 }
 		 finally {
				 				 l.write("===============================================");
				 				 	 l.write("======== END =======");
				 				 	 l.write("===============================================");
				 try{inSession.GetCurrentWindow().SetURL (inSession.GetCurrentDirectory()+LOG_FILE);}
				 catch (Exception e1) {JOptionPane.showMessageDialog ( null,"<p> EXCEPTION in inSession.GetCurrentWindow(): "+e1+" <br>");}
				 }
 /////////////////////////////////
 }

So what I did try  here is that when the drawing model is not the current model (here is not relevant if drawing or an assembly) The important part is that we will use another function sequnece to display the model and will also wait for a second (sleep). In my case was this the solution. May be, this could help also in your case.

Another approach is  to create a new window . (this means a second windows to display model - later if you want you can close the old window)

com.ptc.pfc.pfcWindow.Window current_window = null;
 	 try {


 inSession.GetCurrentWindow().Activate();
 ModelDescriptor proeModelDescriptor=pfcModel.ModelDescriptor_CreateFromFileName(MOD_NAME);
 
 proeModelDescriptor.SetPath(".\\customer_data");

 				 
 			 current_model= inSession.GetCurrentModel();
 			 if(current_model==null)
 {
					 Log.write("WARNING Error no current model:" );
					 }
					 else
					 {
 				 new_model = inSession.RetrieveModelWithOpts(proeModelDescriptor,pfcSession.RetrieveModelOptions_Create());
 				 
 Thread.sleep(500);
				 }
 if(new_model !=null)
 {
 l.write("========TEST HERE THE CUSTOMERS ISSSUE ==================");

 com.ptc.pfc.pfcWindow.Window my_window=inSession.CreateModelWindow((Model) new_model);
 if(my_window != null)
 { my_window.Repaint();
							my_window.Refresh();
							my_window.Activate();
							current_window=my_window;
							 }
 l.write("======= OK customer Test =======================");
 					 }


 			 } catch (jxthrowable x)

....
akok12-AmethystAuthor
12-Amethyst
March 27, 2020

After haven given up on it for a while, I was trying again.
I was trying with getting to use the "Standard Orientation" it look like it doesn't work, it works with view I have saved in the model.

Does any of you know how to get the Standard Oriantation?

Allan

17-Peridot
March 27, 2020

You can always record and run a mapkey to get that orientation ... then export accordingly.

 

In CREOSON you can do this quite easily : note this was code executed in the CREOSON Playground.

 

2020-03-27 at 9.40 AM.png

// note: get connection first. :)
let intObj = new creo.InterfaceObj();

// set the mapkey value
intObj.script = "~ Select `main_dlg_cur` `igToolbar_AncestorIGT_IGT_GRP_inh397369119.proe_win:casc340798662`; ~ Close `main_dlg_cur` `igToolbar_AncestorIGT_IGT_GRP_inh397369119.proe_win:casc340798662`; ~ Command `ProCmdNamedViewsGalSelect` `Standard Orientation`;"

// execute the mapkey
intObj.mapkey();

// set export type
intObj.type = "TIFF";

// export the image
intObj.export_image();

2020-03-27 at 9.41 AM.png

Hope that helps.

 

Dave

 

akok12-AmethystAuthor
12-Amethyst
March 27, 2020

I found it is just called "Default", it works then I start with a part in session.

 

But I want to start from a drawing, then I open the part I still have the darwing in the GetProESession, then it doesn't work.

 

How can I get the part in my session variable?

 

Allan

 

akok12-AmethystAuthor
12-Amethyst
March 30, 2020

Hi

I have come to this code.

I have a drawing open, and I will like to open the part associate to it, reorient the part. But it didn't rotate.

I think it is because I did not do it on the right object.

I tryed with another part insted of the drawing open, here the open part reorient and then open the new part.


The value of window.GetModel().GetFileName() is 15000000.prt

But the value of MySession.GetModel().GetFileName() is the part open from the biginning or the drawing, depent the test.

 

How can I get the new acitve?

Is there a way change that part I'm working on?

 

 

Window window = MySession.OpenFile(pfcModel.ModelDescriptor_CreateFromFileName("15000000.prt"));
window.Activate();

Model localModel = window.GetModel();

View view = localModel.RetrieveView("Default");

 

Allan