Retrieve Slected Dimension in View with VBA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am using Inventor Pro 2014. For several years now, I have been using a VBA macro to create an .idw file with drawing views of a part or assembly. I'm now trying to go to the next step and retrieve selected dimensions for the part or components of the assembly and place in the .idw view.
I found this code in an earlier post:
Private Sub RetrieveTest_1() Dim oDrawDoc As DrawingDocument Set oDrawDoc = ThisApplication.ActiveDocument Dim oSheet As Sheet Set oSheet = oDrawDoc.Sheets.Item(1) Dim oView As DrawingView Set oView = oSheet.DrawingViews.Item(1) 'object collection for dimensions to be retrieved Dim oTO As TransientObjects Set oTO = ThisApplication.TransientObjects Dim oObjColl As ObjectCollection Set oObjColl = oTO.CreateObjectCollection 'fill the object collection with some dimension constrains 'Here we use sketch DimensionConstraint objects. Dim oDoc As PartDocument Set oDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument Dim oDef As PartComponentDefinition Set oDef = oDoc.ComponentDefinition Dim oDimConstraints As DimensionConstraints Set oDimConstraints = oDef.Sketches.Item(1).DimensionConstraints Dim oDC As DimensionConstraint 'add first two constraints to the collection Set oDC = oDimConstraints.Item(1) MsgBox (oDC.Parameter.Name) Call oObjColl.Add(oDC) 'Set oDC = oDimConstraints.Item(2) 'Call oObjColl.Add(oDC) 'retrieve subset of dimensions On Error Resume Next Call oSheet.DrawingDimensions.GeneralDimensions.Retrieve(oView, oObjColl) MsgBox (Error) On Error GoTo 0 ' 'retrieve all the dimensions ' Call oSheet.DrawingDimensions.GeneralDimensions.Retrieve(oView) End Sub 'RetrieveTest_1
When I try to run this, it gives an error on the line, "Call oSheet.DrawingsDim ...." The error is "Method 'Retrieve' of object 'GeneralDimensions' failed."
oDC is being found, and the MsgBox is returning the proper name of a dimension in the part. Also, it will retrieve all of the dimensions.
Any idea what's going on here? Perhaps retrieve all the dims and sort them to get rid of the ones that don't work?
Thanks,
Tim Rumph
