Skip to main content
1-Visitor
February 13, 2014
Solved

How to Create a Baseline Programmatically

  • February 13, 2014
  • 2 replies
  • 4702 views

Hi,

I am looking to create a Managed Baseline programmatically.

We currently create an ECN programmatically, set it up using a few additional lines and persist it using the following:

cn = (WTChangeOrder2)ChangeHelper2.service.saveChangeOrder(cn);

Is there an equivalent for a Managed Baseline?

We are currently running 9.1 M060 but will be upgrading to 10.1 M0XX in a couple months. Whether it works in 9.1 does not matter.

Regards,

Toby

Best answer by SimonHeath

Try this, you can also use code to set the folder, soft type etc.

ManagedBaseline myManagedBaseline = ManagedBaseline.newManagedBaseline();

myManagedBaseline.setName(name);

myManagedBaseline = (ManagedBaseline) PersistenceHelper.manager.save(myManagedBaseline);

BR

Simon

2 replies

1-Visitor
February 13, 2014

Try this, you can also use code to set the folder, soft type etc.

ManagedBaseline myManagedBaseline = ManagedBaseline.newManagedBaseline();

myManagedBaseline.setName(name);

myManagedBaseline = (ManagedBaseline) PersistenceHelper.manager.save(myManagedBaseline);

BR

Simon

1-Visitor
February 13, 2014

Spot on, thanks Simon.

1-Visitor
February 14, 2014

Toby,

Sorry I should have warned you, programming windchill is like pulling at a ball of tangled string, it quickly gets messy if you are not-experienced. Anyway I can give you a little help, I suggest testing code in a little main as follows. If you progress down this path further, think about externalizing and correctly managing code.

1. Put the attached file (below) here

src\net\wincomco\windchill\test

2. Compile it from a Windchill shell

javac -d %WT_HOME%\codebase -classpath %CLASSPATH%;%WT_HOME%\srclib\tool\Annotations.jar W:\ptc\Windchill\src\net\wincomco\windchill\test\CreateBaseline.java

3. Run it

windchill net.wincomco.windchill.test.CreateBaseline MyBaseline

4. It prints the oid of the new baseline e.g. wt.vc.baseline.ManagedBaseline:1094588729

5. Use the URL to find it (note your number will be different)

http://myhost/Windchill/app/#ptc1/tcomp/infoPage?oid=OR:wt.vc.baseline.ManagedBaseline:1094588729

6. It will be created in the Site > Folders, you need to start to learn how to create it where you want and populate it

You can transpose the code to workflows once you have it working

Simon

=====>

package net.wincomco.windchill.test;

import wt.vc.baseline.ManagedBaseline;

public class CreateBaseline {

public static void main(String[] args) throws Exception {
System.out.println("Start....");
String name = args[0];
ManagedBaseline myManagedBaseline = ManagedBaseline.newManagedBaseline();
myManagedBaseline.setName(name);
myManagedBaseline = (ManagedBaseline)wt.fc.PersistenceHelper.manager.save(myManagedBaseline);
System.out.println("===> myManagedBaseline " +myManagedBaseline);
}

}

1-Visitor
February 14, 2014

Hi Simon,

I externalised our code around 2 years ago for several practical reasons. I would recommend that everyone does the same.

I tend to test all my code in a test instance workflow since it is easier and cannot do any real damage. The only nuiance I dont like is that once the code has been used it appears you have to stop the server and clear the cache if you want to make modifications.

Regards,

toby