By Adam Nagy
If you want to retrieve only specific dimensions from the document that is shown in a drawing view then you can use Sheet.DrawingDimensions.GeneralDimensions.Retrieve()
We start with this this set of documents (can be found in this forum post):
Here is the d0 dimension in Sketch1 we are trying to get back:
Here is the VBA code to do it:
Private Sub RetrieveTest() 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) ' Create object collection for dimensions to be retrieved Dim oTO As TransientObjects Set oTO = ThisApplication.TransientObjects Dim oObjColl As ObjectCollection Set oObjColl = oTO.CreateObjectCollection ' Get the derived part document Dim oDoc As PartDocument Set oDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument Dim oDef As PartComponentDefinition Set oDef = oDoc.ComponentDefinition Dim oRefComps As ReferenceComponents Set oRefComps = oDef.ReferenceComponents ' Get the definition of assembly it's derived from Dim oDerAsmDef As DerivedAssemblyDefinition Set oDerAsmDef = oRefComps.DerivedAssemblyComponents(1).Definition ' Get the part being used Dim oPartCompDef As PartComponentDefinition Set oPartCompDef = _ oDerAsmDef.Occurrences(1).ReferencedOccurrence.Definition ' Get the dimensions of the first sketch Dim oDC As DimensionConstraint Set oDC = oPartCompDef.Sketches(1).DimensionConstraints(1) ' Show the name of the dimension we are retrieving MsgBox (oDC.Parameter.Name) Call oObjColl.Add(oDC) ' Retrieve subset of dimensions Call oSheet.DrawingDimensions.GeneralDimensions.Retrieve( _ oView, oObjColl) End Sub
Here is the code in action: