Trigger a ílogic rule right after change a sheet size

Trigger a ílogic rule right after change a sheet size

helder.farinha
Explorer Explorer
747 Views
8 Replies
Message 1 of 9

Trigger a ílogic rule right after change a sheet size

helder.farinha
Explorer
Explorer

I have the following simple rule to "grab" a specific border when selecting a sheet size, A3, A2 or A1:

 

trigger = iTrigger0
 
 If ActiveSheet.Size = "A3" Then
ActiveSheet.Border = "BorderA3"
End If

If
ActiveSheet.Size = "A2" Then ActiveSheet.Border = "BorderA2" End If If ActiveSheet.Size = "A1" Then ActiveSheet.Border = "BorderA1" End If

 I want to run the rule after I select the sheet size at the window, and click OK? Is there a way to make the Trigger associated to this operation?

helderfarinha_0-1715354965004.png

 

I would like to thank in advance for the extensive help I've already got using this forum.

Regards,

Helder Farinha

0 Likes
748 Views
8 Replies
Replies (8)
Message 2 of 9

A.Acheson
Mentor
Mentor

Hi @helder.farinha 

 

Unfortuantely there isn't any built in event trigger to know the sheet size has been changed. So you will need to automate your manual actions of sheet size change and border change etc in a rule.

 

The best way to achieve this is to build a global form with a multi value text parameter of the sheet size. In the form place a button to start the rule and change the sheet size and border etc. Generally I would use the same form to fill in iproperties, hold other drawing related rules. It becomes a utility form as your helper rules grow. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 9

WCrihfield
Mentor
Mentor

Hi @helder.farinha.  I agree with @A.Acheson that this very specific action does not appear to have any specific 'event' associated with it that we can monitor for in an accurate way.  The closest event I was able to monitor happening when I resize a sheet manually is using the DocumentEvents.OnChange event handler.  But that event is fired for tons of different types of things that can 'change' a document, not just when resizing a sheet.  And even when trying to filter further to just this one type of change when this event happens, all we get is a context phrase like "Edit Sheet Properties" or "ChangeSheetProperties".  Not anything like "sheet size just changed from A to B" or anything useful like that.  A sheet has multiple properties (such as initial view scale, name, number, revision, & size), and this does not tell us which property of the sheet was changed.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 9

Frederick_Law
Mentor
Mentor

From Event Watcher:

UserInputEvents.OnActivateCommand
     CommandName: "DrawingEditSheetCtxCmd"
     Context: No context information
DocumentEvents.OnChange
     ReasonsForChange: kShapeEditCmdType
     Context:
          DisplayName = "Edit Sheet Properties"
          InternalName = "ChangeSheetProperties"
          ConsideredDirty = 1
     BeforeOrAfter: kBefore
     HandlingCode: kEventNotHandled

 

You can  catch the command: "DrawingEditSheetCtxCmd" and then check Sheet Size and border.

If border is wrong, change it.

 

What's the different between different sheet size?

I use same border for all sheet size.

 

Message 5 of 9

WCrihfield
Mentor
Mentor

Unfortunately that one would not be very accurate though, as mentioned in my last response above.  There are several different actions that can cause the same exact event and context feedback, without changing sheet size.  We can change any of the things shown within that 'Edit Sheet' dialog to get the same result.  For example:

  • Change sheet name
  • Change sheet revision
  • Change sheet orientation
  • Change corner of sheet for title block
  • Change 'Exclude from count'
  • Change 'Exclude from printing'
  • and so on.

Although, I guess it would not hurt anything to check the size of the active sheet during its 'kBefore' timing status, then again during its 'kAfter' timing status, then check if the sizes are different, and if so, run the routine for changing border out according to the size obtained from the 'kAfter' timing status.  Those types of events likely do not happen that often, so it should not slow Inventor down if we had that 'filter' included.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 9

helder.farinha
Explorer
Explorer

Thank you so much for your help. 

I've been using your inputs, and changed my aproach.

This effort comes for the fact that each sheet size has its own border.

Given I cannot tirgger the rule simply by changing sheet size, not even associating a new parameter to the sheet size, I've created a Form, and changed my Rule, based on another discussion I've found on this forum.

 

