Showing posts with label Windchill API. Show all posts
Showing posts with label Windchill API. Show all posts

Soft Type – How to get type definition reference id

When we want to find the list of soft type objects and with the help of QuerySpec in Windchill, we need to use soft type’s type definition reference id in the QuerySpec condition.
Below code snippet will be useful in writing this QuerySpec

TypeDefinitionReference typeDefRef = TypedUtility.getTypeDefinitionReference("com.maheshmhetre.epmdoc.TestEPMDocument");
if (typeDefRef != null) {
qs.appendWhere(new SearchCondition(EPMDocument.class,
"typeDefinitionReference.key.id",
SearchCondition.EQUAL,
                           typeDefRef.getKey().getId()));
}


Here ‘com.maheshmhetre.epmdoc.TestEPMDocument’ is the Internal Name of the soft type. This value can be retrieved from soft type details from Type and Attribute Manager.

Windchill Part Usage Link


This is an IteratedUsageLink where a specific WTPart uses a WTPartMaster (actually it will use one of the WTParts associated with the WTPartMaster based on a config spec) and the part uses a specific Quantity (with unit of measure) of the part master as a component of its structure. WTParts can use other parts to build assemblies using the WTPartUsageLink. The WTPartUsageLink’s aggregated Quantity can be used to indicate the amount of the component that is being consumed.
Note that since the link is between a WTPart and a WTPartMaster it will be necessary to use a config spec (usually WTPartConfigSpec) to select the correct version of the WTPartMaster, which is a WTPart.
For example:
To build a car there are 4 tires for each car built. For a hammock there might be 2 end ropes that are three feet long.

Part_1 A.1 is dependent on Part_2 master object.

Even after new revision/iteration Part_1 B.1 is link to the Part_2 irrespective of Part_2 iteration number i.e. the parent object’s (Part_1) all iterations are always linked to the child’s (Part_2) latest iteration.

Model Diagram:

JavaDoc:
wt.part

Class WTPartUsageLink
java.lang.Object
 wt.fc.WTObject
  wt.fc.ObjectToObjectLink
      wt.vc.struct.IteratedUsageLink
          wt.part.WTPartUsageLink
public class WTPartUsageLink
extends IteratedUsageLink
implements Externalizable
UI Navigations:
To see the part usage, navigate to parent part details page -> third level navigations -> Structure -> Product Structure table
API Navigations:
To get the usage parts, we need to navigate through this link table. The service APIs are available in WTPartService class.
The relevant methods are (Please refer JavaDoc for more details)
QueryResult
getUsedByWTParts(WTPartMaster partMaster)
         Navigates the WTPartUsageLink along the usedBy role, returning a QueryResult of WTParts.
QueryResult
getUsesWTPartMasters(WTPart part)
         Navigates the WTPartUsageLink along the uses role, returning a QueryResult of WTPartUsageLinks.
Persistable[][][]
getUsesWTParts(WTList parts, ConfigSpec configSpec)
         Navigates from many used-by parts to their uses part masters and applies a ConfigSpec to select the iterations of the uses parts.

Windchill Document Dependency Link


This is a version-specific relationship between two documents i.e. WTDocument to WTDocument link.  A reference between two documents can be created to show a dependency on another document. A document may reference some information in another document, so during a create or update, a reference to that document is added. The references relationship has a comment attribute that can be used to explain why the reference exists or what the dependency is.
For example:
A document is depends on another document.

Doc1 A.1 is dependent on Doc2 A.1

After new revision/iteration Doc1 B.1 is dependent on Doc2 B.1

Doc1 A.1 is dependent on Doc2 A.1. This is a version dependency. If the Doc1 get revised/iterated, the dependent document’s will also get updated.
Model Diagram:

JavaDoc:

wt.doc
Class WTDocumentDependencyLink
java.lang.Object
 wt.fc.WTObject
  wt.fc.ObjectToObjectLink
      wt.vc.struct.IteratedUsageLink
          wt.doc.WTDocumentDependencyLink
public class WTDocumentDependencyLink
extends IteratedUsageLink
implements Externalizable

