Common Question ITK Algorithm and Code
Common Question ITK Algorithm and Code
Common Question ITK Algorithm and Code
1
1.Based on the value entered in the one property according to that second property LOV should be selected if entered
value is positive first Lov value should be select if not second value should be select.
ALGORITHM
(Every api is sent to the api check function.)
(After fetching the tag, all tags are sent to the function to check for NULLTAG.)
1. Initialize variables:
tag_t tlov_tag (for LOV tag)
char* cpPropName (for the property name to check)
char** cdpLovValues (for LOV values)
const char* cpLovPropName (for the LOV property name)
int iCode (to store the property value)
int iVlaues (to store the number of LOV values)
2. Check if ‘tObjectTag’is not a null tag .
If ‘tObjectTag’is null, log an error message and exit.
Otherwise, proceed.
3. Retrieve the integer property value (‘iCode’) using AOM_ask_value_int with ‘cpPropName’.
4. Retrieve the LOV tag (‘tlov_tag’) associated with the LOV property (‘cpLovPropName’) using AOM_ask_lov.
5. Check if ‘tlov_tag’is not a null tag.
If ‘tlov_tag’is null, log an error message and exit.
Otherwise, proceed.
6. Retrieve the LOV values (‘cdpLovValues’) as array format of strings from ‘tlov_tag’using
LOV_ask_values_string.
7. Determine whether ‘iCode’is even or odd by checking if ‘iCode % 2’:
If ‘iCode’is even, log a message indicating that the value is even in the syslog.
Set the property of ‘tObjectTag’with ‘cpLovPropName’to the first LOV value (cdpLovValues[0]) using
AOM_set_value_string.
If ‘iCode’is odd, log a message indicating that the value is odd in the syslog.
Set the property of ‘tObjectTag’with ‘cpLovPropName’to the second LOV value (cdpLovValues[1]) using
AOM_set_value_string.
Log a message indicating the successful LOV value update.
8. Free the memory allocated for ‘cdpLovValues’using SAFE_SM_FREE.
9. END.
CODE
#include <A7new_lib_test_itk/A7Extension_itk.hxx>
#undef ITKCALL // The macro function to check for the api errors
#define ITKCALL(argument) \
do { \
int retcode = argument; \
if (retcode != ITK_ok) { \
char* s; \
TC_write_syslog(“Function call: %s\n”, #argument); \
TC_write_syslog(“Returns [%d]\n”, retcode); \
EMH_store_error(EMH_severity_error, retcode);\
EMH_ask_error_text(retcode, &s); \
TC_write_syslog(“Teamcenter ERROR--------------------: [%s]\n”, s); \
TC_write_syslog(“File: %s, Line-----------------------: %d\n\n”, __FILE__, __LINE__); \
if (s != NULL) MEM_free(s); \
}\
} while (0)
char* cpPropName=“a7Item_code”;
char **cdpLovValues = NULL;
const char* cpLovPropName=“a7Item_LOV”;
int iCode=0;
int iVlaues=0;
CheckNull(tObjectTag);
ITKCALL(AOM_ask_value_int(tObjectTag, cpPropName, &iCode)); // feching the property value
ITKCALL(AOM_ask_lov(tObjectTag,cpLovPropName, &tlov_tag)); // feching the lov tag using the
property name
CheckNull(tlov_tag);
ITKCALL(LOV_ask_values_string(tlov_tag, &iVlaues, &cdpLovValues)); // storing the lov value in the
array format
}
SAFE_SM_FREE(cdpLovValues);
TC_write_syslog(“\nExiting A7Extension_itk function\n”);
return 0;
}
Question no.2
2.While creating ITEM empty dataset should be created with name as itemid_revision_id_ATT in pdf format.
ALGORITHM
(Every api is sent to the api check function.)
(After fetching the tag, all tags are sent to the function to check for NULLTAG.)
1. Initialize various variables and tags:
tag_t tSpecification, tRelation, tDatasettype, titem, ttRev, tnewDataset
int iSize
char* cpRevID, cpItemid, cpcRevid
char* newDsName
2. Check if ‘tRev’ is not a null tag.
If ‘tRev’ is null, log an error message and exit.
Otherwise, proceed.
3. Retrieve the revision ID (‘cpRevID’) of ‘tRev’using ITEM_ask_rev_id2.
4. Retrieve the value of the “current_id” property (‘cpItemid’) from ‘tRev’using AOM_ask_value_string.
5. Find the item with the current ID (‘cpItemid’) and store its tag in ‘titem’.
6. Retrieve the latest revision of ‘titem’and store its tag in ‘ttRev’.
7. Retrieve the “current_id” and “current_revision_id” properties from ‘ttRev’and store them in ‘cpItemid’and
‘cpcRevid’, respectively.
8. Calculate the size (‘iSize’) required to store the name for the dataset based on ‘cpItemid’and ‘cpcRevid’.
9. Allocate memory for the ‘newDsName’character array with a size of ‘iSize * sizeof(char)’.
10. Find the dataset type (‘tDatasettype’) with the name “PDF” using AE_find_datasettype2.
11. Check if ‘tDatasettype’is not a null tag.
If ‘tDatasettype’is null, log an error message and exit.
Otherwise, proceed.
12. Log a message indicating that the dataset type is fetched.
13. Create a new dataset (‘tnewDataset’) with the specified dataset type, ‘newDsName’, “datasetDesc,” “001,” and
‘cpcRevid’using AE_create_dataset_with_id.
14. Check if ‘tnewDataset’is not a null tag.
If ‘tnewDataset’is null, log an error message and exit.
Otherwise, proceed.
15. Save ‘tnewDataset’using AOM_save_without_extensions.
16. Find the relation type “IMAN_specification” and store it in ‘tSpecification’using GRM_find_relation_type.
CODE
#include <A7new_lib_test_itk/A7Ext_itk_test2.hxx>
#undef ITKCALL // The macro function to check for the api errors
#define ITKCALL(argument) \
do { \
int retcode = argument; \
if (retcode != ITK_ok) { \
char* s; \
TC_write_syslog(“Function call: %s\n”, #argument); \
TC_write_syslog(“Returns [%d]\n”, retcode); \
EMH_store_error(EMH_severity_error, retcode);\
EMH_ask_error_text(retcode, &s); \
TC_write_syslog(“Teamcenter ERROR--------------------: [%s]\n”, s); \
TC_write_syslog(“File: %s, Line-----------------------: %d\n\n”, __FILE__, __LINE__); \
if (s != NULL) MEM_free(s); \
}\
} while (0)
iSize=tc_strlen(cpItemid)+tc_strlen(cpcRevid)+4; // calculating the size to store the name for the dataset
char* newDsName = (char*)MEM_alloc(iSize * sizeof(char)); // allocation of memory for the name variable
ITKCALL(AE_find_datasettype2(“PDF”,&tDatasettype)); // finding the data set tag
CheckNull1(tDatasettype);
ITKCALL(AE_create_dataset_with_id(tDatasettype,newDsName,”datasetDesc”,”001”, cpcRevid,
&tnewDataset)); // creation of dataset
CheckNull1(tnewDataset);
AOM_save_without_extensions(tnewDataset);
ITKCALL(GRM_find_relation_type(“IMAN_specification”,&tSpecification)); // finding the relation to attach the
created dataset to the item revision
CheckNull1(tSpecification);
TC_write_syslog(“-------------End-------------\n”);
return 0;
}
Question no.3
3. User should provide the CAR model, then based on that Car's three property should be set (ex. Mileage,
HP,Torque)
ALGORITHM
(Every api is sent to the api check function.)
(After fetching the tag, all tags are sent to the function to check for NULLTAG.)
1. Initialize various variables and constant property names:
const char* cpProModelName, cpProMileageName, cpProTorqueName, cpProHPName, cpPreferenceName.
char* cpToken, cpPropValue, cpModelName, cpTorque
char** cdpPref_Value
int iMileage, iHorsepower, iIndex, iPrefCount
2. Check if ‘tObjectTag’is not a null tag.
If ‘tObjectTag’is null, log an error message and exit.
Otherwise, proceed.
3. Retrieve the string property value (‘cpPropValue’) for ‘cpProModelName’ using AOM_ask_value_string.
4. Log the fetched property value.
5. Retrieve preference values (‘cdpPref_Value’) for ‘cpPreferenceName’using PREF_ask_char_values.
6. Iterate through the preference values for up to three models (iIndex from 0 to 2).
Set ‘cpToken’to the current preference value.
‘cpProTorqueName’with ‘cpTorque’.
CODE
#undef ITKCALL // Undefine the existing ITKCALL macro
#define ITKCALL(argument) \
do { \
int retcode = argument; \
if (retcode != ITK_ok) { \
char* s; \
TC_write_syslog("Function call: %s\n", #argument); \
TC_write_syslog("Returns [%d]\n", retcode); \
EMH_store_error(EMH_severity_error, retcode);\
EMH_ask_error_text(retcode, &s); \
TC_write_syslog("Teamcenter ERROR--------------------: [%s]\n", s); \
TC_write_syslog("File: %s, Line-----------------------: %d\n\n", __FILE__, __LINE__); \
if (s != NULL) MEM_free(s); \
/* Add your custom error handling code here */ \
}\
} while (0)
}
void setMultiplestrProperties(tag_t tObjectTag, const char* propertyName, char* value)
{
for(iIndex=0;iIndex<3;iIndex++){
cpToken = cdpPref_Value[iIndex];
if(cpToken!=NULL)
{
while(cpToken!=NULL)
{
cpModelName=tc_strtok(cpToken,"|"); // separate the preference value
iMileage=atoi(tc_strtok(NULL, "|"));// separate the preference value
cpTorque=tc_strtok(NULL, "|");// separate the preference value
iHorsepower=atoi(tc_strtok(NULL, "|"));// separate the preference value
if(tc_strcmp(cpModelName,cpPropValue)==0)
{
MEM_free(cdpPref_Value);
TC_write_syslog("\n--------------Operation Exit---------------------\n");
return 0;