Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X
I'm trying to write a Java function that searches the external catalog using the method getDatatables:
//get the datatables matching the specified partnumber
Condition condition = new SimpleCondition("part_number", "eq", value);
Condition[] conditions = {condition};
Iterator components = design.getDatatables(conditions, true, true);
The third parameter in the getDatatables call is supposed to search the external catalog, but unfortunately I'm getting a NullPointerException when trying to read a central catalog file:
java.lang.NullPointerException
at rsdesigner.design.DatatableCCSearch.readFile(DatatableCCSearch.java:177)
at rsdesigner.design.DatatableCCSearch.readCCFiles(DatatableCCSearch.java:110)
at rsdesigner.design.DatatableCCSearch.readCCFiles(DatatableCCSearch.java:103)
at rsdesigner.design.DatatableCCSearch.readCCFiles(DatatableCCSearch.java:103)
at rsdesigner.design.DatatableCCSearch.findCCDatatables(DatatableCCSearch.java:76)
at rsdesigner.design.Design.getDatatables(Design.java:227)
I'm using Creo 2.0 M010. Does anyone know if it's fixed in a later build of 2.0, or in 3.0?
What's worse is that I do actually get at least one PropertySet returned but it seems to be incomplete, so I can't actually scan the results anyway!
Thanks
Martin
Hi Martin,
when central catalog item is not loaded yet, you can't refer to it the same way you refer to internal catalog item ;
in order to get Central catalog items properties for catalog items which were not loaded yet , you need to use class of type CCitem (part of Design Package), below you can see example :
import java.util.Iterator;
import rsdesigner.component.*;
import rsdesigner.design.*;
import rsdesigner.uiextension.Utils;
public class testGetDTItem {
public static void getDT(String value, String intCatalog, String centralCatalog) throws RSDException{
try {
Design currentDesign=Design.getCurrentDesign();
Condition condition = new SimpleCondition("part_number", "eq", value);
Condition[] conditions = {condition};
String dataTableName;
Iterator<PropertySet> result=currentDesign.getDatatables(conditions,Boolean.parseBoolean(intCatalog),Boolean.parseBoolean(centralCatalog));
while (result.hasNext()) {
PropertySet dataTable = result.next();
if (dataTable instanceof Datatable) {
// if DT is part of internal catalog it will be of type Datatable
dataTableName = ((Datatable)dataTable).getName();
Utils.displayTextMessage("Internal catalog DT found, name is : "+ dataTableName);
} else {
// if it is not of type Datatable, it is probably CCitem
dataTableName = ((CCItem)dataTable).getName();
Utils.displayTextMessage("Central Catalog DT found, name is : "+ dataTableName);
}
}
} catch (Exception e) {
Utils.displayTextWarning("fail to get DT");
// TODO: handle exception
}
}
}
this method will search for datatable which has property part_number with given value as defined in value parameter ;
for example if you create custom command which invoke {testGetDTItem.getDT(205204-1,true,true)} - this will look in internal and in Central Catalog for DataTable which has the parameter part_number with value 205204-1 in one of its DataSet ;
Best regards,
Gaby
Thanks Gaby,
The bit about CCItem helped lot - I now have the datatables being found. Unfortunately I'm then calling design.getAssociatesItemsList(dt, true, true); and still getting a NullPointerException!
I found that in the initial case the design in question had an item that was reported as missing from the Central Catalog when running Verify Catalog. However, for the getAssociates call I have confirmed that Verify Catalog does not return any errors.
Also! Why would the getDatatables search return a datatable, when it's actually searching in the datasets? It would be far more useful if it returned the matching dataset(s), since I can just call ds.getOwner() to get the Datatable if I really need it. I know the method is called getDatatables but it is a bit annoying, since I now need to search through the datasets of the returned datatable to mimic the search and find the one that initially matched.
Thanks
Martin
Hi Martin,
please try following code (work fine in creo Schematics 3.0 M020):
public static void getDT(String value, String intCatalog, String centralCatalog) throws RSDException{
try {
Design currentDesign=Design.getCurrentDesign();
Condition condition = new SimpleCondition("part_number", "eq", value);
Condition[] conditions = {condition};
ArrayList<String> classList =new ArrayList<String>();
classList.add("block");
classList.add("fibre");
classList.add("group");
Iterator<PropertySet> result=currentDesign.getDatatables(conditions,Boolean.parseBoolean(intCatalog),Boolean.parseBoolean(centralCatalog));
String dataTableName;
while (result.hasNext()) {
PropertySet dataTable = result.next();
if (dataTable instanceof Datatable) { //if DT is part of internal catalog it will be of type Datatable
dataTableName = ((Datatable)dataTable).getName();
Utils.displayTextMessage("Internal catalog DT found, name is : "+ dataTableName);
} else {
dataTableName = ((CCItem)dataTable).getName();
Utils.displayTextMessage("Central Catalog DT found, name is : "+ dataTableName);
}
ArrayList<PropertySet> assocatedItems = currentDesign.getAssociatesItemsList(dataTable, true, true); // For use in Creo Schematics 2.0
// ArrayList<PropertySet> assocatedItems = currentDesign.getAssociatesItemsList(dataTable, classList , true, true); //For use in Creo Schematics 3.0 M020 or later
Iterator<PropertySet> propIt=assocatedItems.iterator();
while (propIt.hasNext()) {
PropertySet propertySet = (PropertySet) propIt.next();
Utils.displayTextMessage("Associated artifacts: " + propertySet.getStringProperty("full_name"));
} catch (Exception e) {
Utils.displayTextWarning("fail to get DT");
}
}
}
notice the following :
Best Regards ,
Gaby
Hi Gaby,
So I've only just been struck by the change in Creo 3 to getAssociatesItemsList. It's unfortunate that they changed an API method between versions and didn't update the documentation correctly either:
It still says:
pset—A property set that is an instance of a datatable or a central catalog item
representing a datatable object.
It also doesn't mention the string array!
Now I need to work out how to create a version that will work for Creo 2 and 3!