Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X
Version: Windchill 13.0
Use Case: The goal is to create a URL that acts as a shortcut to download a STEP file for a CAD Document directly from the More Info page in Windchill. Instead of downloading the file manually from the Representations/Annotations table under the Content Tab, If i click a URL in the More Info section and trigger the download action for the STEP file.
Description:
The goal is to create a URL that acts as a shortcut to download a STEP file for a CAD Document directly from the More Info page in Windchill. Instead of downloading the file manually from the Representations/Annotations table under the Content Tab, If i click a URL in the More Info section and trigger the download action for the STEP file.
Solved! Go to Solution.
Been down this road and have worked on many iterations of the same fundamental problem. Moving it to the main details page will not be your user's final ask. Start from the EPMDocument itself to get the assumed default representation:
VisualizationHelper vizHelper = new VisualizationHelper();
Representation rep = vizHelper.getRepresentation(doc);
I have send this to a method that returns a bit more but is looking for file extension ".stp":
//processRep takes a representation and finds the STP or PDF's download link
//@param fileExt the type of file extension to look for
//@param rep the representation to look through
//@param ch the content holder where the file is located
//@returns a content message either download url, or telling user file not found.
private static ContentMessage processRep(String fileExt, Representation rep, ContentHolder ch) throws WTException, PropertyVetoException {
LOGGER.debug("Looking in representation: " + rep.getName() + ", id: " + IdentityFactory.getDisplayIdentifier(rep));
//Get the content within the representation
ContentHolder repContent = (ContentHolder)ContentHelper.service.getContents(rep);
Vector<?> appDatas = ContentHelper.getContentListAll(repContent);
for(int i = 0; i < appDatas.size(); i++) {
ApplicationData appData = (ApplicationData)appDatas.get(i);
LOGGER.debug("File found with name: " + appData.getFileName() + ", and role: " + appData.getRole());
//If the content is an additional file and matches the file extensions get the download url and return it.
if((appData.getRole().equals(ContentRoleType.ADDITIONAL_FILES) || appData.getRole().equals(ContentRoleType.SECONDARY)) && appData.getFileName().contains(fileExt)) {
LOGGER.debug("File found meets all conditions! Will download url and return it.");
ApplicationData ad = (ApplicationData)ContentHelper.getPrimary((FormatContentHolder)ch);
ContentMessage returned = new ContentMessage(ContentHelper.getDownloadURL(repContent, appData, false).toString(), null, true);
if(returned.getValid()) {
LOGGER.debug("file found is good");
}
else {
LOGGER.debug("File found is bad");
}
return returned;
}
}
//If fails to find a file return an error message to the user
LOGGER.debug("failed to find a file inside given representation");
return new ContentMessage(null, "Error: could not find " + fileExt + " file.<br>", false);
}
In the bean class I return is the download URL to the step file. That is what you need to render on your details page.
Been down this road and have worked on many iterations of the same fundamental problem. Moving it to the main details page will not be your user's final ask. Start from the EPMDocument itself to get the assumed default representation:
VisualizationHelper vizHelper = new VisualizationHelper();
Representation rep = vizHelper.getRepresentation(doc);
I have send this to a method that returns a bit more but is looking for file extension ".stp":
//processRep takes a representation and finds the STP or PDF's download link
//@param fileExt the type of file extension to look for
//@param rep the representation to look through
//@param ch the content holder where the file is located
//@returns a content message either download url, or telling user file not found.
private static ContentMessage processRep(String fileExt, Representation rep, ContentHolder ch) throws WTException, PropertyVetoException {
LOGGER.debug("Looking in representation: " + rep.getName() + ", id: " + IdentityFactory.getDisplayIdentifier(rep));
//Get the content within the representation
ContentHolder repContent = (ContentHolder)ContentHelper.service.getContents(rep);
Vector<?> appDatas = ContentHelper.getContentListAll(repContent);
for(int i = 0; i < appDatas.size(); i++) {
ApplicationData appData = (ApplicationData)appDatas.get(i);
LOGGER.debug("File found with name: " + appData.getFileName() + ", and role: " + appData.getRole());
//If the content is an additional file and matches the file extensions get the download url and return it.
if((appData.getRole().equals(ContentRoleType.ADDITIONAL_FILES) || appData.getRole().equals(ContentRoleType.SECONDARY)) && appData.getFileName().contains(fileExt)) {
LOGGER.debug("File found meets all conditions! Will download url and return it.");
ApplicationData ad = (ApplicationData)ContentHelper.getPrimary((FormatContentHolder)ch);
ContentMessage returned = new ContentMessage(ContentHelper.getDownloadURL(repContent, appData, false).toString(), null, true);
if(returned.getValid()) {
LOGGER.debug("file found is good");
}
else {
LOGGER.debug("File found is bad");
}
return returned;
}
}
//If fails to find a file return an error message to the user
LOGGER.debug("failed to find a file inside given representation");
return new ContentMessage(null, "Error: could not find " + fileExt + " file.<br>", false);
}
In the bean class I return is the download URL to the step file. That is what you need to render on your details page.
Hello @avillanueva
Thank you for the response, I hope you are doing well.
if user wants to download .pdf, .dxf and .dwg then the above method will return these files.
Thanks
Is that a question? Yes, what you showed is what the code is getting. You need to write something to retrieve and format the URL for download. What you know on the details page is the object ID of the EPMDocument. From there, the code finds the representations and files contained within returning a URL to that content. That is what you were asking for right?
While you are considering @avillanueva 's response, also consider voting on this idea: