Create event trigger for when placing first DrawingView onto new DrawingDocument (iLogic/VB.NET)

Create event trigger for when placing first DrawingView onto new DrawingDocument (iLogic/VB.NET)

WCrihfield
Mentor Mentor
676 Views
1 Reply
Message 1 of 2

Create event trigger for when placing first DrawingView onto new DrawingDocument (iLogic/VB.NET)

WCrihfield
Mentor
Mentor

 

I want to create an event trigger for when I place the first drawing view onto a new drawing.

The new drawing may be started either by manually clicking the New button (AppFileNewCmd), choosing a drawing template, then placing the view (DrawingBaseViewCmd); or by right clicking the top browser node within my model file and choosing "Create Drawing View" (UCxCreateDrawingViewCmd).  I prefer the second option, because it holds the model reference needed for the drawing view.

So the main code can be triggered to run by the "New Document" event of the (all) Drawings tab within the Event Triggers dialog, for simplicity.

When the code runs, I would like it to 'listen for' when I place that first drawing view.  I have a couple other external iLogic rules I would like to run at this point using something like "iLogicVb.RunExternalRule("oRuleName")."

(One of which, copies all custom iProperties from the model to the drawing for use within the title block, notes, and other uses, which needs to access the ThisDrawing.ModelDocument to work.)

I sometimes use the "Event Watcher" standalone, and can only see two events listen within it that deal with Drawings.  The "DrawingEvents.OnRetrieveDimensions" and the "DrawingViewEvents.OnViewUpdate", but neither seem to be the right one.  I have dabbled with using the "TransactionEvents.OnCommit" and UserInputEvents.OnActivateCommand", but I think I may be missing something, and need to see more examples of how they're used.

This is my latest attempt, but it doesn't appear to be working.

 

Class ThisRule
	Sub Main
		Dim oContext As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
		UINewDrawingView_OnActivateCommand("UCxCreateDrawingViewCmd",oContext)
	End Sub

	Private WithEvents oUINewDrawingView As UserInputEvents

	Public Sub Activate(ByVal addInSiteObject123 As Inventor.ApplicationAddInSite, ByVal firstTime As Boolean) 'Implements Inventor.ApplicationAddInServer.Activate
		oUINewDrawingView = ThisApplication.ApplicationEvents
	End Sub

	Private Sub UINewDrawingView_OnActivateCommand(CommandName As String, Context As Inventor.NameValueMap) Handles oUINewDrawingView.OnActivateCommand
		If CommandName = "UCxCreateDrawingViewCmd" Then
		'If CommandName = "DrawingBaseViewCmd" Then
			iLogicVb.RunExternalRule("Copy All Custom iProperties from Model to Drawing")
		End If
	End Sub
End Class

 

I would ideally like to accomplish this using iLogic/VB.NET, but would also accept VBA, but I don't have the Admin rights to work with Addins at this time.

Any help would be greatly appreciated.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
677 Views
1 Reply
Reply (1)
Message 2 of 2

WCrihfield
Mentor
Mentor

Here is another failed attempt I made using someone's OnParameterChange EventHandler code, then tried to customize it to fit my needs, but I didn't really define most of the variables, because I wasn't sure what they needed to be set to.

Option Explicit On

Imports System.Runtime.InteropServices
Imports System.Text
'Class ThisRule
	Sub Main()
		Dim oHandlerExists As String = "On1stViewEventHandlerExists"
		Dim oTaEvents As TransactionEvents = ThisApplication.TransactionManager.TransactionEvents
		If SharedVariable.Exists(oHandlerExists) Then
			Dim oRemove As MsgBoxResult = MsgBox("Handler Exists.  Remove it?", vbYesNo + vbQuestion, "HANDLER EXISTS")
			If oRemove = vbYes Then
				RemoveHandler oTaEvents.OnCommit, AddressOf TransactionEventsSink_OnCommitEventHandler
				SharedVariable.Remove(oHandlerExists)
			End If
		End If
		If SharedVariable.Exists(oHandlerExists) = False Then
			Dim oAdd As MsgBoxResult = MsgBox("Handler doesn't exist.  Create it?", vbYesNo + vbQuestion, "HANDLER DOESN'T EXIST")
			If oAdd = vbYes Then
				AddHandler oTaEvents.OnCommit, AddressOf TransactionEventsSink_OnCommitEventHandler
				SharedVariable(oHandlerExists) = True
			End If
		End If
	End Sub
		
	Sub TransactionEventsSink_OnCommitEventHandler(TransactionObject As Inventor.Transaction, Context As Inventor.NameValueMap, BeforeOrAfter As Inventor.EventTimingEnum, ByRef HandlingCode As Inventor.HandlingCodeEnum)
		Dim oDDoc As DrawingDocument = ThisDrawing.Document
		If BeforeOrAfter = EventTimingEnum.kAfter And
			HandlingCode = HandlingCodeEnum.kEventHandled Then
			If oDDoc.ActiveSheet.DrawingViews.Count = 1 Then
				iLogicVb.RunExternalRule("Copy All Custom iProperties from Model to Drawing")
			End If
		End If
	End Sub
' End Class

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes