Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
gert-leonvanlier
387 Views, 4 Replies

Execute method when sheet size is changed in addin C#

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.

Currently using Inventor 2019. Addin in C#.

This is the code that is stuck in a loop:

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;
}

 

What am I doing wrong here? How can I check if the sheet size has changed so I can execute some code?

Labels (1)