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

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

Creating a Creao/Elements Direct Modeling EPMDocument via API

agalli
5-Regular Member

Creating a Creao/Elements Direct Modeling EPMDocument via API

Hello,

i'm trying to create via API an EPMDocument and upload to it a Creo/Elements Direct Modeling .sdpc file.

Here is my java code:

public static EPMDocument createNewModelingEPMDocument(String epmnumber, String sdpcfilename, String sd_gfxfilename, String model_id) throws PropertyVetoException, WTException, IOException {
EPMDocument document = null;
// Create new EPDocument from sdpc template
EPMAuthoringAppType appType = EPMAuthoringAppType.toEPMAuthoringAppType("COCRMOD");
EPMDocumentType docType = EPMDocumentType.toEPMDocumentType("CADCOMPONENT");
EPMContextHelper.setApplication(EPMApplicationType.toEPMApplicationType("EPM"));
File sdpcfile = new File(sdpcfilename);
File sd_gfxfile = new File(sd_gfxfilename);
document = EPMDocument.newEPMDocument(epmnumber, epmnumber, appType, docType, sdpcfile.getName().toLowerCase());
// Set creation location
PDMLinkProduct creationContext = WindchillUtils.getProductByName("MY_PRODUCT");
WTContainerRef c_ref = WTContainerRef.newWTContainerRef(creationContext);
Folder folder = FolderHelper.service.getFolder("/Default/CAD Documents" , c_ref);
document.setContainer(folder.getContainer());
FolderHelper.assignLocation(document, folder);
EPMDocumentMaster master = (EPMDocumentMaster) document.getMaster();
master.setGlobalID(model_id);
document = (EPMDocument) PersistenceHelper.manager.store(document);
// Upload sdpc file
FileInputStream fis = new FileInputStream(sdpcfile);
ContentHolder contentholder = document;
ApplicationData applicationdata = ApplicationData.newApplicationData(contentholder);
applicationdata.setCategory("GENERAL");
applicationdata.setRole(ContentRoleType.MULTI_PRIMARY);
String wncfilename = "{$CAD_NAME}";
applicationdata.setFileName(wncfilename);
applicationdata.setFileSize(sdpcfile.length());
applicationdata = ContentServerHelper.service.updateContent(contentholder, applicationdata, fis);
document = (EPMDocument) PersistenceHelper.manager.refresh(document, true, true);
fis.close();
// Upload sd_gfx file
FileInputStream fis1 = new FileInputStream(sd_gfxfile);
ApplicationData applicationdata_gfx = ApplicationData.newApplicationData(contentholder);
applicationdata_gfx.setCategory("GENERAL");
applicationdata_gfx.setRole(ContentRoleType.MULTI_PRIMARY);
wncfilename = "{$CAD_NAME}.sd_gfx";
applicationdata_gfx.setFileName(wncfilename);
applicationdata_gfx.setFileSize(sd_gfxfile.length());
applicationdata_gfx = ContentServerHelper.service.updateContent(contentholder, applicationdata_gfx, fis1);
document = (EPMDocument) PersistenceHelper.manager.refresh(document, true, true);
fis1.close();

return document;
}

The input parameter are the EPM Number, the .spdc path to my local drive, the sd_gfx (lightweight representation) path to my local drive and the sysid of the 3D Model.

 

If i try to reload the newly created EPMDocument the Windchill Work Group Manager try to load the attached file as a 2D Drawing and not as a 3D Component. It's give me the error: "The specified file is not a valid MI file".

If i try to manually load the source .sdpc file from my local drive the component is correcly loaded in Creo/Elements Direct Modeling.

Im' working on Windchill 13.0.0.0 and Creo/Elements Direct Modeling 20.6.

 

Any help will be very appreciated.

Thank you so much.

 

Regards

2 REPLIES 2
Fadel
22-Sapphire I
(To:agalli)

can you check if you have any IT encryption ,as advised in https://www.ptc.com/en/support/article/CS356393 

Fede
agalli
5-Regular Member
(To:Fadel)

Hi Fadel,

thank you so much for your reply.

The file is brand new .sdpc file saved directly from Creo/Elements Direct Modeling.

If i try to load it directly from the local drive it can be loaded without any problem,

I don't think is a problem related to the specific file.

I think that the problem is how to load it in Windchill via API...

 

Thanks again.

Top Tags