Hello everyone.
I was able to come up with a code that selects dimensions from a specific view and then we can do as we want with them.
In my case I want to:
- Go through all dimensions from a view
- Select vertical Dimensions
- Hide their dimension value
So far this code is only working for horizontal dimensions and not at all working for vertical dimensions. Can you guy please help me with that??
Edit 1: I just got to know that the line
if oLinearDim.IntentOne.Geometry.Parent Is oView Then
is the cause of problem as the dimension is being taken from two different planes in an assembly and not from a single geometry. Can anyone tell me how do i fix it to ge all dimensions?
Sub Main
Dim oView As DrawingView = ActiveSheet.View("VIEW1").View
For Each oDim As DrawingDimension In GetDrawingDimForView(oView)
'If oDim.Type = kLinearGeneralDimensionObject Then
Dim oVertGenDim As LinearGeneralDimension = oDim
'If oVertGenDim.DimensionType = kVerticalDimensionType Then
oVertGenDim.HideValue = True
'oDim.Text = HEIGHT_RANGE
'End If
'End If
Next
End Sub
Function GetDrawingDimForView(oView As DrawingView) As ObjectCollection
Dim oDrawDimsForView As ObjectCollection
oDrawDimsForView = ThisApplication.TransientObjects.CreateObjectCollection
Dim oDrawDims As DrawingDimensions
oDrawDims = oView.Parent.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 Is oView Then
If oLinearDim.DimensionType = kHorizontalDimensionType Then
MessageBox.Show("Message", "Title")
oDrawDimsForView.Add(oDrawDimIterator)
End If
End If
Case Else
'Case is not handled...
End Select
Next
GetDrawingDimForView = oDrawDimsForView
End Function
I would try a different approach by checking lineardimension.IntentOne.PointOnSheet, if it lays within a view. See code below:
Sub Main
Dim oView As DrawingView = ActiveSheet.View("main").View
For Each oDim As GeneralDimension In oView.Parent.DrawingDimensions.GeneralDimensions
'check dimension if it lays in view
If IsDimensionInView(oDim, oView)
'hide value
oDim.HideValue = True
End If
Next
End Sub
Private Function IsDimensionInView(ByVal oDim As GeneralDimension, ByVal oView As DrawingView) As Boolean
'create bounding box around a view
Dim b As Box2d = ThisApplication.TransientGeometry.CreateBox2d()
b.MinPoint = ThisApplication.TransientGeometry.CreatePoint2d(oView.Left, oView.Top - oView.Height)
b.MaxPoint = ThisApplication.TransientGeometry.CreatePoint2d(oView.Left + oView.Width, oView.Top)
Dim x As Double, xx As Double
Select Case oDim.Type
Case ObjectTypeEnum.kLinearGeneralDimensionObject
Try
'create linesegment2d representing dimension line and save startpoint and endpoint x values
Dim lin As LineSegment2d = oDim.DimensionLine
x = Round(lin.StartPoint.X, 5)
xx = Round(lin.EndPoint.X, 5)
'if bounding box contains intentone point a x's values are the same, it's a vertical dimension in view you are looking for
If b.Contains(oDim.IntentOne.PointOnSheet) AndAlso x = xx Then
Return True
Else
Return False
End If
Catch
Return False
End Try
End Select
End Function
Hi @sohaib.as01. These cases which involve determining the connection between a DrawingDimension object and the DrawingView object that it is supposed to be associated with are always interesting. As you likely noticed, there is no direct link between the two objects, so there have been many methods used over the years in the attempt to determine that connection. I have seen folks try to go through the GeometryIntent object of the dimension, then follow the Geometry.Parent path to the DrawingView, but that does work 100% for all cases. I have seen folks attempt to determine of some piece of geometry of the dimension is within the bounds of the view, similar to the example above. And I have seen folks use suppression of views to determine which group of dimensions belong to specific views. All of these methods will likely work a lot of the time, but I'm not sure if any of them will always work 100% of the time for all dimension types in all situations. Below are a few links to some of the other forum posts trying to solve that same problem in these different ways.
Wesley Crihfield
(Not an Autodesk Employee)
Can't find what you're looking for? Ask the community or share your knowledge.