Update model when opening the drawing

Update model when opening the drawing

a81383
Enthusiast Enthusiast
351 Views
4 Replies
Message 1 of 5

Update model when opening the drawing

a81383
Enthusiast
Enthusiast

Hello,

In the code below I'm using the "on open" event to identify when a drawing is opened. I'm then trying to grab the model used in the drawing and update multiple model states within it. 

 

The only way I've found that works, is to use the document open command "oDocOpen = ThisApplication.Documents.Open(FullFileName, True)". But in order to update multiple model states I have to set visibility to "True" and physically open the model, which I would rather not have to do. 

 

Is there a better way to accomplish this?

 

        Private Sub m_ApplicationEvents_OnOpenDocument(ByVal DocumentObject As Inventor._Document, ByVal FullDocumentName As String,
            ByVal BeforeOrAfter As Inventor.EventTimingEnum, ByVal Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum) Handles m_ApplicationEvents.OnOpenDocument
            If BeforeOrAfter = EventTimingEnum.kAfter And DocumentObject Is ThisApplication.ActiveDocument Then
                If localEventsEnabled = False Then Exit Sub
                Select Case True
                    Case DocumentObject.DocumentType = Inventor.DocumentTypeEnum.kDrawingDocumentObject
                        Dim oDocOpen, oDrawDocOpen As Inventor.Document
                        Dim FullFileName As String = Nothing
                        Select Case True
                            Case My.Computer.FileSystem.FileExists(IO.Path.ChangeExtension(FullDocumentName, "iam"))
                                FullFileName = IO.Path.ChangeExtension(FullDocumentName, "iam")
                                oDocOpen = ThisApplication.Documents.Open(FullFileName, True)
                            Case My.Computer.FileSystem.FileExists(IO.Path.ChangeExtension(FullDocumentName, "IAM"))
                                FullFileName = IO.Path.ChangeExtension(FullDocumentName, "IAM")
                                oDocOpen = ThisApplication.Documents.Open(FullFileName, True)
                            Case Else
                                Exit Sub
                        End Select

                        Dim inv As InventorLink = New InventorLink(oDocOpen)
                        Try : Dim oTest As String = inv.getParam("pane_type") : oDocOpen.Close() : Exit Sub : Catch : End Try
                        Try : Dim GLS_ID As Integer = inv.getParam("GLASS_ID") : Catch : oDocOpen.Close() : Exit Sub : End Try

                        Dim glassRule As Glass_Master_Rule = New Glass_Master_Rule
                        glassRule.Main(DocumentObject, oDocOpen, 1)
                        oDrawDocOpen = ThisApplication.Documents.Open(FullDocumentName, True)
                End Select
            End If
        End Sub

 

0 Likes
352 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Hi @a81383.  I could be wrong, but it looks to me like you may need to keep in mind the differences between 'FullFileName' & 'FullDocumentName' within that routine.  That 'Open' method requests that you use the 'FullDocumentName', because it can contain extra information to indicate which variation of something within the document should be active when the main file is opened.  The FullDocumentName will start with the value of the FullFileName, but then sometimes, it will also include the LOD name (prior to 2022), or ModelState name (2022 or later), or iPart/iAssembly member name, or something like that.  You can use that to your advantage to open and get direct access to specific ModelState version of a file that has multiple ModelStates defined within it.  In order to be able to take more/better advantage of this file/document naming conventions / resources, you should include the use of the Inventor.FileManager object into your routine.  You can use that to get a list of ModelState names within a file (if any), which ModelState was active when that file was last saved, assemble, and dis-assemble FullFileName / FullDocumentName Strings.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

Frederick_Law
Mentor
Mentor

Update ModelState?

The model is not up to date?

Or drawing not up to date?

 

Also.

Select Case True?

What are you selecting?

https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/select-case-stat...

Message 4 of 5

Frederick_Law
Mentor
Mentor

Not sure what you mean by "update ModelState".

I create drawing for each ModelState with iLogic.

SaveAs the drawing and change ModelState in each View.

For Each oDrawingView In oIDWFile.ActiveSheet.DrawingViews
	If oDrawingView.ActiveModelState <> oMSName Then
		Logger.Info(oDrawingView.Label.Text & " " & oDrawingView.ActiveModelState)
		oDrawingView.SetActiveModelState(oMSName, True, True)
	End If
Next
0 Likes
Message 5 of 5

Frederick_Law
Mentor
Mentor

ModelStates is under ComponentDefinition of PartDocument and AssemblyDocument.

 

oDocOpen.ComponentDefinition.ModelStates

 

0 Likes