Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X
Hi,
I am trying to extract the values of generics and instances in a family table using jlink api. I was successful in extracting the values of instances but not generics.
In the attached image , First row indicates the generic, Rest of the rows are instances.
Using the below code I am able to get the instance values but not generics.
Can any one let me know if there is any API to extract generic values.
Thanks.
ParamValue dimV = ((FamilyMember) proeModel).GetCell(colValue, row);
Try this!
It looks like you treat the Generic Dimensions as Model Parameters not FamilyMember Items.
******************************************************************************************************
try {
//Get current model(open the Generic model)
Model model =curSession.GetCurrentModel();
//Get a list of all Columns in the Row
FamilyTableColumns colList = ((FamilyMember)model).ListColumns();
//Loop thru each Column in the list
for(int j=0;j<colList.getarraysize();j++) {
FamilyTableColumn currentColumn = colList.get(j);
//Get column name
String cName = currentColumn.GetSymbol();
//Get generic dimension
//If all the Parameter Value Types are always the same,
//you can ditch the "getParamValueAsString" Method.
//But testing for the type makes it more universal.
String genDim = getParamValueAsString(model.GetParam(cName));
//Prints to a System window
//If you don't have a System Console you can send it somewhere else!!!
System.out.println("Generic Dimension @ " +cName +" = "+genDim);
}
}catch (jxthrowable e) {
e.printStackTrace();
}
}
******************************************************************************************************
/**
* Method to get a String Value of a Parameter
*
*/
public static String getParamValueAsString (Parameter param)
{
String paramVal = "UNDEFINED";
try {
int type = param.GetValue().Getdiscr().getValue();
switch (type)
{
case ParamValueType._PARAM_STRING:
paramVal = param.GetValue().GetStringValue();;
break;
case ParamValueType._PARAM_INTEGER:
int iVal = param.GetValue().GetIntValue();
paramVal ="" +iVal;
break;
case ParamValueType._PARAM_BOOLEAN:
boolean Bval = param.GetValue().GetBoolValue();
paramVal = "" +Bval;
break;
case ParamValueType._PARAM_DOUBLE:
double Dval = param.GetValue().GetDoubleValue();
paramVal = "" +Dval;
break;
case ParamValueType._PARAM_NOTE:
paramVal = param.GetValue().GetStringValue();
break;
default:
System.out.println("unknown Pro/E parameter type: " +paramVal);
paramVal = "UNDEFINED";
break;
}
} catch (jxthrowable e) {
e.printStackTrace();
}
return (paramVal);
}
******************************************************************************************************
Thanks . This solved my problem.
But using this code I am able to retrieve only dimension values but not the feature values. For feature I am getting values as null .
I see what you mean, for some reason a Y/N response to a Feature is not the same as a Boolean YES/NO response to a Parameter. I think I have an idea but I need to try it out.
Yes, I think you got my point. Just for more clarification I will explain through a snap shot.
In the attached snap shot I have marked F77 and F177 columns in red. I have marked it only for first row (Feature of generics ). F77 and F177 have values Y and Y respectively. Using the code which you gave I was able to retrieve values of all the coloumns ( d2, d3, d14,d15 and d24 except F77 and F177 for generics) .
I put a print statement as below:
Parameter cNameValue = proeModel.GetParam(cName);
System.out.println("*****************@@@@@@@@@@@@@@@ paramter" + cNameValue);
String genDim = getParamValueAsString(proeModel.GetParam(cName));
Parameter value prints null for F77 and F177. So here is where I am struck.
Well after making a call to PTC this is there response:
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
It seems there isn't any direct function available to read this information. However, you may try with below approach and that might help.
Steps:
---------------------------------------------------------------------------------------------------------------------------------------------------------------
This is the updated Code:
try {
//Get current model(open the Generic model)
Model model =curSession.GetCurrentModel();
//Get a list of all Columns in the Row
FamilyTableColumns colList = ((FamilyMember)model).ListColumns();
//Loops thru each Column in the list
for(int j=0;j<colList.getarraysize();j++) {
//Initialize variable
String genVal = null;
//Get the Column
FamilyTableColumn currentColumn = colList.get(j);
//Get column name
String cName = currentColumn.GetSymbol();
// System.out.println("cName = " +cName);
//Get Value Type
int cType = currentColumn.GetType().getValue();
// System.out.println("Type = " +cType);
//Get generic values
//If Type is parameter
if(cType==0 || cType==1)genVal = getParamValueAsString(model.GetParam(cName));
//If Type is Feature
if(cType==3)genVal = getFeatStatus(currentColumn);
//Prints to a System window
System.out.println("Generic Value @ " +cName +" = "+genVal);
}
}catch (jxthrowable e) {
e.printStackTrace();
}
}
public static String getFeatStatus (FamilyTableColumn col) {
String strVal = "UNDEFINED";
try {
ModelItem feature = ((FamColModelItem) col).GetRefItem();
int status = ((Feature) feature).GetStatus().getValue();
switch (status)
{
case 0:
strVal = "Y";
break;
case 5:
strVal = "N";
break;
default:
System.out.println("unknown feature status type: <" +status +">");
strVal = "UNDEFINED";
}
} catch (jxthrowable e) {
e.printStackTrace();
}
return (strVal);
}
public static String getParamValueAsString (Parameter param)
{
String paramVal = "UNDEFINED";
try {
int type = param.GetValue().Getdiscr().getValue();
switch (type)
{
case ParamValueType._PARAM_STRING:
paramVal = param.GetValue().GetStringValue();;
break;
case ParamValueType._PARAM_INTEGER:
int iVal = param.GetValue().GetIntValue();
paramVal ="" +iVal;
break;
case ParamValueType._PARAM_BOOLEAN:
boolean Bval = param.GetValue().GetBoolValue();
paramVal = "" +Bval;
break;
case ParamValueType._PARAM_DOUBLE:
double Dval = param.GetValue().GetDoubleValue();
paramVal = "" +Dval;
break;
case ParamValueType._PARAM_NOTE:
paramVal = param.GetValue().GetStringValue();
break;
default:
System.out.println("unknown Pro/E parameter type: <" +paramVal +">");
paramVal = "UNDEFINED";
break;
}
} catch (jxthrowable e) {
e.printStackTrace();
}
return (paramVal);
}
}
Awesome . Thanks I got the values perfectly
Cool! Glad it worked. You might want to create a third Switch statement in place of the two IF statements for cType. (There are 25 different types) I shortcut the process in my code and only account for type 0, 1 & 3. using the two IF statements. See "pfcFamily.FamilyColumnType" in the J-Link library.
0 = "FAM_USER_PARAM"
1 = "FAM_DIMENSION"
3 = "FAM_FEATURE"
ect...
Good Luck!