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

Representation publishing from code using Publish rules

TamasBiro
11-Garnet

Representation publishing from code using Publish rules

Hi everyone,

 

I want to create a "shortcut" for a manual representation creation for an EPM document. The idea is to have preconfigured publish options and assign an action to do the actual call to the publisher. 

I have a PublishRules.xml uploaded to the  Site --> utilities --> Visualisation Configuration Administration. Because of the rules in this xml I have a dropdown combo (Output Options) on the "Chose Structure Type" step of the New representation wizard. The default value is "All" but if I select for example PDF it will start only one Publish job with the param-set selected.

Now if I want to call from an action the Publisher.doPublish(...) API as I read I have to use the PublisherAction to define the "Output Options".

 

This is the code that I'm using, but it will trigger the publisher like if I would left "All" in the combo (4 publish jobs will be created):

 

Publisher pub = new Publisher();
ReferenceFactory ref = new ReferenceFactory();
PublisherAction pa = new PublisherAction("pubrulename","PDF");
pub.doPublish(false,
		true,
		ref.getReferenceString((Persistable) commandBean.getElementOid().getRefObject()),
		(ConfigSpec)null,
		(ConfigSpec)null,
		true,
		"alternate", 
		null,
		Publisher.EPM,
		pa.toString(),
		1 //job source: manual
		);
1 ACCEPTED SOLUTION

Accepted Solutions

Hi,

 

meanwhile I found the solution. The problem was that I didn't use the exact name for the publishing rule. Actually it is built in a special way. For the following rule in the xml this will be name which you have to give to the action: 

<publish on="create-representation" output="PDF" display-label="PDF" param-set="PDF"/>
PublisherAction pa = new PublisherAction("pubrulename", "PDF using PDF");

The first PDF is the output type, then (depending on the selected locale) using and afterwards the param-set.

You can find out what rules are available for your EPMDocument using the following API:

Publisher pub = new Publisher();
String[] rules = pub.getPublishRuleList(objRef, null, Locale.ENGLISH);

Hope this will help out someone,

BR,

Tamás

View solution in original post

4 REPLIES 4

Hi,

 

meanwhile I found the solution. The problem was that I didn't use the exact name for the publishing rule. Actually it is built in a special way. For the following rule in the xml this will be name which you have to give to the action: 

<publish on="create-representation" output="PDF" display-label="PDF" param-set="PDF"/>
PublisherAction pa = new PublisherAction("pubrulename", "PDF using PDF");

The first PDF is the output type, then (depending on the selected locale) using and afterwards the param-set.

You can find out what rules are available for your EPMDocument using the following API:

Publisher pub = new Publisher();
String[] rules = pub.getPublishRuleList(objRef, null, Locale.ENGLISH);

Hope this will help out someone,

BR,

Tamás

Hi,

 

I'm trying to do the same thing, but I want to create STEP files. I can't figure out, what i'm doing wrong.

 

This is the java code:

String objRef = ObjectReference.newObjectReference(epmDoc).toString();
Publisher pub = new Publisher();
ReferenceFactory ref = new ReferenceFactory();
PublisherAction pa = new PublisherAction("pubrulename", "STP using STEP");
pub.doPublish(false,true, objRef,(ConfigSpec)null,(ConfigSpec)null,true,"test",null,Publisher.EPM,pa.toString(),1);

This is the publish rule:

<rules xmlns="http://www.ptc.com"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.ptc.com PublishRulesSchema.xsd"
	   evaluate-rules-on-republish="true">

    <authoring-application name="COCRMOD">
	<publish on="create-representation" output="STP" param-set="STEP"/>
		
	<param-set name="STEP">
            <post-publish name="delegate">com.ptc.wvs.server.publish.AdditionalFilesPostPublishDelegate</post-publish>
            <post-publish name="name">Additional_File_For_{AUTHORING_APP}_{EPM_NUMBER}_{ADDITIONAL_FILE_PRIMARY_BASENAME}_{ADDITIONAL_FILE_PRIMARY_EXTENSION}</post-publish>
            <post-publish name="published-content-link">stp</post-publish>
            <post-publish name="additional-file-primary" delete-original="true">.*\.stp</post-publish>
        </param-set>

    </authoring-application>
</rules>

It doesn't work to create the additional STEP file with the api java code.

Can you TamasBiro or someone else help me with this?

 

Thanks in adance

 

 

 

Hi,

 

I would first suggest, that you try to add additional jobsources to your publish rule, like this: 

 

<publish on="unknown-source" output="STP" param-set="STEP"/>

and set the last attribute of the doPublish function to 0.

 

Try to do also manual publishing from the UI and see if it works like that first. If it does, then your publish rules xml is ok. 

 My code looks something like this:

String pubRuleName = WVSUtil.getPublishRuleName(commandBean.getElementOid().getReferenceString(), "STEP");

PublisherAction pa = new PublisherAction("pubrulename", pubRuleName);
ReferenceFactory ref = new ReferenceFactory();
pub.doPublish(false, //viewable link
				true, //force republish
				ref.getReferenceString((Persistable) commandBean.getElementOid().getRefObject()),
				(NavigationCriteria)null,
				(NavigationCriteria)null,
				false, //default representation
				"custom description", 
				null,
				Publisher.EPM,
				pa.toString(),
				1 //job source: manual
				);

where that WVSUtil contains this:

public static String getPublishRuleName(String objRef, String paramSetName) {
		
		Publisher pub = new Publisher();
		String[] rules = pub.getPublishRuleList(objRef, null, Locale.ENGLISH);
		for (String rule : rules)
		{
			if(rule.contains("using " +  paramSetName)) {
				return rule;
			}
		}
		return rules[0];
	}

Hope this helps,

BR,

Tamás

Hello TamasBiro,

 my name is Fontana Giorgio, i've tried your solution but for me doesn't work.

My problem is that i have to publish an IGES as additional files using API.

This is the action that i have passed to doPublish method

PublisherAction pa = new PublisherAction("pubrulename","iges using Creo"); where Creo is the result of the getPublishRuleList function.

 

Note that when the IGES was not defined as additional files all worked right.

Attached my publish rule ..

Thanks in advance

 

 

Top Tags