UI Navigations:
To see the dependent documents, navigate to main document’s details page third level navigations -> Related Objects -> Documents
To add the dependent documents, from ‘References Documents’ use ‘Add’ or ‘Associate New’ table level action on main document. You can add dependency comment from the row level actions.
MainDoc depends on doc01. MainDoc details page
If you see the doc01 document, related document you can see MainDoc is dependent on doc01
API Navigations:
To get the depedent documents, we need to navigate through this link table. The service APIs are available in WTDocumentService class.
The relevant methods are (Please refer JavaDoc for more details)
QueryResult
getDependsOnWTDocuments(WTDocument document)
         Return a QueryResult of WTDocuments that the given WTDocument is dependent on.
QueryResult
getDependsOnWTDocuments(WTDocument document, boolean onlyOtherSides)
         Return a QueryResult of WTDocuments that the given WTDocument is dependent on.

Windchill Document Usage Link


The WTDocumentUsageLink is an IteratedUsageLink between WTDocuments and WTDocumentMasters and used to create uses relationships between documents or document structure.
For example:
Several documents can contain the same glossary or one document can be made up of several sub-documents.
Documents should use this if a document is made up of subdocuments and the sub-documents can be reused by other documents, or need to be controlled separately.


The main document is linked to the other document’s master objects. Here main document is linked to the WTDocumentMaster objects of document_1, document_2 and document_3.
This means main document is always pointing to the latest copy of all linked document even they get new version or iteration.
Model Diagram:


JavaDoc:

wt.doc Class WTDocumentUsageLink
java.lang.Object
 wt.fc.WTObject
  wt.fc.ObjectToObjectLink
      wt.vc.struct.IteratedUsageLink
          wt.doc.WTDocumentUsageLink
public class WTDocumentUsageLink
extends IteratedUsageLink
implements Externalizable
UI Navigations:
To see the usage documents, navigate to main document’s details page -> Structure -> Document Structure table
To add the child documents, use ‘Add Documents’ row level action on parent document.
API Navigations:
To get the usage documents, we need to navigate through this link table. The service APIs are available in WTDocumentService class.
The relevant methods are (Please refer JavaDoc for more details)
Enumeration
getOrderedUsesWTDocumentMasters(WTDocument document)
         Navigates the WTDocumentUsageLink along the uses role, returning a Enumeration of WTDocumentMaster.
Enumeration
getOrderedUsesWTDocuments(WTDocument document, ConfigSpec configSpec)
         Applies the configSpec to the result of navigating the WTDocumentUsageLink along the uses role; returns a Enumeration of Persistable[], in which the WTDocumentUsageLinks are at the 0th position and the corresponding iterations (or master if there is no corresponding iteration) in the 1th position.
QueryResult
getUsedByWTDocuments(WTDocumentMaster documentMaster)
         Navigates the WTDocumentUsageLink along the usedBy role, returning a QueryResult of WTDocuments.
QueryResult
getUsesWTDocumentMasters(WTDocument document)
         Navigates the WTDocumentUsageLink along the uses role, returning a QueryResult of WTDocumentMaster.
QueryResult
getUsesWTDocuments(WTDocument document, WTDocumentConfigSpec configSpec)
         Applies the configSpec to the result of navigating the WTDocumentUsageLink along the uses role; returns a QueryResult of Persistable[], in which the WTDocumentUsageLinks are at the 0th position and the corresponding iterations (or master if there is no corresponding iteration) in the 1th position.
QueryResult
getUsesWTDocumentUsageLinks(WTDocument document)
         Returns the WTDocumentUsageLinks resulting from navigating the WTDocumentUsageLink along the uses role.

Windchill Rose Web Publisher


While working on Windchill customization, sometimes we need to look into the object models. In Windchill 9.1 we can use the Rational Rose tool for the same but most of the times the tool is not available to all the developers. In this scenario, we can use the Windchill Rose Web Publisher tool to view the object model.

Access Windchill Rose Web Publisher using URL:


















Navigate to Logical View -> Assembly -> Module -> appropriate package and double click on item. Please find below screenshot for wt.doc package object model

Note: There may be issue in panel scrolling. Try different browsers. Mostly works with IE.

Windchill Command Line Utility Skeleton

In the last topic Windchill Remote Method Server Access API we saw how we can use RemoteMethodServer to invoke method server code remotely. Even though there are plenty of utilities available in Windchill OOTB, we came across various scenarios where we need to write our own custom utilities.
In this post I am trying to share the Windchill command line utility skeleton which uses RemoteMethodServer.
package com.blogspot.maheshmhetre.windchill.utilities;

import java.lang.reflect.InvocationTargetException;
import java.rmi.RemoteException;

