Skip to main content
4-Participant
September 22, 2023
Solved

Export Container Templates with code Windchill 12.1

  • September 22, 2023
  • 1 reply
  • 1795 views

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.

 

 

 

Best answer by HelesicPetr

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

1 reply

HelesicPetr
22-Sapphire II
22-Sapphire II
September 22, 2023

Hi @Leon_Dietz 

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

am I  Right?

 

PetrH

4-Participant
September 22, 2023

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.

HelesicPetr
22-Sapphire II
22-Sapphire II
September 22, 2023

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