By Barbara Han
Issue
I want to be able to determine or sort out which drawing dimensions belongs to a view in a drawing. Is there an example that shows how this can be done?
Solution
A DrawingDimension object is not directly related to a particular view, they are just annotations on a Sheet. So there is not a direct way to determine which View a DrawingDimension belongs to.
However you can reach this information through the "Intent" property of the GeneralDimension, which is dependent of the View.
Here is a VBA example that you can run on a drawing document. It will iterate through the DrawingDimensions of the sheet and find out if the dimension belongs to a given View, based on the view's name:
VBA:
Public Function GetDrawingDimForView(oSheet As Sheet, ViewName As String) As ObjectCollection
Dim oDrawDimsForView As ObjectCollection
Set oDrawDimsForView = ThisApplication.TransientObjects.CreateObjectCollection
Dim oDrawDims As DrawingDimensions
Set oDrawDims = oSheet.DrawingDimensions
Dim oDrawDimIterator As DrawingDimension
For Each oDrawDimIterator In oDrawDims
Select Case oDrawDimIterator.Type
Case kLinearGeneralDimensionObject
Dim oLinearDim As LinearGeneralDimension
Set oLinearDim = oDrawDimIterator
If oLinearDim.IntentOne.Geometry.Parent.Name = ViewName Then
oDrawDimsForView.Add oDrawDimIterator
End If
Case kRadiusGeneralDimensionObject
Dim oRadiusDim As RadiusGeneralDimension
Set oRadiusDim = oDrawDimIterator
If oRadiusDim.Intent.Geometry.Parent.Name = ViewName Then
oDrawDimsForView.Add oDrawDimIterator
End If
Case kDiameterGeneralDimensionObject
Dim oDiameterDim As DiameterGeneralDimension
Set oDiameterDim = oDrawDimIterator
If oDiameterDim.Intent.Geometry.Parent.Name = ViewName Then
oDrawDimsForView.Add oDrawDimIterator
End If
Case kAngularGeneralDimensionObject
Dim oAngularDim As AngularGeneralDimension
Set oAngularDim = oDrawDimIterator
If oAngularDim.IntentOne.Geometry.Parent.Name = ViewName Then
oDrawDimsForView.Add oDrawDimIterator
End If
Case Else
'Case is not handled...
End Select
Next
Set GetDrawingDimForView = oDrawDimsForView
End Function
'Test function GetDrawingDimForView
Public Sub TestGetDrawingDimensions()
Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.ActiveDocument
Dim oDrawingDimCollec1 As ObjectCollection
Set oDrawingDimCollec1 = GetDrawingDimForView(oDoc.ActiveSheet, "VIEW1")
Dim oDrawingDimCollec2 As ObjectCollection
Set oDrawingDimCollec2 = GetDrawingDimForView(oDoc.ActiveSheet, "VIEW2")
End Sub
VB.NET:
Public Function GetDrawingDimForView(ByVal oSheet As Sheet, ByVal ViewName As String) As ObjectCollection
Dim oDrawDimsForView As ObjectCollection
oDrawDimsForView = _InvApplication.ActiveDocument.TransientObjects.CreateObjectCollection
Dim oDrawDims As DrawingDimensions
oDrawDims = oSheet.DrawingDimensions
Dim oDrawDimIterator As DrawingDimension
For Each oDrawDimIterator In oDrawDims
Select Case oDrawDimIterator.Type
Case kLinearGeneralDimensionObject
Dim oLinearDim As LinearGeneralDimension
oLinearDim = oDrawDimIterator
If oLinearDim.IntentOne.Geometry.Parent.Name = ViewName Then
oDrawDimsForView.Add(oDrawDimIterator)
End If
Case kRadiusGeneralDimensionObject
Dim oRadiusDim As RadiusGeneralDimension
oRadiusDim = oDrawDimIterator
If oRadiusDim.Intent.Geometry.Parent.Name = ViewName Then
oDrawDimsForView.Add(oDrawDimIterator)
End If
Case kDiameterGeneralDimensionObject
Dim oDiameterDim As DiameterGeneralDimension
oDiameterDim = oDrawDimIterator
If oDiameterDim.Intent.Geometry.Parent.Name = ViewName Then
oDrawDimsForView.Add(oDrawDimIterator)
End If
Case kAngularGeneralDimensionObject
Dim oAngularDim As AngularGeneralDimension
oAngularDim = oDrawDimIterator
If oAngularDim.IntentOne.Geometry.Parent.Name = ViewName Then
oDrawDimsForView.Add(oDrawDimIterator)
End If
Case Else
'Case is not handled...
End Select
Next
GetDrawingDimForView = oDrawDimsForView
End Function
'Test function GetDrawingDimForViewPublic
Sub TestGetDrawingDimensions()
Dim oDoc As DrawingDocument
oDoc = _InvApplication.ActiveDocument.ActiveDocument
Dim oDrawingDimCollec1 As ObjectCollection
oDrawingDimCollec1 = GetDrawingDimForView(oDoc.ActiveSheet, "VIEW1")
Dim oDrawingDimCollec2 As ObjectCollection
oDrawingDimCollec2 = GetDrawingDimForView(oDoc.ActiveSheet, "VIEW2")
End Sub
In the case where you have to deal with dimensions that are not GeneralDimensions, the function above is no longer valid and you have no means to sort out these dimensions through that way. However you can still check the "Annotations Visibility->Drawing Dimensions" setting by right-clicking on a view to activate the dimensions on this particular view, and uncheck the same setting on other views. Then if you run this code:
Dim oDoc As DrawingDocumentSet
oDoc = ThisApplication.ActiveDocument
Dim oDrawDims As DrawingDimensionsSet
oDrawDims = oDoc.ActiveSheet.DrawingDimensions
You will get the complete set of DrawingDimensions that are in the specified view.