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

Windchill Listener Rename only on first checkin

davidegp
6-Contributor

Windchill Listener Rename only on first checkin

Hi All,

 

I have written a windchill listener that waits for EPMWorkspaceManagerEvent.PRE_WORKSPACE_CHECKIN events, and then changes the names of epm documents, and parts in certain ways depending on some IBA.

 

It works fine, a part from the fact that I am unable to distinguish between the first checkin, when the autonumber is substituted with the proper computed-by-the-listener name, and all the following checkins.

 

For example, I checkin the part 295.prt, and it gets renamed to NEWNAME-142-DONE.prt; then, I modify it, and check it in again, but instead of becoming A.2, it becomes NEWNAME-143-DONE.prt, version A.1. This does not happen to the WTPart, which is renamed as well initially, but then keeps the same name and only increases the iteration.

 

Is there any attribute of the EPMDocument that I can check? Any API that could help me?

 

(I may check the format of the name to verify if it has been already renamed, but I would prefer to use something else, beacuse it may be the case that parts with a different format exist and they should keep the different name).

 

Thank you in advance.

 

Regards

 

Davide

1 ACCEPTED SOLUTION

Accepted Solutions
davidegp
6-Contributor
(To:davidegp)

I have found a solution that I publish here, just in case someone else may need it,

 

for prt and asm,

 

 public boolean understandModifications() throws WTException {
        if (WorkInProgressHelper.service.isPreCheckedInObject(this.associated)) {
            return true;
        } else {
            return false;
        }
    }

isPreCheckedInObject returns true only the first time that a prt or assembly is checked in in Windchill.

 

However, this does not work for drawings. So, I used a workaround,

public boolean understandModifications() {
        // the drawingReference is the document master of the drawing
        EPMDocumentMaster activePart = this.drawingReference;
        // the getRelatedSinglePart method failed!
        if (activePart == null) {
            System.out.println("getDrawingReference failed.");
            return false;
        }
        // if the drawing has already been renamed, skip it!
        String subNumberPart = activePart.getNumber().substring(0, activePart.getNumber().indexOf("."));
        String subNumberDrw = doc.getNumber().substring(0, doc.getNumber().indexOf("."));
        if (subNumberDrw.equalsIgnoreCase(subNumberPart)) {
            return false;
        } else {
            return true;
        }
    }

Here, I confront the name of the drawing with the one of the document master associated with it. If they are the same, it means that I have already renamed them in a previous checkin, so this is not the first one. Otherwise, this is the first one.

View solution in original post

3 REPLIES 3
davidegp
6-Contributor
(To:davidegp)

I have found a solution that I publish here, just in case someone else may need it,

 

for prt and asm,

 

 public boolean understandModifications() throws WTException {
        if (WorkInProgressHelper.service.isPreCheckedInObject(this.associated)) {
            return true;
        } else {
            return false;
        }
    }

isPreCheckedInObject returns true only the first time that a prt or assembly is checked in in Windchill.

 

However, this does not work for drawings. So, I used a workaround,

public boolean understandModifications() {
        // the drawingReference is the document master of the drawing
        EPMDocumentMaster activePart = this.drawingReference;
        // the getRelatedSinglePart method failed!
        if (activePart == null) {
            System.out.println("getDrawingReference failed.");
            return false;
        }
        // if the drawing has already been renamed, skip it!
        String subNumberPart = activePart.getNumber().substring(0, activePart.getNumber().indexOf("."));
        String subNumberDrw = doc.getNumber().substring(0, doc.getNumber().indexOf("."));
        if (subNumberDrw.equalsIgnoreCase(subNumberPart)) {
            return false;
        } else {
            return true;
        }
    }

Here, I confront the name of the drawing with the one of the document master associated with it. If they are the same, it means that I have already renamed them in a previous checkin, so this is not the first one. Otherwise, this is the first one.

dharlan-2
4-Participant
(To:davidegp)

Thanks for posting the solution. By why not just check to see if the version is A.1 or not?

davidegp
6-Contributor
(To:dharlan-2)

Unfortunately, as I wrote above, the part or assembly was renamed each time, and it got A1 as version! I could have checked the WTPart that was never renamed twice, and got the A2, but it would have meant do something at every checkin.

 

With the code above, I am able to just check if it is the first checkin; if not, I just skip all the operations. 

Announcements