<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Cancel New Sketch event VB.NET in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/cancel-new-sketch-event-vb-net/m-p/6685517#M67873</link>
    <description>&lt;P&gt;hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/68582"&gt;@wayne.brill﻿&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Actually, right now,&amp;nbsp;I already&amp;nbsp;do this as a workaround, but that way you still leave the door open for later editing without the notification. an undoable CTRL+Z would solve my problem, but then inventor crashes...&lt;/P&gt;</description>
    <pubDate>Mon, 14 Nov 2016 07:10:32 GMT</pubDate>
    <dc:creator>frederic.vandenplas</dc:creator>
    <dc:date>2016-11-14T07:10:32Z</dc:date>
    <item>
      <title>Cancel New Sketch event VB.NET</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/cancel-new-sketch-event-vb-net/m-p/6674054#M67779</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In a certain condition, if a user creates a new sketch, i want to intercept that command, and abort if the conditions are met.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I already tried to undo or delete the last sketch, but Inventor crashes (problaby bad coding &lt;img class="lia-deferred-image lia-image-emoji" src="https://forums.autodesk.com/html/@6F93DBFC7E4AAABB1178AEAE8B835CA8/emoticons/1f61b.png" alt=":face_with_tongue:" title=":face_with_tongue:" /&gt; )&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And in the documentation, i found this...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SketchEvents.OnNewSketch Event&lt;/P&gt;
&lt;TABLE class="list"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="list"&gt;HandlingCode&lt;/TD&gt;
&lt;TD class="list"&gt;Output HandlingCodeEnum that indicates how you are handling the event. The value of this argument is currently ignored for this event&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;'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&lt;/PRE&gt;
&lt;PRE&gt;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&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Nov 2016 12:23:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/cancel-new-sketch-event-vb-net/m-p/6674054#M67779</guid>
      <dc:creator>frederic.vandenplas</dc:creator>
      <dc:date>2016-11-08T12:23:34Z</dc:date>
    </item>
    <item>
      <title>Re: Cancel New Sketch event VB.NET</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/cancel-new-sketch-event-vb-net/m-p/6681334#M67844</link>
      <description>&lt;P&gt;Hi Frederic,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I believe that deleting the sketch from the sketch OnNewSketch event is problematic. I am able to recreate the crash. I also tried using a Document Changed event to delete the sketch and Inventor crashes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How important is it that the sketch is not created until the requirement is meant?&amp;nbsp;Would just&amp;nbsp;calling ExitEdit on the sketch in the OnNewSketch event be enough?&amp;nbsp;You could display the message box telling them to add the side definition and then&amp;nbsp;call ExitEdit. They would need to click on the sketch that was created&amp;nbsp;to edit it. (hopefully after doing what they are supposed to).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the VBA code I used to test ExitEdit.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Private Sub SketchEvents_OnNewSketch(ByVal DocumentObject As Document, ByVal Sketch As Sketch, ByVal BeforeOrAfter As EventTimingEnum, ByVal Context As NameValueMap, HandlingCode As HandlingCodeEnum)

    
    
  If BeforeOrAfter = EventTimingEnum.kAfter Then

     Dim oDocDef As SheetMetalComponentDefinition
     Set oDocDef = DocumentObject.ComponentDefinition

     If oDocDef.ASideDefinitions.count = 0 Then
           ' If DocumentObject.EnvironmentManager.EditObjectEnvironment.DisplayName = "Flat Pattern" Then
            If DocumentObject.EnvironmentManager.EditObjectEnvironment.DisplayName = "2D Sketch" Then
                'Call MsgBox("You must create an A Side Definition First", "Missing A Side Definition", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                Call MsgBox("in OnNewSketch in kAfter - closing sketch, please edit the sketch after you do something")
                Sketch.ExitEdit
            End If
     End If
         
  End If
End Sub&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Wayne&lt;/P&gt;</description>
      <pubDate>Fri, 11 Nov 2016 00:33:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/cancel-new-sketch-event-vb-net/m-p/6681334#M67844</guid>
      <dc:creator>wayne.brill</dc:creator>
      <dc:date>2016-11-11T00:33:10Z</dc:date>
    </item>
    <item>
      <title>Re: Cancel New Sketch event VB.NET</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/cancel-new-sketch-event-vb-net/m-p/6685517#M67873</link>
      <description>&lt;P&gt;hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/68582"&gt;@wayne.brill﻿&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Actually, right now,&amp;nbsp;I already&amp;nbsp;do this as a workaround, but that way you still leave the door open for later editing without the notification. an undoable CTRL+Z would solve my problem, but then inventor crashes...&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2016 07:10:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/cancel-new-sketch-event-vb-net/m-p/6685517#M67873</guid>
      <dc:creator>frederic.vandenplas</dc:creator>
      <dc:date>2016-11-14T07:10:32Z</dc:date>
    </item>
    <item>
      <title>Re: Cancel New Sketch event VB.NET</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/cancel-new-sketch-event-vb-net/m-p/6687217#M67919</link>
      <description>&lt;P&gt;Hi Frederic,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am not finding anyway to delete that sketch without crashing Inventor.&lt;/P&gt;
&lt;P&gt;Please post a request for this on the Inventor Idea station:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/inventor-ideastation/idb-p/v1232/tab/most-recent" target="_blank"&gt;http://forums.autodesk.com/t5/inventor-ideastation/idb-p/v1232/tab/most-recent&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could add the Sketch.ExitEdit to the OnSketchChange. This should get the message across to the user. Each time they add a sketch entity they would need start editing the sketch again. You could have a global flag and keep track of how many times the user does this. After three or so tell them that they are going to crash Inventor if they edit the sketch again and that they better save if they intend to do&amp;nbsp;it. If they do edit the sketch again delete the sketch and crash Inventor.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is strange to me that users would be so insistent on not following company policies about model creation. The API is not really intended to stop users from doing things in the UI.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Wayne&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2016 22:51:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/cancel-new-sketch-event-vb-net/m-p/6687217#M67919</guid>
      <dc:creator>wayne.brill</dc:creator>
      <dc:date>2016-11-14T22:51:57Z</dc:date>
    </item>
  </channel>
</rss>

