cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community email notifications are disrupted. While we are working to resolve, please check on your favorite boards regularly to keep up with your conversations and new topics.

i wanted to retrieve the generic part, and it has available in the workspace through api

RaikarRaghu
6-Contributor

i wanted to retrieve the generic part, and it has available in the workspace through api

Version: Windchill 12.1

 

Use Case: I have created Family instances in solid works and I associated those instance to WTparts. I am able retrieve all the parts, associated cad Documents and instances. I have added all the objects to workspace. Now I wanted to add the generic part of those instances to workspace . Can you help to add the generic part of those instances to workspace.


Description:

This is the code i am using to retrieve all the parts, associate cad documents and ins tances. Now i wanted to retrieve the generic parts and add it to workspace

 

 

private void updateChildParts(WTPart parentPart) throws WTException, WTPropertyVetoException {

System.out.println("Updating child parts for:Raghu " + parentPart.getNumber());

QueryResult partUsageLinks = WTPartHelper.service.getUsesWTPartMasters(parentPart);

while (partUsageLinks.hasMoreElements()) {

WTPartUsageLink usageLink = (WTPartUsageLink) partUsageLinks.nextElement();

WTPartMaster partMaster = (WTPartMaster) usageLink.getUses();

QueryResult resultSet = ConfigHelper.service.filteredIterationsOf(partMaster, new LatestConfigSpec());

while (resultSet.hasMoreElements()) {

WTPart childPart = (WTPart) resultSet.nextElement();

try {

System.out.println("Processing child part: " + childPart.getNumber());

if (isVariantPart(childPart)) {

EPMDocument associatedEPM = getAssociatedEPM(childPart);

if (associatedEPM == null) {

EPMDocument copy = saveAsCADAssembly(getEmptyCADAssembly(), childPart);

createLink(copy, childPart);

}

}

addAllToWorkspace(childPart);

// Recursively process the child parts

updateChildParts(childPart);

} catch (Exception e) {

e.printStackTrace();

throw new WTException("Error processing child part: " + childPart.getNumber() + ": " + e.getMessage());

}

}

}

}

 

 

private void addAllToWorkspace(WTPart part) throws WTException {

try {

System.out.println("Adding part to workspace: " + part.getNumber());

addToWorkspace(part);

EPMDocument associatedEPM = getAssociatedEPM(part);

if (associatedEPM != null) {

addToWorkspace(associatedEPM);

}

} catch (Exception e) {

e.printStackTrace();

throw new WTException("Error adding part and its related documents to the workspace: " + e.getMessage());

}

}

 

private void addToWorkspace(Persistable persistable) throws WTException {

try {

System.out.println("Adding to workspace: " + persistable);

wt.fc.ReferenceFactory referenceFactory = new wt.fc.ReferenceFactory();

wt.epm.workspaces.EPMWorkspace workspace = (wt.epm.workspaces.EPMWorkspace) referenceFactory

.getReference("OR:wt.epm.workspaces.EPMWorkspace:1150900").getObject();

 

wt.fc.collections.WTHashSet collection = new wt.fc.collections.WTHashSet();

 

if (persistable instanceof EPMDocument) {

EPMDocument epmDoc = (EPMDocument) persistable;

System.out.println("Adding EPMDocument to collection: " + epmDoc.getNumber());

collection.add(epmDoc);

 

// Get the EPMDocument configuration

wt.epm.workspaces.EPMAsStoredConfigSpec asStored = wt.epm.workspaces.EPMAsStoredConfigSpec.newEPMAsStoredConfigSpec(epmDoc);

wt.fc.QueryResult queryResult = wt.epm.structure.EPMStructureHelper.service.navigateReferencesToIteration(epmDoc, null, true, asStored);

 

while (queryResult.hasMoreElements()) {

EPMDocument referencedDoc = (EPMDocument) queryResult.nextElement();

System.out.println("Adding referenced EPMDocument to collection: " + referencedDoc.getNumber());

collection.add(referencedDoc);

}

} else if (persistable instanceof WTPart) {

WTPart part = (WTPart) persistable;

System.out.println("Adding WTPart to collection: " + part.getNumber());

collection.add(part);

 

}

 

// Add the collection to the workspace

wt.epm.workspaces.EPMWorkspaceHelper.manager.addToWorkspace(workspace, collection);

System.out.println("Added collection to workspace");

 

} catch (Exception e) {

e.printStackTrace();

throw new WTException("Error adding object to workspace: " + e.getMessage());

}

}

3 REPLIES 3

Hi @RaikarRaghu,


Thank you for your question. 

It appears your post is well documented , but I am replying to raise awareness. Hopefully, another community member will be able to help.

 

Regards,

Vivek N
Community Moderation Team.


 

Hi @RaikarRaghu 

The generic is still CAD so you can use standard method to add it to the workspace. 

Try following method to get the generic from an instance.

QueryResult queryresult = EPMStructureHelper.service.navigateGeneric(epmdocument, null, true);

PetrH

Hello @RaikarRaghu

 

It looks like you have a response from a community member. If it helped you solve your question please mark the reply as the Accepted Solution. 

Of course, if you have more to share on your issue, please let the Community know so other community members can continue to help you.

Thanks,
Community Moderation Team.

Top Tags