Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
eric.frissell26WKQ
666 Views, 4 Replies

Activate Referenced Model Opened from Drawing - VBA

I'm trying to write a VBA macro to fill in dates on our models and drawings (because opening iProperties, clicking through the property update menus, just to check 'date' is too much work) and I'm running into a roadblock figuring out how to activate the now open document.  Idea is you run this from the drawing and it re-writes all the dates in the model and drawing - it's worked for the drawing but now I'm expanding it.  Here's the code

 

 

Sub UpdateDrawPropertiesV2()

Dim invDraw As DrawingDocument
Set invDraw = ThisApplication.ActiveDocument

Dim oSheet As Sheet
Dim oDrawingView As DrawingView
Dim oModelDoc As Document


Dim oPropSet As PropertySet
Dim oStatusSet As PropertySet
Dim oProjSet As PropertySet
Set oPropSet = invDraw.PropertySets.Item("Inventor User Defined Properties")
Set oStatusSet = invDraw.PropertySets.Item("Design Tracking Properties")
Set oSumSet = invDraw.PropertySets.Item("Inventor Summary Information")


'Add Drawn By
Dim invDrawDes As Property
Dim invDrawDesigner As String
invDrawDesigner = InputBox("Enter Drawn By Name", drawnby, Default)
Set invDrawDes = oSumSet.ItemByPropId(kAuthorSummaryInformation)
invDrawDes.Value = invDrawDesigner

'Add Drawn By Date
'Debug.Print (Date)
Dim invDrawDate As Property
Set invDrawDate = oStatusSet.ItemByPropId(kCreationDateDesignTrackingProperties)
invDrawDate.Value = Date

invDraw.Save

'Add Designed By Date
Dim invDesignDate As Property
For Each oSheet In invDraw.Sheets
oSheet.Activate
Set oDrawingView = oSheet.DrawingViews.Item(1)
Set oModelDoc = oDrawingView.ReferencedDocumentDescriptor.ReferencedDocument
Call ThisApplication.Documents.Open(oModelDoc.FullDocumentName, True) ' False for invisbly opened

'Need to activate model here'

'Set invDesignDate = ThisApplication.OpenoStatusSet.ItemByPropId(kCreationDateDesignTrackingProperties)


Next
oModelDoc.Save

End Sub

 

 

Calling ThisApplication.Documents....... may not be the most efficient way to do this so if anyone has any suggestions I'd really appreciate it. 

 

Also if anyone has any suggestions on how to set up part/assembly/drawing templates so that things like creation date are linked to first check in that'd be pretty slick too.