Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

Programatically how to retrive the objects present in the workspace

RaikarRaghu
12-Amethyst

Programatically how to retrive the objects present in the workspace

I am trying to retrieve the WTParts / EPMdocument from the workspace, it was throwing error it was saying that the query is wromng.

 

help me to retrieve the objects from the workspace.

 

this is my code.


This is my workspace id iam passing :

private static String WorkspaceNumber = "OR:wt.epm.workspaces.EPMWorkspace:1150900;

From this method iam getting the workspace:

private static EPMWorkspace getWorkspaceById(String WorkspaceNumber ) {

try {

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

wt.fc.WTReference wtReference = referenceFactory.getReference(workspaceId);

return (EPMWorkspace) wtReference.getObject(); // Returns the workspace object

} catch (Exception e) {

System.err.println("Error fetching workspace by ID: " + workspaceId);

e.printStackTrace();

return null; // Return null if workspace cannot be fetched

}

}

This is the method i used to retrive objects present in the workspace

private static List<EPMDocument> getEPMDocumentsInWorkspace(EPMWorkspace workspace) throws WTException {

List<EPMDocument> epmDocuments = new ArrayList<>();

QuerySpec query = new QuerySpec(EPMDocument.class);

query.appendWhere(new SearchCondition(EPMDocument.class, "thePersistInfo.theObjectIdentifier.id", SearchCondition.EQUAL, workspace.getPersistInfo().getObjectIdentifier().getId()), null);

 

QueryResult results = PersistenceHelper.manager.find(query);

System.out.println("results: "+results.size());

while (results.hasMoreElements()) {

Persistable per = (Persistable) results.nextElement();

System.out.println("per "+per.toString());

if(per instanceof EPMDocument) {

epmDocuments.add((EPMDocument) per);

}

}

return epmDocuments;

}

12 REPLIES 12

d_graham_0-1736286291482.png

 

d_graham_2-1736286373596.png

 

 

Hello,

 

In my scenario, I have multiple EPMDocuments Assembly  within a workspace that are checked out (e.g., 123.SLDASM). Iwant to retrieve all these EPMDocuments that are checked out, and then check them in programmatically.

 

Regards

Raikar

HelesicPetr
22-Sapphire II
(To:RaikarRaghu)

Hi @RaikarRaghu 

It would be nice to see full stack error 

PetrH

Hello,

Any solution you have to retrieve the available objects in the workspace. you know any API please share it.

 

Regards

Raikar

@RaikarRaghu 

Why are you ignoring Petr's question? We're trying to help you, which is not always easy. Print a stack trace or describe exactly what's not working. The best approach is to always include the Windchill version.

I’m guessing your code is working, and you’re able to retrieve the assemblies, but you’re unable to check them back in. Is that the case?

Hello,

Yes, I am unable to check in the CAD assemblies. i found the API to retrieve the available EPMDocuments from the workspace(CS244949).but I not able to check-in from the workspace.

 

Regards

Raikar

HelesicPetr
22-Sapphire II
(To:RaikarRaghu)

Hi @RaikarRaghu 

@BjoernRueegg  is right. Why do you not share any errors? 

I can say, that the query definition is wrong because you search for EPMDocument but you provide the Workspace ID so it can not work at all..

 

btw Windchill has a helper for Workspace, and it can retrieve the objects from workspace

 

PS> EPMWorkspaceHelper

PetrH

Hello,

Yes, Thank you.

I found the article regarding to this, I think it will work on this.

 

WTSet objsInWS = EPMWorkspaceHelper.manager.getObjectsInWorkspace(workspace, EPMDocument.getClass());
Iterator iterator = objsInWS.iterator();
while (iterator.hasNext()) {
EPMDocument keyobj = (EPMDocument)((ObjectReference)iterator.next()).getObject();
}

Regards

Raikar

HelesicPetr
22-Sapphire II
(To:RaikarRaghu)

@RaikarRaghu 

Ok, and what is the error in the windchill log during the check-in process ?

PetrH 

Hello,

It was showing the assembly is already check-in.

error log.

RaikarRaghu_0-1737537607017.png

available object in workspace 

RaikarRaghu_1-1737537689231.png

This is the code I am using to do checkin:

workingepm = (EPMDocument) WorkInProgressHelper.service.workingCopyOf(epmDocument);
checkincollection.put(workingepm,null);

// Now we proceed with the check-in operation using the provided API
if (!checkincollection.isEmpty()) {
workspace = getWorkspaceById(WorkspaceNumber);
if (workspace != null) {

// Call the checkin method from EPMWorkspaceHelper
EPMWorkspaceHelper.manager.checkin(workspace, checkincollection, null, null, null);
System.out.println("Documents successfully checked in.");
}
}

HelesicPetr
22-Sapphire II
(To:RaikarRaghu)

hi @RaikarRaghu 

The error log should contains also all the stack-trace info with java row numbers. Thanks that I can find the problematic place and look what should be there. 

 

btw if the system tell you that the object is already checked-in that means that you have wrong collection or you work with commonspace version instead of the working modified object in the workspace.

 

PetrH

Hello,

 Yes, actually it was taking the EPMDocument from the common space which is original copy. now I figured out.

Thank you.

 

Regards

Raghavendra

Announcements
Top Tags