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