<?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: Execute method when sheet size is changed in addin C# in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/execute-method-when-sheet-size-is-changed-in-addin-c/m-p/10822382#M132559</link>
    <description>&lt;P&gt;I tried adding the HandlingCode, but I get two errors on the if statement:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Error CS0269 Use of unassigned out parameter&lt;/LI&gt;&lt;LI&gt;Error CS0177 The out parameter 'HandlingCode' must be assigned to before control leaves the current method&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="csharp"&gt;private void OnChange(_Document DocumentObject, EventTimingEnum BeforeOrAfter, CommandTypesEnum ReasonsForChange, NameValueMap Context, out HandlingCodeEnum HandlingCode)
{
	if (HandlingCode == HandlingCodeEnum.kEventHandled) { return; } //Error happens on this line
	HandlingCode = HandlingCodeEnum.kEventNotHandled;
	
	//DO SOMETHING
	
	HandlingCode = HandlingCodeEnum.kEventNotHandled;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Settings EventNotHandled before the if statement is not a solution I guess. In that case the if statement will always fail.&lt;/P&gt;</description>
    <pubDate>Tue, 14 Dec 2021 14:37:50 GMT</pubDate>
    <dc:creator>gert-leonvanlier</dc:creator>
    <dc:date>2021-12-14T14:37:50Z</dc:date>
    <item>
      <title>Execute method when sheet size is changed in addin C#</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/execute-method-when-sheet-size-is-changed-in-addin-c/m-p/10821768#M132540</link>
      <description>&lt;P&gt;I am trying to figure out how to execute a method in my addin when the sheet size in a drawing is changed. I tried it using the on change event, however that leads to some kind of loop (stack overflow) that I kind get out of.&lt;/P&gt;&lt;P&gt;Currently using Inventor 2019. Addin in C#.&lt;/P&gt;&lt;P&gt;This is the code that is stuck in a loop:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;private void OnChange(_Document DocumentObject, EventTimingEnum BeforeOrAfter, CommandTypesEnum ReasonsForChange, NameValueMap Context, out HandlingCodeEnum HandlingCode)
{
	UserInterfaceManager userInterfaceManager = Globals.invApp.UserInterfaceManager;
	Document document = Globals.invApp.ActiveDocument;
	DocumentTypeEnum documentType = document.DocumentType;
	DrawingDocument drawingDocument;
	Sheet sheet;
	DrawingSheetSizeEnum sheetSizeEnumOld = DrawingSheetSizeEnum.kADrawingSheetSize;

	if (BeforeOrAfter == EventTimingEnum.kBefore)
	{
		switch (documentType)
		{
			case DocumentTypeEnum.kDrawingDocumentObject:
				drawingDocument = (DrawingDocument)document;
				sheet = drawingDocument.ActiveSheet;
				sheetSizeEnumOld = sheet.Size;
				break;
		}
	}

	if (BeforeOrAfter == EventTimingEnum.kAfter)
	{
		if (Properties.Settings.Default.ShowFullyConstraints == true)
		{
			showFullyConstraint.startMarking(DocumentObject, isSaving);
		}

		switch (documentType)
		{
			case DocumentTypeEnum.kDrawingDocumentObject:
				Ribbon drawingRibbon = userInterfaceManager.Ribbons["Drawing"];
				RibbonTab ribbonTab = drawingRibbon.RibbonTabs["tab_dwg"];
				RibbonPanel ribbonPanel = ribbonTab.RibbonPanels["Drawing_panel_dwg"];
				drawingDocument = (DrawingDocument)document;
				sheet = drawingDocument.ActiveSheet;
				DrawingSheetSizeEnum sheetSizeEnum = sheet.Size;

				//This should later be placed in a method
				if (sheetSizeEnumOld != sheetSizeEnum)
				{
					RevisionTable revisionTable = null;

					foreach (Sheet sheetA in drawingDocument.Sheets)
					{
						try { revisionTable = sheetA.RevisionTables[1]; }
						catch { }

						if (revisionTable != null)
						{
							Point2d revPt;
							//Point2d borderPt;
							TransientGeometry transientGeometry;

							//borderPt = sheet.Border.RangeBox.MaxPoint;
							transientGeometry = Globals.invApp.TransientGeometry;
							revPt = transientGeometry.CreatePoint2d(sheetA.Border.RangeBox.MaxPoint.X - 1.085, 1 + (revisionTable.RangeBox.MaxPoint.Y - revisionTable.RangeBox.MinPoint.Y));
							revisionTable.Position = revPt;
						}
						//}
					}
				break;
		}

	}
	HandlingCode = HandlingCodeEnum.kEventNotHandled;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What am I doing wrong here? How can I check if the sheet size has changed so I can execute some code?&lt;/P&gt;</description>
      <pubDate>Tue, 14 Dec 2021 10:02:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/execute-method-when-sheet-size-is-changed-in-addin-c/m-p/10821768#M132540</guid>
      <dc:creator>gert-leonvanlier</dc:creator>
      <dc:date>2021-12-14T10:02:26Z</dc:date>
    </item>
    <item>
      <title>Re: Execute method when sheet size is changed in addin C#</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/execute-method-when-sheet-size-is-changed-in-addin-c/m-p/10822214#M132556</link>
      <description>&lt;P&gt;Use this event is not recommended. But if you have no another choice, you need to be careful in handling of this event.&lt;/P&gt;&lt;P&gt;If you create any document modification, the event is fired again and again. Up to StackOverflowException.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this case i necessary to check if you are currently handling this event. This asample is not complete, but demonstrates how to achieve this.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;private void OnChange (...){
   if(currentlyHandling) return;
   currentlyHandling = true;

   //DO SOMETHING

   currentlyHandling = false;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Dec 2021 13:43:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/execute-method-when-sheet-size-is-changed-in-addin-c/m-p/10822214#M132556</guid>
      <dc:creator>Michael.Navara</dc:creator>
      <dc:date>2021-12-14T13:43:17Z</dc:date>
    </item>
    <item>
      <title>Re: Execute method when sheet size is changed in addin C#</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/execute-method-when-sheet-size-is-changed-in-addin-c/m-p/10822382#M132559</link>
      <description>&lt;P&gt;I tried adding the HandlingCode, but I get two errors on the if statement:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Error CS0269 Use of unassigned out parameter&lt;/LI&gt;&lt;LI&gt;Error CS0177 The out parameter 'HandlingCode' must be assigned to before control leaves the current method&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="csharp"&gt;private void OnChange(_Document DocumentObject, EventTimingEnum BeforeOrAfter, CommandTypesEnum ReasonsForChange, NameValueMap Context, out HandlingCodeEnum HandlingCode)
{
	if (HandlingCode == HandlingCodeEnum.kEventHandled) { return; } //Error happens on this line
	HandlingCode = HandlingCodeEnum.kEventNotHandled;
	
	//DO SOMETHING
	
	HandlingCode = HandlingCodeEnum.kEventNotHandled;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Settings EventNotHandled before the if statement is not a solution I guess. In that case the if statement will always fail.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Dec 2021 14:37:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/execute-method-when-sheet-size-is-changed-in-addin-c/m-p/10822382#M132559</guid>
      <dc:creator>gert-leonvanlier</dc:creator>
      <dc:date>2021-12-14T14:37:50Z</dc:date>
    </item>
    <item>
      <title>Re: Execute method when sheet size is changed in addin C#</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/execute-method-when-sheet-size-is-changed-in-addin-c/m-p/10822552#M132572</link>
      <description>&lt;P&gt;After some trying I found a (workable) solution:&lt;/P&gt;&lt;P&gt;I check which change is being made using NameValueMap Context. In this case it is "ChangeSheetProperties".&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;private void OnChange(_Document DocumentObject, EventTimingEnum BeforeOrAfter, CommandTypesEnum ReasonsForChange, NameValueMap Context, out HandlingCodeEnum HandlingCode)
{
	UserInterfaceManager userInterfaceManager = Globals.invApp.UserInterfaceManager;
	Document document = Globals.invApp.ActiveDocument;
	DocumentTypeEnum documentType = document.DocumentType;
	DrawingDocument drawingDocument;
	Sheet sheet;

	if (BeforeOrAfter == EventTimingEnum.kBefore)
	{
		if (documentType == DocumentTypeEnum.kDrawingDocumentObject &amp;amp;&amp;amp; Context.Item["InternalName"].ToString() == "ChangeSheetProperties")
		{
			drawingDocument = (DrawingDocument)document;
			sheet = drawingDocument.ActiveSheet;
			sheetSizeEnumOld = sheet.Size;
		}
	}

	if (BeforeOrAfter == EventTimingEnum.kAfter)
	{
		switch (documentType)
		{
			case DocumentTypeEnum.kDrawingDocumentObject:
				DrawingSheetSizeEnum sheetSizeEnum = sheet.Size;

				if (sheetSizeEnumOld != sheetSizeEnum &amp;amp;&amp;amp; Context.Item["InternalName"].ToString() == "ChangeSheetProperties")
				{
					//DO SOMETHING
				}
				break;
		}

	}
	HandlingCode = HandlingCodeEnum.kEventNotHandled;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;sheetSizeOld is declared at the constructor (it must have a value, cannot be null):&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;private DrawingSheetSizeEnum sheetSizeEnumOld = DrawingSheetSizeEnum.kADrawingSheetSize;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This solution will fire the OnDocumentChange twice: first the sheet sizes are different and my code is executed. That triggers again the OnDocumentChange event, but this time the sheet sizes are the same, so nothing further happens.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Still, I am interested how this could work using the HandlingCode. If anyone could me give an example (somewhere) on how to use this, would be great.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Dec 2021 15:52:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/execute-method-when-sheet-size-is-changed-in-addin-c/m-p/10822552#M132572</guid>
      <dc:creator>gert-leonvanlier</dc:creator>
      <dc:date>2021-12-14T15:52:13Z</dc:date>
    </item>
    <item>
      <title>Re: Execute method when sheet size is changed in addin C#</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/execute-method-when-sheet-size-is-changed-in-addin-c/m-p/10822870#M132584</link>
      <description>&lt;P&gt;The argument HandlingCode is defined as out. Set its value is required. If you don't want to cancel this change, set its value to kEventNotHandled.&lt;BR /&gt;For more information see the API specification of OnChange event&lt;/P&gt;&lt;P&gt;&lt;A href="https://help.autodesk.com/view/INVNTOR/2020/ENU/?guid=GUID-45C2F0C0-6B5D-413A-9359-9DFD86E3A764" target="_blank"&gt;https://help.autodesk.com/view/INVNTOR/2020/ENU/?guid=GUID-45C2F0C0-6B5D-413A-9359-9DFD86E3A764&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Dec 2021 18:30:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/execute-method-when-sheet-size-is-changed-in-addin-c/m-p/10822870#M132584</guid>
      <dc:creator>Michael.Navara</dc:creator>
      <dc:date>2021-12-14T18:30:54Z</dc:date>
    </item>
  </channel>
</rss>

