Previous Topic

Next Topic

Inhoudsopgave

Book Index

Modifying Parts and Part Revisions

Description

The Engineering Link API supports several Isah items, including parts. It is possible to build an entire part structure with a number of interfaces (Part, Partrevisions, Partrevision, Part Bill of Material, Part Bom line).

Before you can use the part functionality of the Engineering Link, you have to create a part object. In order to read all the underlying components of the part, you have to use the Refresh method.

Reading all Part Components with the Refresh Method

If you have created a part object, no properties in the object have been filled in yet. By filling in the PartCode and using the Refresh mehod as well, all object properties will be filled in from the database. In addition, all revsions and its bills of materials will be read. This may affect the performance. An alternative way, is to read just one particular part revision by creating an IPDMLink.PartRevision object, which will take less time.

Note: If the entered part does not exist, an error will occur. You have to account for this in the code, for example by using a try/catch statement.

The following code reads all the underlying components of a part:

oPart = New IPDMLink.Part

oPart.PartCode = “0”

Try

oPart.Refresh

Catch ex As Exception

Msgbox(ex.Message)

Exit Sub

End Try

MsgBox "Part: " & oPart.PartCode & ", " & oPart.Description

Adding a Part

All you have to do to add a part is filling in a number of required fields and running the Insert method. If a part already exists or if other (database) exceptions arise, an error may occur. That error should be addressed. Either you track down the exception with a try/catch statement and solve the problem in the application or you display a message to the user.

If you use a part code in Isah that numbers parts automatically, you do not have to enter a part code. The default Isah part code will be used instead. However, the Isah script for customizing part codes cannot be used.

The following code adds a part. It contains a try/catch statement.

oPart.PartCode = "NEWPART"

oPart.Description = "New part"

oPart.PartMnem = "NEW"

oPart.PartGrpCode = "DIV"

Try

oPart.Insert()

Catch ex As Exception

Exit Sub

End Try

Changing Part Data

It is imperative that you refresh part data before changing them. This way, you will always work with the most recent data. You can choose to check whether the part is valid before you run the Update method. A part is valid if it is present in the database and in addition, reading the properties was succesfull.

The following code changes the part after refreshing the part data and checking the part validity:

oPart.PartCode = "NEWPART"

Try

oPart.Refresh()

Catch ex As Exception

Msgbox(“Part ‘NEWPART’ does not exist!”)

Exit Sub

End Try

oPart.Description = "Changed part"

If oPart.IsValid Then

oPart.Update()

End If

Deleting a Part

You have to run the Refresh method before deleting the part, because the LastUpdatedOn value has to be added to the stored procedure that deletes it. If you have run the Delete method, the part is removed from the database but the object still remains.

The following code deletes a part:

oPart.PartCode = "NEWPART"

Try

oPart.Refresh()

Catch ex As Exception

Msgbox(“Part ‘NEWPART’ does not exist!”)

Exit Sub

End Try

oPart.Delete()

Showing the Parts Form

The ShowForm method allows you to show the Parts form (F0040) with the part concerned selected. All form functionality the user has the rights to is available.

The following code shows the Part form:

oPart.PartCode = "NEWPART"

Try

oPart.Refresh()

Catch ex As Exception

Msgbox(“Part ‘NEWPART’ does not exist!”)

End Try

If oPart.IsValid Then

oPart.ShowForm()

End If

Creating a Part Revision

There are several ways to create a part revision: via a part object (Revisions property) and directly based on the PrimKey. If you create the part revision object directly, only a limited number of data will be read from the database, namely revision data and the bill of materials of the revision.

The following code creates a part revision directly:

oPartRev = New IPDMLink.PartRevision

oPartRev.PrimKey = “1000.001.000000|061”

Try

oPartRev.Refresh()

Catch ex As Exception

MsgBox “Partrevision does not exist!”

End Try

The following code creates a part revision via the part object:

oPart.PartCode = "0"

Try

oPart.Refresh()

Catch ex As Exception

MsgBox “Part does not exist!”

End Try

If oPart.IsValid Then

lMsg = "This part has " & oPart.Revisions.Count & _

“revisions: " & vbCrLf

For i = 0 To oPart.Revisions.Count – 1

lMsg = lMsg & oPart.Revisions.Item(i).RevisionNr & ", " & _

oPart.Revisions.Item(i).Description & vbCrLf

Next I

MsgBox lMsg

End If

Modifying the Bill of Materials

With the Bom property you can display the bill of materials lines of a part revision. Subsequently, you can add, change or delete lines.

The following code selects the part revision "003" in the list of part revisions using the ActivateRevision method. In addition, the code displays the bill of materials lines.

Dim oBomLine As IPDMLink.IISPDMPartBomLine

oPart = New IPDMLink.Part

oPart.PartCode = "0"

Try

oPart.Refresh()

Catch ex As Exception

MsgBox “Part does not exist!”

End Try

If oPart.IsValid Then

oPart.Revisions.ActivateRevision "003"

lMsg = "Number of lines: " & _

oPart.Revisions.ActiveRevision.Bom.Count & vbCrLf

For i = 0 To oPart.Revisions.ActiveRevision.Bom.Count – 1

oBomLine = oPart.Revisions.ActiveRevision.Bom.Item(i)

lMsg = lMsg & oBomLine.LineNr & ": " & _

oBomLine.SubPartCode & "" & oBomLine.Description & vbCrLf

Next I

MsgBox lMsg

End If