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

Finding the right object

Regular Member

Finding the right object

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

 

 

 

 

6 REPLIES 6

Re: Finding the right object

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 

Regular Member
(in response to RPN)

Re: Finding the right object

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

Re: Finding the right object

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)

....

Re: Finding the right object

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
Highlighted
Regular Member
(in response to RPN)

Re: Finding the right object

First I want to have a TIFF file for a part or assembly, not a Drawing.

I'm starting the app then a drawing is active. I will then open the object showen on the drawing, and saving a tiff file of that.

 

Allan

Re: Finding the right object

In Tcl I can do this, In Toolkit or VB you have to search similar functions. No error check in this code.

 

# Prerequisites
# Your current object is a drawing
# Your drawing has minimum one model attached

# Get active/current drawing model
set model [ps_draw current]

# We need to have it in a windows
set exists [ps_wind exists $model]
if {!$exists} {
# No window for the model exists, create it ps_model display -model $model } # Get/save current working dir set pwd [ps_pwd] # change to a folder for saving the file
ps_cd c:/tmp
# The name of the TIFF file (modelname.tif)
set TIF [file root $model].tif

# You may now retrieve a saved view, or give an orientation matrix
# not part of the code sample for a view name: 'ps_view set -model $model -- <YOUR_VIEWNAME>'
# save the image with the name $TIF
ps_util image -model $model -type tif -width 200 -height 200 -dpi 300 -- $TIF
# change back ps_cd $pwd

# Done