Cancel New Sketch event VB.NET
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
In a certain condition, if a user creates a new sketch, i want to intercept that command, and abort if the conditions are met.
I'm now at the point where i can intercept the NewSketchEvent, but how do i cancel the event so no new sketch is created?
I already tried to undo or delete the last sketch, but Inventor crashes (problaby bad coding
)
And in the documentation, i found this...
SketchEvents.OnNewSketch Event
| HandlingCode | Output HandlingCodeEnum that indicates how you are handling the event. The value of this argument is currently ignored for this event |
This is what i have now, i know that i'm pretty close but i have never worked with events, and there is not much information available
'Declare the sketchevents variable
Private WithEvents SketchEvents As SketchEvents
'Add the handler for the event
SketchEvents = InvApp.SketchEvents
AddHandler SketchEvents.OnNewSketch, AddressOf Me.SketchEvents.OnNewSketch
'Intercepting the event
Private Sub SketchEvents_OnNewSketch(oDoc As _Document, Sketch As Sketch, BeforeOrAfter As EventTimingEnum, Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum) Handles SketchEvents.OnNewSketch
If BeforeOrAfter = EventTimingEnum.kBefore Then
Dim oDocDef As SheetMetalComponentDefinition = oDoc.ComponentDefinition
If oDocDef.ASideDefinitions.Count = 0 Then
If oDoc.EnvironmentManager.EditObjectEnvironment.DisplayName = "Flat Pattern" Then
MessageBox.Show("You must create an A Side Definition First", "Missing A Side Definition", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
End If
End If
End Sub
Private m_oClosingDoc As Object Private Sub oAppEvents_OnClose(ByVal DocumentObject As Document, ..., ByVal BeforeOrAfter As EventTimingEnum, ...) If BeforeOrAfter = kBefore Then ' Check to see if the Document being closed is an interesting one. If Interesting(DocumentObject) Then ' Save a reference to the object. Set m_oClosingDoc = DocumentObject End If Else ' Now we're either after the close or it's been aborted. Check to see if the document is the interesting one. If DocumentObject Is m_oClosingDoc Then If BeforeOrAfter = kAfter then ' The document was closed. ElseIf BeforeOrAfter = kAbort Then ' The close was aborted. End If End If End Sub
If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
please feel free to "kudos"