Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

API events for drawing view

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
prakash.muthu
420 Views, 4 Replies

API events for drawing view

Hi,

 

We are looking for API events triggered on selecting files in drawing view option. This will help us to find which file getting imported to drawing file. 

 

steps:

  1. Open the Inventor 2022 application.

  2. Click New and select "Standard.dwg" option.

  3. Click "Place Views" under the "Base"

  4. Popup folder "Drawing view" will display and Click "Component".

  5. Click "Open an Existing file" in File field and select already protected part file.

Tags (1)
4 REPLIES 4
Message 2 of 5
WCrihfield
in reply to: prakash.muthu

Hi @prakash.muthu.  Unfortunately, I believe the only drawing related events that we have direct access to through Inventor's API are the DrawingEvents.OnRetrieveDimensions Event, and the DrawingViewEvents.OnViewUpdate Event.  And I believe that second one is the same one that you see listed within the Event Triggers dialog, named 'Drawing View Change'.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 5
prakash.muthu
in reply to: WCrihfield

WCrihfield, Thank you for the reply.

How to add drawing view events. 

Message 4 of 5
WCrihfield
in reply to: prakash.muthu

Hi @prakash.muthu.  I do not think it is possible for us (regular Inventor users) to define new events for the DrawingView Object.  Those Events are built into Inventor's API (application programming interface) for that object by Autodesk.  There is a block of code somewhere within their program files which creates the Class that is used to define these DrawingView objects.  Within that Class block of code is where all of its Methods (Sub & Function routines), Properties, & Events are defined/created.  Either Autodesk would have to update their Class block of code to define/create new Events for it, or we would have to create our own new Class block of code to represent our own version slightly different version of the DrawingView object, in which we define new Events for it.  But then you would have to know how to back-up those events, so they can be used, and you would have to define your DrawingView object as being one of your different Type of object, so you could access its Events.  It's pretty complicated.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 5

Hi Prakash,

 

I'm assuming that from your drawing you cant just fire an external rule Before Document Save, that would get the model of the last view on the active sheet?  E.g.

Dim inventorApp As Application = ThisApplication
' Check that the active edit document is a drawing document
If Not inventorApp.ActiveDocument.DocumentType = kDrawingDocumentObject Then
	Logger.Info("Not Drawing Document")
	Exit Sub
End If
drawingDoc = inventorApp.ActiveDocument
' Get the active sheet as thats where the view is being placed
Dim drgActiveSheet As Sheet = drawingDoc.ActiveSheet
' Set reference to the views on the sheet
Dim activeSheetDrawingViews As DrawingViews = drgActiveSheet.DrawingViews
' Get the last view created
Dim newestView As DrawingView = activeSheetDrawingViews.Item(activeSheetDrawingViews.Count)
' Get the document that this view references
docViewModel = newestView.ReferencedDocumentDescriptor.ReferencedDocument
' Get the file name, this is hopefully what you are after and you can then write this to an iProperty or text file etc...
' This will obviously get updated each time a new view is placed, and override the previous value
Dim viewModelName As String = docViewModel.FullDocumentName
MsgBox("New View model: " & viewModelName)

Assuming that you can't, then this next code may be handy. Please test it thoroughly before using it on production drawings.

 

' After the create view command has finished it gets the last created view's model filename
' Add this rule to your drawing template as an external rule, on the following rule events New Document & After Open Document 
Class ThisRule
	Private WithEvents appEvents As ApplicationEvents
	Private WithEvents docEvents As DocumentEvents
	Public drawingDoc As DrawingDocument = Nothing
	Public FDName As String
	Public beforeTimingEnum As EventTimingEnum = EventTimingEnum.kBefore
	Public afterTimingEnum As EventTimingEnum = EventTimingEnum.kAfter
	Public contxt As NameValueMap
	Public handling As HandlingCodeEnum
	Public reasonForChange As CommandTypesEnum
	Public previousCMDName As String = Nothing
	Public previousPreviousCMDName As String = Nothing

	Sub Main
		Dim inventorApp As Application = ThisApplication
		' Check that the active edit document is a drawing document
		If Not inventorApp.ActiveDocument.DocumentType = kDrawingDocumentObject Then
			Logger.Info("Not Drawing Document")
			Exit Sub
		End If
		drawingDoc = inventorApp.ActiveDocument
		If drawingDoc Is Nothing Then Logger.Error("$$$drawingDoc is nothing")
		appEvents = inventorApp.ApplicationEvents
		docEvents = drawingDoc.DocumentEvents
		FDName = drawingDoc.FullDocumentName
	End Sub

	Sub appEvents_OnCloseDocument(drawingDoc As Document, FDName As String, beforeTimingEnum As EventTimingEnum, contxt As NameValueMap, _
		ByRef handling As HandlingCodeEnum) Handles appEvents.OnCloseDocument
		Logger.Info("Closing Doc")
		RemoveHandler docEvents.OnChange, AddressOf docEvents_OnChange
		RemoveHandler appEvents.OnCloseDocument, AddressOf appEvents_OnCloseDocument
	End Sub

	Sub docEvents_OnChange(reasonForChange As CommandTypesEnum, afterTimingEnum As EventTimingEnum, _
		contxt As NameValueMap, ByRef handling As HandlingCodeEnum) Handles docEvents.OnChange
		Dim CommandName As String = contxt.Value("DisplayName")
		Logger.Info("1CommandName: " & CommandName)
		Logger.Info("2previousCMDName: " & previousCMDName)
		' Only run after these three commands have been run in this sequence, otherwise we can end up in a loop. 
		' This seems to be the sequence of commands that happen when at the tail end of view creation
		If CommandName = "Edit View Properties" And previousCMDName = "Edit View Properties" And previousPreviousCMDName = "Create Drawing View" Then
			' Get the active sheet as thats where the view is being placed
			Dim drgActiveSheet As Sheet = drawingDoc.ActiveSheet
			' Set reference to the views on the sheet
			Dim activeSheetDrawingViews As DrawingViews = drgActiveSheet.DrawingViews
			' Get the last view created
			Dim newestView As DrawingView = activeSheetDrawingViews.Item(activeSheetDrawingViews.Count)
			' Get the document that this view references
			docViewModel = newestView.ReferencedDocumentDescriptor.ReferencedDocument
			' Get the file name, this is hopefully what you are after and you can then write this to an iProperty or text file etc...
			' This will obviously get updated each time a new view is placed, and override the previous value
			Dim viewModelName As String = docViewModel.FullDocumentName
			MsgBox("New View model: " &  viewModelName)
			Logger.Info("New View model: " &  viewModelName)
		End If
		previousPreviousCMDName = previousCMDName
		previousCMDName = CommandName
	End Sub
End Class ']j

 Cheers,

 

James

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report