Sub Main
	If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
		MsgBox("A Drawing Document must be active for this rule to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
		Exit Sub
	End If
	Dim oDDoc As DrawingDocument = ThisApplication.ActiveDocument
	Dim oTBDefs As TitleBlockDefinitions = oDDoc.TitleBlockDefinitions

	Dim oSheetSizesList As New List(Of String)
	oSheetSizesList.AddRange({"A1", "A2", "A3", "A4" })
	Dim oChoice As String = InputListBox("Choose Sheet Size.", oSheetSizesList)
	MsgBox("You chose " & oChoice, , "")

	Dim oChangedSheetSize As Boolean = False
	
	For Each oSheet As Inventor.Sheet In oDDoc.Sheets
		'run the Function defined below to update sheet sizes & title blocks
		oChangedSheetSize = UpdateSheet(oSheet, oChoice, oTBDefs)
		If oChangedSheetSize Then
		End If
	Next

'	Call ChangeStdStyle(oDDoc, oChoice)
'	Call UpdateStylesOfExisting(oDDoc, oChoice)
End Sub

Function UpdateSheet(oSht As Inventor.Sheet, oSize As String, oTBDs As TitleBlockDefinitions) As Boolean
	Dim oTargetSheetSize As DrawingSheetSizeEnum
	

	
	Select Case oSize
		Case "A1"
			oTargetSheetSize = DrawingSheetSizeEnum.kA1DrawingSheetSize
			ActiveSheet.Border = "A1"
		Case "A2"
			oTargetSheetSize = DrawingSheetSizeEnum.kA2DrawingSheetSize
			ActiveSheet.Border = "A2"
		Case "A3"
			oTargetSheetSize = DrawingSheetSizeEnum.kA3DrawingSheetSize
			ActiveSheet.Border = "A3"
		Case "A4"
			oTargetSheetSize = DrawingSheetSizeEnum.kA4DrawingSheetSize
			ActiveSheet.Border = "A4"
	End Select
	Dim oChangedSheetSize As Boolean = False
	If oSht.Size <> oTargetSheetSize Then
		oSht.Size = oTargetSheetSize
		oChangedSheetSize = True
	End If
	
	'now deal with changing the title block
	Dim oTBDef As TitleBlockDefinition
	Dim oTBDefName As String = "FAURECIA"
	Try
		oTBDef = oTBDs.Item(oTBDefName)
	Catch
		MsgBox("Couldn't find a Title Block Definition named '" & oTBDefName & "'.", , "")
		Return False
		Exit Function
	End Try
	If Not oSht.TitleBlock Is Nothing Then
		oSht.TitleBlock.Delete
	End If
	oSht.AddTitleBlock(oTBDef)
	UpdateSheet = oChangedSheetSize
	
	'Atualizar o parametro do tamanho da folha
	Dim TamanhoFolha As String 
TamanhoFolha = ActiveSheet.Size

iProperties.Value("Custom", "TamanhoFolhaPROP") = ActiveSheet.Size
	
End Function





Is there a way to automatically close the form right after I selected the sheet size and clicked ok, or right after I load this above window?

helderfarinha_0-1716482413607.png

 

 

Thank you again.

0 Likes
Message 7 of 9

WCrihfield
Mentor
Mentor

Hi @helder.farinha.  Are you saying that you created a regular iLogic Form that you are using, and that is different from the InputListBox dialog you attached the image of above?  ...and that iLogic Form is still open when you run the rule above, which then shows that InputListBox?  If so, then possibly yes.  In one of the latest releases of Inventor, we now have the ability to close one or more iLogic Forms that are currently open.  However, it can be tricky, depending what mode (Modal or not Modal) the Form was launched in.  If it was launched by an iLogic rule, as Modal, then that iLogic rule that launched it will remain 'paused' until that Form is closed due to some other action, then once that Form is closed, the rest of that iLogic rule will resume.  However, if it was launched by some other rule, or it is not modal, then we can potentially close it by code.

iLogicForm 

iLogicForm.Close() 

iLogicForm.CloseGlobal() 

iLogicForm.CloseAllForms() 

 

By the way, be careful with how you use that 'ActiveSheet' iLogic object (an IManagedSheet Interface).  You are passing the actual Inventor.Sheet Inventor API object from the 'Main' routine, to the other routine, but then you are not using that regular Sheet object for setting the border, or for reporting sheet size back, but you are using it for the TitleBlock.  Since you are not using Sheet.Activate within your 'Main' routine, as you are iterating through them, only the originally active sheet will still be the 'active' sheet.  So, that iLogic object named 'ActiveSheet' may be accessing that originally active sheet each time, instead of the Sheet object that you passed into that other routine.  You could be using the Sheet.Border property, check if it is Nothing, if not Nothing, Delete it, then use Sheet.AddBorder() method, instead of that ActiveSheet.Border property.  And you could be using the Sheet.Size.ToString or Sheet.Height & Sheet.Width properties to report sheet size.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 8 of 9

helder.farinha
Explorer
Explorer

I would like to thank you all for your help. 

I've got to this solution to one that might be interested:

 

I wanted to change sheet size, and automatically load it's respective Border. Each sheet size has it's own border. Same Title Block for all sheet sizes.

helderfarinha_0-1720522453764.png

 

1. I've Customized the iTrigger button to the Main TAB

helderfarinha_1-1720522521431.png

2. Added a Rule that allowed me to: select sheet size, load related Border, define orientation portrait or Landscape:

Sub Main
	If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
		MsgBox("A Drawing Document must be active for this rule to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
		Exit Sub
	End If
	Dim oDDoc As DrawingDocument = ThisApplication.ActiveDocument
	Dim oTBDefs As TitleBlockDefinitions = oDDoc.TitleBlockDefinitions

	Dim oSheetSizesList As New List(Of String)
	oSheetSizesList.AddRange({"A0","A1", "A2", "A3"})
	Dim oChoice As String = InputListBox("Choose Sheet Size.", oSheetSizesList)
	
	                       
	Dim oChangedSheetSize As Boolean = False
	
	For Each oSheet As Inventor.Sheet In oDDoc.Sheets
		            'run the Function defined below to update sheet sizes & title blocks
		oChangedSheetSize = UpdateSheet(oSheet, oChoice, oTBDefs)
		If oChangedSheetSize Then
		End If
	Next

End Sub

Function UpdateSheet(oSht As Inventor.Sheet, oSize As String, oTBDs As TitleBlockDefinitions) As Boolean
	Dim oTargetSheetSize As DrawingSheetSizeEnum
	

	
	Select Case oSize
		Case "A0"
			oTargetSheetSize = DrawingSheetSizeEnum.kA0DrawingSheetSize
			ActiveSheet.Border = "A0"
			ThisApplication.ActiveDocument.ActiveSheet.Orientation = kLandscapePageOrientation
		Case "A1"
			oTargetSheetSize = DrawingSheetSizeEnum.kA1DrawingSheetSize
			ActiveSheet.Border = "A1"
			ThisApplication.ActiveDocument.ActiveSheet.Orientation = kLandscapePageOrientation
		Case "A2"
			oTargetSheetSize = DrawingSheetSizeEnum.kA2DrawingSheetSize
			ActiveSheet.Border = "A2"
			ThisApplication.ActiveDocument.ActiveSheet.Orientation = kLandscapePageOrientation
		Case "A3"
			oTargetSheetSize = DrawingSheetSizeEnum.kA3DrawingSheetSize
			ActiveSheet.Border = "A3"
			ThisApplication.ActiveDocument.ActiveSheet.Orientation = kLandscapePageOrientation
		'Case "A4"
			'oTargetSheetSize = DrawingSheetSizeEnum.kA4DrawingSheetSize
			'ActiveSheet.Border = "A4"
	End Select
	Dim oChangedSheetSize As Boolean = False
	If oSht.Size <> oTargetSheetSize Then
		oSht.Size = oTargetSheetSize
		oChangedSheetSize = True
	End If
	trigger = iTrigger0

1st click Trigger

2nd select size on window

3rd ok

 

 

 

Thank you all again.

Best regards,

Helder

0 Likes
Message 9 of 9

Frederick_Law
Mentor
Mentor

You could setup "Sheet Format".

I use a simple border without zone which change with sheet size.

0 Likes