By Adam Nagy
There is already a similar post related to Derived Assemblies. The difference there is that in that case you could not get a proxy for a sketch entity because there is no direct connection between the proxy inside the derived document and the native object in the original document:
http://adndevblog.typepad.com/manufacturing/2014/11/get-edge-in-derived-part-that-drives-work-point.html
In case of a normal assembly we need to get the proxy for the sketch dimension entity that resides inside the part document. We can then use that to retrieve what we need.
Sub RetrieveDimension() Dim oDwg As DrawingDocument Set oDwg = ThisApplication.ActiveDocument Dim oSheet As Sheet Set oSheet = oDwg.ActiveSheet Dim oView As DrawingView Set oView = oSheet.DrawingViews.Item(2) Dim oAsmDoc As AssemblyDocument Set oAsmDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument Dim oRefOcc As ComponentOccurrence Set oRefOcc = oAsmDoc.ComponentDefinition.Occurrences.Item(1) Dim oPartDoc As PartDocument Set oPartDoc = oRefOcc.Definition.Document Dim oPartCompDef As PartComponentDefinition Set oPartCompDef = oPartDoc.ComponentDefinition Dim oDC As DimensionConstraint Set oDC = oPartCompDef.Sketches(1).DimensionConstraints(1) Dim oDCproxy As Object Call oRefOcc.CreateGeometryProxy(oDC, oDCproxy) Dim oObjColl As ObjectCollection Set oObjColl = ThisApplication.TransientObjects.CreateObjectCollection() Call oObjColl.Add(oDCproxy) Call oSheet.DrawingDimensions.GeneralDimensions.Retrieve(oView, oObjColl) End Sub
Note: if for some reason retrieving a specific dimension is not working then you could work around it by retrieving all the dimensions and deleting the ones you don't need:
Dim oDims As GeneralDimensionsEnumerator Set oDims = oSheet.DrawingDimensions.GeneralDimensions.Retrieve(oView) Dim o As Object For Each o In oDims If Not o.RetrievedFrom Is oDCproxy Then Call o.Delete End If Next