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

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

Export Container Templates with code Windchill 12.1

Leon_Dietz
4-Participant

Export Container Templates with code Windchill 12.1

I wanted to know, if there is a way to export Container Templates with code, or a windchill shell command.
I couldn't find anything in the knowledge base, that's why I wanted to ask in a post.

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @Leon_Dietz 

Templates are clastic objects that have content and the content is XML. The content is an ApplicationData so you can use standard api to search the template and download it.

 

here is a code that gives you the content URL and download URL

 

QuerySpec queryspec;
String templateName="Product Design";
try
{
	queryspec = new QuerySpec();
	int idClassIssue = queryspec.appendClassList(DefaultWTContainerTemplate.class, true);
	CompositeWhereExpression andCondition = new CompositeWhereExpression(LogicalOperator.AND);
	andCondition.append(new SearchCondition(DefaultWTContainerTemplate.class, DefaultWTContainerTemplate.LATEST_ITERATION, SearchCondition.IS_TRUE), new int[]{idClassIssue});
	andCondition.append(new SearchCondition(DefaultWTContainerTemplate.class, DefaultWTContainerTemplate.NAME, SearchCondition.LIKE, templateName), new int[]{idClassIssue});
	queryspec.appendWhere(andCondition, new int[]{idClassIssue, idClassIssue});
	queryspec.appendOrderBy(new OrderBy(new ClassAttribute(DefaultWTContainerTemplate.class, DefaultWTContainerTemplate.MODIFY_TIMESTAMP), false), new int[]{0});

	QueryResult queryresult = PersistenceHelper.manager.find((StatementSpec) queryspec);
	while (queryresult.hasMoreElements())
	{
		Object object = queryresult.nextElement();
		if (object instanceof Persistable[])
		{
			DefaultWTContainerTemplate cam = (DefaultWTContainerTemplate) ((Persistable[])object)[0];
			ContentHolder syHold = ContentHelper.service.getContents(cam);
			Vector<ApplicationData> vectorOfAppData = ContentHelper.getContentListAll(syHold);
			Iterator<ApplicationData> appIter = vectorOfAppData.iterator();
			while (appIter.hasNext())
			{
				ApplicationData syAppData = appIter.next();
				ContentHolder holder = ContentHelper.service.getContents(cam);
				final URL viewContentURL = WVSContentHelper.getViewContentURL(syAppData, holder);
				final URL downloadURL = WVSContentHelper.getDownloadURL(syAppData, holder);
			}
		}
	}
} catch (QueryException e)
{
	e.printStackTrace();
} catch (WTException e)
{
	e.printStackTrace();
} catch (PropertyVetoException e)
{
	throw new RuntimeException(e);
}

 

PS: how to get inputStream

InputStream stream = ContentServerHelper.service.findContentStream(syAppData);

PetrH

View solution in original post

4 REPLIES 4

Hi @Leon_Dietz 

The Container Template ? so you need to download a XML definition of product/Library template? 

am I  Right?

 

PetrH

Yeah at the end I need Product/Library/Project Templates inform of xml Files, I could also create a xml file by hand, but I was wondering if there is another way already implemented within the windchill api.

Hi @Leon_Dietz 

Templates are clastic objects that have content and the content is XML. The content is an ApplicationData so you can use standard api to search the template and download it.

 

here is a code that gives you the content URL and download URL

 

QuerySpec queryspec;
String templateName="Product Design";
try
{
	queryspec = new QuerySpec();
	int idClassIssue = queryspec.appendClassList(DefaultWTContainerTemplate.class, true);
	CompositeWhereExpression andCondition = new CompositeWhereExpression(LogicalOperator.AND);
	andCondition.append(new SearchCondition(DefaultWTContainerTemplate.class, DefaultWTContainerTemplate.LATEST_ITERATION, SearchCondition.IS_TRUE), new int[]{idClassIssue});
	andCondition.append(new SearchCondition(DefaultWTContainerTemplate.class, DefaultWTContainerTemplate.NAME, SearchCondition.LIKE, templateName), new int[]{idClassIssue});
	queryspec.appendWhere(andCondition, new int[]{idClassIssue, idClassIssue});
	queryspec.appendOrderBy(new OrderBy(new ClassAttribute(DefaultWTContainerTemplate.class, DefaultWTContainerTemplate.MODIFY_TIMESTAMP), false), new int[]{0});

	QueryResult queryresult = PersistenceHelper.manager.find((StatementSpec) queryspec);
	while (queryresult.hasMoreElements())
	{
		Object object = queryresult.nextElement();
		if (object instanceof Persistable[])
		{
			DefaultWTContainerTemplate cam = (DefaultWTContainerTemplate) ((Persistable[])object)[0];
			ContentHolder syHold = ContentHelper.service.getContents(cam);
			Vector<ApplicationData> vectorOfAppData = ContentHelper.getContentListAll(syHold);
			Iterator<ApplicationData> appIter = vectorOfAppData.iterator();
			while (appIter.hasNext())
			{
				ApplicationData syAppData = appIter.next();
				ContentHolder holder = ContentHelper.service.getContents(cam);
				final URL viewContentURL = WVSContentHelper.getViewContentURL(syAppData, holder);
				final URL downloadURL = WVSContentHelper.getDownloadURL(syAppData, holder);
			}
		}
	}
} catch (QueryException e)
{
	e.printStackTrace();
} catch (WTException e)
{
	e.printStackTrace();
} catch (PropertyVetoException e)
{
	throw new RuntimeException(e);
}

 

PS: how to get inputStream

InputStream stream = ContentServerHelper.service.findContentStream(syAppData);

PetrH

Hey PetrH,

sorry for the late reply, I had something else to do in the meantime.
I just tried it out and after changing the code a bit it worked perfectly for me.

 

Thanks a lot that was exactly what I needed!

Top Tags