add-in to process part document not working

Esteemed Contributor
Esteemed Contributor

I have an add-in that ran a process on a Draft document before it saved.  I'm now trying to modify it to run a different process on a Part document before save but it doesn't seem to be running the process which makes me thing that it isn't detecting that it is a part document that is open.  I'm using TryCast and am using the following code:

 

Public Sub BeforeDocumentSave(ByVal theDocument As Object) Implements SolidEdgeFramework.ISEApplicationEvents.BeforeDocumentSave

'Dim document = TryCast(theDocument, SolidEdgeFramework.SolidEdgeDocument)

Dim draftDocument = TryCast(theDocument, SolidEdgeDraft.DraftDocument)

Dim partDocument = TryCast(theDocument, SolidEdgePart.PartDocument)

'Process the Draft

If Not draftDocument Is Nothing Then

PellaUtils.UpdateDocumentBeforeSave(draftDocument)

End If

'Process the Part

If Not partDocument Is Nothing Then

PellaUtils.UpdatePartBeforeSave(partDocument)

End If

End Sub

 

Anyone see where I went wrong?


Thanks,
Ken

Production: ST9 MP10
Testing: ST10 MP1
3 REPLIES

Re: add-in to process part document not working

Esteemed Contributor
Esteemed Contributor

I might add that the portion below wasprofessionally coded:

Public Sub BeforeDocumentSave(ByVal theDocument As Object) Implements SolidEdgeFramework.ISEApplicationEvents.BeforeDocumentSave

'Dim document = TryCast(theDocument, SolidEdgeFramework.SolidEdgeDocument)

Dim draftDocument = TryCast(theDocument, SolidEdgeDraft.DraftDocument)

Dim partDocument = TryCast(theDocument, SolidEdgePart.PartDocument)

'Process the Draft

If Not draftDocument Is Nothing Then

PellaUtils.UpdateDocumentBeforeSave(draftDocument)

End If

 

I added the following which does not seem to work:

'Process the Part

If Not partDocument Is Nothing Then

PellaUtils.UpdatePartBeforeSave(partDocument)

End If

 

It calls the following sub:

Public Shared Sub UpdatePartBeforeSave(ByVal partDocument As SolidEdgePart.PartDocument)

Dim objBody As SolidEdgeGeometry.Body

Dim dblMinimum(0 To 2) As Double

Dim dblMaximum(0 To 2) As Double

Dim X As Double

Dim Y As Double

Dim Z As Double

Dim objPropSets As SolidEdgeFramework.PropertySets

Dim objProps As SolidEdgeFramework.Properties

'Dim objProp As SolidEdgeFramework.Property

Const CV = 39.3700787

' getting the body object of the model

objBody = partDocument.Models(0).Body

' getting the range values for the Body object

Call objBody.GetRange(MinRangePoint:=dblMinimum, MaxRangePoint:=dblMaximum)

X = FormatNumber(((dblMaximum(0) - dblMinimum(0)) * CV), 4, TriState.True, TriState.True, TriState.UseDefault)

Y = FormatNumber(((dblMaximum(1) - dblMinimum(1)) * CV), 4, TriState.True, TriState.True, TriState.UseDefault)

Z = FormatNumber(((dblMaximum(2) - dblMinimum(2)) * CV), 4, TriState.True, TriState.True, TriState.UseDefault)

MsgBox(X & " x " & Y & " x " & Z)

objPropSets = partDocument.Properties

objProps = objPropSets.Item("Custom")

objProps.Add("X", X)

objProps.Add("Y", Y)

objProps.Add("Z", Z)

' Release objects

objBody = Nothing

End Sub

 


Thanks,
Ken

Production: ST9 MP10
Testing: ST10 MP1

Re: add-in to process part document not working

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

Are you able to debug the addin code? Doing so should quickly iron out what's going wrong. I can help over Skype but it would have to be in the evening.

Jason Newell
Applications Architect
www.jasonnewell.net

Re: add-in to process part document not working

Esteemed Contributor
Esteemed Contributor

Not sure how to debug an add-in.  The code works as a macro but doesn't use an Event to fire (on demand).  The add-in is loading for the part environment but it's like it is not picking up the Save event in part.


Thanks,
Ken

Production: ST9 MP10
Testing: ST10 MP1