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

Finding the right object

akok
11-Garnet

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

 

 

 

 

13 REPLIES 13
RPN
17-Peridot
17-Peridot
(To:akok)

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 

akok
11-Garnet
(To:RPN)

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
17-Peridot
17-Peridot
(To:akok)

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
akok
11-Garnet
(To:RPN)

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

RPN
17-Peridot
17-Peridot
(To:akok)

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

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)

....
akok
11-Garnet
(To:akok)

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

DavidBigelow
17-Peridot
(To:akok)

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

 

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

 

DavidBigelow
17-Peridot
(To:akok)

In CREOSON - if you are starting from the drawing - you would just run a 

 

drawing : get_cur_model

 

You can find this under the functions documentation.

 

CREOSON Functions

 

Hope that helps.

 

Dave

Hmm I don't know CREOSON.

If I don't get a Jlink solution I mite learn CREOSON

 

Allan

DavidBigelow
17-Peridot
(To:akok)

CREOSON uses JLINK as it's core... - just uses JSON transactions via a micro-HTTP server to enable the functionality.   It is highly optimized.

 

So if you are a JLINK developer - we would welcome contributions to the code! 🙂

 

Dave

 

 

 

 

akok
11-Garnet
(To:akok)

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

Top Tags