Dealing with Manufacturing process plan
How do you create relation between manufacturing objects ?
Important steps are
1)Open context
2)Create Relation
2)Save BOM Window
3)Close Context
Open Context
com.teamcenter.services.strong.manufacturing.DataManagementService dataManagementService
= com.teamcenter.services.strong.manufacturing.DataManagementService.getService( connection );
//Get Plant Model object
ModelObject mdlPlantobbj=getModelObjectsFromUIDs(new String[]{"yUWhDLC_Y95QJC"},connection)[0];
OpenContextInput[] openContextInps = new OpenContextInput[1];
openContextInps[0] = new OpenContextInput();
openContextInps[0].object = getModelObjectsFromUIDs( new String[]{ "S8chkjqvY95QJC" }, connection )[0];
openContextInps[0].openAssociatedContexts = true; //This will open all context i.e if user has associated/linked something to Process then that will open in their respective context
openContextInps[0].openViews = true;
openContextInps[0].contextSettings = new CreateInput();
OpenContextsResponse openContexts = dataManagementService.openContexts( openContextInps );
OpenContextInfo openContextInfo = openContexts.output[0].contexts[0]; //Process context
ModelObject topLine = openContextInfo.context; //Process Top line
OpenContextInfo openContextInfo1 = openContexts.output[0].contexts[2];//WorkArea context
ModelObject factorytopline=openContextInfo1.context;
/*------ Create Relation Left=MEProcessRevision Right=MEWorkArea -> plant --------*/
//Get Plant Model object
ModelObject mdlPlantobbj=getModelObjectsFromUIDs(new String[]{"yUWhDLC_Y95QJC"},connection)[0];
com.teamcenter.services.strong.manufacturing.DataManagementService dataManagementService
= com.teamcenter.services.strong.manufacturing.DataManagementService.getService( connection );
ConnectObjectsInputData[] connectinfor = new ConnectObjectsInputData[1];
connectinfor[0] = new ConnectObjectsInputData();
connectinfor[0].targetObjects = new ModelObject[]{ leftObject };
SourceInfo sourceInfoobj=new SourceInfo() ;
sourceInfoobj.sourceObjects=new ModelObject[]{ mdlPlantobbj};
sourceInfoobj.additionalInfo.stringProps=
hmChildObjectAttributes; //Property to be set on MEWorkArea
sourceInfoobj.relationType= "MEWorkArea";//Used to set the Occurrence Type
sourceInfoobj.additionalInfo.boolProps.put("occTypeFromPreferenceFlag", false);
connectinfor[0].sourceInfo=sourceInfoobj;
ConnectObjectResponse connectObjects = dataManagementService.connectObjects(connectinfor);
connectObjects.newObjects; // This will give us array of BOMLine objects created
/*------ Create Relation Left=MEProcessRevision Right=Operation --------*/
ModelObject mdlOperationobbj=
getModelObjectsFromUIDs(new String[]{"idThVI8tY95QJC"},connection)[0];
com.teamcenter.services.strong.structuremanagement.StructureService strservice_oper=
com.teamcenter.services.strong.structuremanagement.StructureService.getService(connection);
ConnectObjectsInputData[] connectinforoperationandprocess=new ConnectObjectsInputData[1];
connectinforoperationandprocess[0]=new ConnectObjectsInputData();
connectinforoperationandprocess[0].targetObjects=
new ModelObject[]{topLineObject};//process topline
SourceInfo sourceInfoobjopME=new SourceInfo() ;
sourceInfoobjopME.sourceObjects=new ModelObject[]{mdlOperationobbj};
connectinforoperationandprocess[0].sourceInfo=sourceInfoobjopME;
ConnectObjectResponse connectObjects =
dataManagementService.connectObjects(connectinforoperationandprocess);
//How to set the Bomline attribute
//i.e how to set the find number or other attibute on operation BOMLine created recently
//This is achieved using
com.teamcenter.services.strong.bom.StructureManagementService ds1 = com.teamcenter.services.strong.bom.StructureManagementService.getService( connection );
AddOrUpdateChildrenToParentLineInfo[] infos = new AddOrUpdateChildrenToParentLineInfo[1];
infos[0] = new AddOrUpdateChildrenToParentLineInfo();
infos[0].parentLine = topLineObject;
ItemElementLineInfo[] itemElements = new ItemElementLineInfo[1];
itemElements[0] = new ItemElementLineInfo();
itemElements[0].itemElementline
= (BOMLine) connectObjects.newObjects[0];//This is operation BOMLine got from execution of connectObjects method
itemElements[0].itemElementLineProperties.put( "TEMPLATE ACTION", "Reference" );
itemElements[0].itemElementLineProperties.put( "bl_sequence_no", "90" );
infos[0].itemElements = itemElements;
AddOrUpdateChildrenToParentLineResponse addOrUpdateChildrenToParentLine =
ds1.addOrUpdateChildrenToParentLine( infos );
/*------ Create Relation Left=Operation Right= Document --------*/
ModelObject mdlDocumentobbj=
getModelObjectsFromUIDs(new String[]{"SxRhkmxTY95QJC"},connection)[0];
ConnectObjectsInputData[] connectinfor=new ConnectObjectsInputData[1];
connectinfor[0]=new ConnectObjectsInputData();
connectinfor[0].targetObjects=
new ModelObject[]{operationline};//operationline is operation BOMLine to which we need to add child document
SourceInfo sourceInfoobj=new SourceInfo() ;
sourceInfoobj.sourceObjects=new ModelObject[]{mdlDocumentobbj};
sourceInfoobj.relationType="KK_ManufacturingDocumentation"; //Occurrence Type
sourceInfoobj.additionalInfo.boolProps.put("occTypeFromPreferenceFlag", false);
//Above bollProps must be specified to set occurrence type
connectinfor[0].sourceInfo=sourceInfoobj;
dataManagementService.connectObjects(connectinfor);
/*------ Create Relation Left=Operation Right=RR_Part - > optegra part --------*/
ModelObject mdloptegraobj=
getModelObjectsFromUIDs(new String[]{"j9chklAWY95QJC"},connection)[0];
ConnectObjectsInputData[] connectinforoper_optegrapart=new ConnectObjectsInputData[1];
connectinforoper_optegrapart[0]=new ConnectObjectsInputData();
connectinforoper_optegrapart[0].targetObjects=new ModelObject[]{operationline_OPER_optegra};//operationline_OPER_optegra is operation BOMLine to which we need to add child part
SourceInfo sourceInfoobj_oper_optegrapart=new SourceInfo() ;
sourceInfoobj_oper_optegrapart.sourceObjects=new ModelObject[]{mdloptegraobj};
sourceInfoobj_oper_optegrapart.relationType=
"KK_Reference"; //Occurrence Type it can be //MEResource/MECONSUMED
sourceInfoobj_oper_optegrapart.additionalInfo.boolProps.put("occTypeFromPreferenceFlag", false);//This must be specified to set occurrence type
connectinforoper_optegrapart[0].sourceInfo=sourceInfoobj_oper_optegrapart;
dataManagementService.connectObjects(connectinforoper_optegrapart);
//SAVE BOM WINDOW
com.teamcenter.services.strong.cad.StructureManagementService cadSMService =
com.teamcenter.services.strong.cad.StructureManagementService.getService(connection);
BOMWindow bomwindow1=(BOMWindow)topLine.get_bl_window();
cadSMService.saveBOMWindows(new BOMWindow[]{bomwindow1});
//Close Context
dataManagementService.closeContexts( new ModelObject[]{ topLine } );
How to Print complete BOM Recursively
private void printBoMLine(ModelObject topLine, Connection connection) throws NotLoadedException
{
if ( topLine instanceof BOMLine )
{
BOMLine topLineObject = (BOMLine) topLine;
DataManagementService dataManagementService =
DataManagementService.getService( connection );
dataManagementService.getProperties( new ModelObject[] { topLineObject }, new String[]{ "bl_all_child_lines", "bl_formatted_title" } );
String sName = topLineObject.get_bl_formatted_title();
ModelObject[] allChildLines = topLineObject.get_bl_all_child_lines();
for ( int i = 0; i < allChildLines.length; i++ )
{
BOMLine bomLine = (BOMLine) allChildLines[i];
dataManagementService.getProperties( new ModelObject[] { bomLine }, new String[]{ "bl_formatted_title" } );
System.out.println( bomLine.get_bl_formatted_title() );
printBoMLine( bomLine, connection );
}
}
}
/*---Create Collaboration Context and create Relation to Process,Product,Plant context----*/
CreateIn[] createIn = new CreateIn[1];
createIn[0] = new CreateIn();
createIn[0].data.stringProps.put( "object_name", "cc_object_name" );
createIn[0].data.boName = "MECollaborationContext";
//dataManagementService1 is com.teamcenter.services.strong.core.DataManagementService object
CreateResponse createObjects =
dataManagementService1.createObjects( createIn );// Create Collaboration context object
MECollaborationContext modelObject =
(MECollaborationContext) createObjects.output[0].objects[0]; //Get the Collaboration context object
//Now link Other context object to Collaboration context
//When you do open context its output response gives you all context objects
CreateConfigInput[] createConfigInp = new CreateConfigInput[1];
createConfigInp[0] = new CreateConfigInput();
createConfigInp[0].modifyObject = modelObject;//Collaboration context object
//Info about process context
CreateConfigInput[] internalConfigData = new CreateConfigInput[3];
internalConfigData[0] = new CreateConfigInput();
internalConfigData[0].data.type = "MEProcessContext";
internalConfigData[0].data.stringProps.put( "object_name", "process context name " );
//actual object of process context
internalConfigData[0].basedOn =
openContexts.output[0].contexts[0].context;//openContexts is OpenContextsResponse object ,this line gives you Process context which is process top line
//Info about Product context
internalConfigData[1] = new CreateConfigInput();
internalConfigData[1].data.type = "MEProductContext";
internalConfigData[1].data.stringProps.put( "object_name", "prod context name " );
//actual object of product context
internalConfigData[1].basedOn =
openContexts.output[0].contexts[1].context;//openContexts is OpenContextsResponse object ,this line gives you Product context which is process top line
//Info about Product context
internalConfigData[2] = new CreateConfigInput();
internalConfigData[2].data.type = "MEPlantContext";
internalConfigData[2].data.stringProps.put( "object_name", "plant context name" );
//actual object of plant context
internalConfigData[2].basedOn =
openContexts.output[0].contexts[2].context;//openContexts is OpenContextsResponse object ,this line gives you Plant context which is process top line
createConfigInp[0].internalConfigData = internalConfigData;
CreateConfigResponse createOrUpdateConfigObjects =
dataManagementService.createOrUpdateConfigObjects( createConfigInp );// Create Relation between Collaboration context and Process,Product,plant context
/*-------------------------------------------------------------------------------------------------------*/
/*--------------------------------Create Form and Attach to Collaboration Context------------------------*/
//Create Form
createIn[0] = new CreateIn();
createIn[0].data.stringProps.put( "object_name", "sample_Info_name" );
createIn[0].data.stringProps.put( "object_desc", "Sample_Info desc" );
createIn[0].data.boName = "FormObjectName";//This is Business Object name for form
CreateResponse createObjectsForm =
dataManagementService1.createObjects( createIn ); // create form object
//End Create form
CreateOrUpdateRelationsInfo[] inps = new CreateOrUpdateRelationsInfo[1];
inps[0] = new CreateOrUpdateRelationsInfo();
inps[0].primaryObject = modelObject;//collaboration context object
SecondaryData[] secondaryData = new SecondaryData[1];
secondaryData[0] = new SecondaryData();
secondaryData[0].secondary =
createObjectsForm.output[0].objects[0];//Created form object
inps[0].secondaryData = secondaryData;
inps[0].relationType = "IMAN_reference";
//dataManagementService1 is com.teamcenter.services.strong.core.DataManagementService object
CreateOrUpdateRelationsResponse createOrUpdateRelations =
dataManagementService1.createOrUpdateRelations( inps, false ); //Create relation between Collaboration context and form