import wt.method.RemoteAccess;
import wt.method.RemoteMethodServer;
import wt.session.SessionHelper;
import wt.util.WTException;

public class WindchillCustomUtilitySkeleton {

 //START of inner class - Server
 public static class Server implements RemoteAccess {
  
  public static void methodOne(String param1, String param2) {
   try {
    //Get login credentials
    SessionHelper.manager.getPrincipal();
    
    //Call core processing method
    WindchillCustomUtilitySkeleton utility = new WindchillCustomUtilitySkeleton(); 
    utility.doOperation(param1, param2);
    
   } catch (Exception e) {
    e.printStackTrace();
   }
   
   return;
  }
 } //END of inner class - Server

 private void doOperation(String param1, String param2) throws WTException{
  //TODO execute your utility logic
  System.out.println("This sysout will be available in method server log.");
 }
 
 public static void main(String[] args) {
  //TODO get utility input parameters
  //TODO basic validation

  System.out.println("This sysout will be available on console from where the utility is running.");
  //prepare input params
  //data types will depends on your method parameters and can be any valid object type
  Class argTypes[] = {String.class, String.class};//add all remote method parameter data types
  Object argValues[] = {"param_1_value", "param_2_value"};//respective data value
  
  //call remote method - pass inner class name, method name, arg types and arg values
  try {
   RemoteMethodServer.getDefault().invoke("methodOne", 
     "com.blogspot.maheshmhetre.windchill.utilities.WindchillCustomUtilitySkeleton$Server",
     null, argTypes, argValues);
  } catch (RemoteException e) {
   e.printStackTrace();
  } catch (InvocationTargetException e) {
   e.printStackTrace();
  }

  Runtime.getRuntime().exit(0);
 }
}

Please share your thoughts to improve this skeleton.

Windchill Remote Method Server Access API


To invoke Windchill server side code from outside method server, we need to use RMI calls. Windchill provides mechanism to do this by using RemoteMethodServer class.

The method signature
RemoteMethodServer.getDefault().invoke(String methodName, String className, Object obj, Class[] paramClassTypeArray, Objet[] paramValuesArray);

The core code to invoke remote method is
RemoteMethodServer remotemethodserver = RemoteMethodServer.getDefault();
remotemethodserver.setUserName(userName);
remotemethodserver.setPassword(Password);

Class argTypes[] = {String.class, String.class};//add all remote method parameter data types
Object argValues[] = {"param_1_value", "param_2_value"};//respective data value

Object returnObj = remotemethodserver.invoke(methodName, className, null, argTypes, argValues);

If you want the user who is executing the code should provide username and password explicitly using basic authentication handled by framework, skip the username and password set to RemoteMethodServer and user SessionHelper.manager.getPrincipal(); Adding this will give popup for username and password if not available.
Keep in mind that there may be an issue if you are executing the remote access code from some external terminal like putty session. The popup will not work by default and need some additional settings.

In the next post we will see a command line utility skeleton which uses RemoteMethodServer API.

Windchill ... Where to Start?

Many guys who want or have to work on Windchill, the first question they usually ask is “Where to start?”.

The best training material for Windchill is PTC University courses. This is a web based training provided by PTC and need to be purchased.

As we can see, most of the companies working in Windchill are service industries. Rare to see those companies purchasing PTC University courses to train employees. Adding to this, these days the Windchill service industry following the pattern of hiring pure Java developers for Windchill customization and train them the Windchill framework. So all the responsibility goes to the senior person in the team who is most of time busy.
Now you are at dead end where we must start to explore Windchill yourself. Here are few pointers where we can start learning Windchill.

Windchill Help:
URL: http://hostname/Windchill-WHC/index.jspx
This the real material to learn the Windchill functionality. You can directly go to the home page and explore the area the you of interest. The other way is open help from the screen you are working on, this will take to the respective help topic.

Windchill Java/API Doc:
Folder: Windchill_Home/codebase/wt/clients/library/api/index.html
Web: http://hostname/Windchill/wt/clients/library/api/index.html

Windchill Examples:
Location: Windchill_Home/codebase/netmarkets/jsp/carambola/customization/examples/
Many examples found under his location.
In Windchill 10.x you can found this under Tools as well.

Top most Windchill Guides:
Windchill Customization Guide
Windchill Business Administration Guide
Windchill System Administration Guide