Hi@bhavikpatel311 .
Here is another version of the code that is built to deal with when there are multiple views on the sheet, and there are center marks within multiple views. This version is also using the OrdinateDimensionSets.Add() method. Since Ordinate type dimensions need to indicate an origin, then the other dimensions specify distance away from that origin, there needs to be more than one dimension in the set for them to work as intended. If there is only one dimension, it will be the origin dimension, so its value will be zero, which doesn't accomplish anything. So this code checks the Count of the resulting collection to see if it is either zero or 1, and if so, it doesn't attempt to create ordinate dimensions for the one (or none) center mark that was within that view. This helps avoid some of the errors. As stated at the end of my previous post, this version first starts looping through each view on the sheet. Then it defines the view's bounding box. Then it starts looping through all the center marks on the sheet. When one of the center marks is found to be within the bounds of that view, it then gets its geometry intent and adds it to the collection to be processed. After the center marks loop is done, it checks the count of the collection as mentioned above. Then if more than 1, it attempts to create the ordinate dimensions for them. Then loops to the next view on the sheet. Please note that the 'collection' is defined within the loop of the views, instead of at the top (or outside of the loop). This is important, so it cleans itself (recreates itself) fresh for each loop, and doesn't keep the previous intent objects in it. There are a lot of checks and messages in this code, so once your comfortable with how everything works, you can comment out some of those messages (because they can get irritating after a while).
Here's the new version code:
Sub Main
Dim oDDoc As DrawingDocument = ThisDrawing.Document
Dim oSheet As Sheet = oDDoc.ActiveSheet
Dim oOrdDimSets As OrdinateDimensionSets = oSheet.DrawingDimensions.OrdinateDimensionSets
Dim oOrdDimSet As OrdinateDimensionSet
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
For Each oView As DrawingView In oSheet.DrawingViews
'define the view's bounding box
Dim oBottomLeft As Point2d = oTG.CreatePoint2d(oView.Left, oView.Top - oView.Height)
Dim oTopRight As Point2d = oTG.CreatePoint2d(oView.Left + oView.Width, oView.Top)
Dim oViewBounds As Box2d = oTG.CreateBox2d()
oViewBounds.MinPoint = oBottomLeft
oViewBounds.MaxPoint = oTopRight
'create the collection object
Dim oIntents As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
'loop through the center marks, checking which ones are within this view
For Each oCM As Centermark In oSheet.Centermarks
If oViewBounds.Contains(oCM.Position) Then
'this center mark is within this view, so add its 'Intent' to the collection
Dim oGIntent As GeometryIntent
If oCM.Attached Then
' MsgBox("This Centermark is 'Attached' to a " & TypeName(oCM.AttachedEntity), , "")
If TypeOf oCM.AttachedEntity Is GeometryIntent Then
oGIntent = oCM.AttachedEntity
End If
Else
MsgBox("This Centermark is NOT 'Attached'.", , "")
End If
If oGIntent Is Nothing Then
oGIntent = oSheet.CreateGeometryIntent(oCM, PointIntentEnum.kCenterPointIntent)
End If
oIntents.Add(oGIntent)
End If
Next
'check the count of the resulting collection, before trying to use it
If oIntents.Count = 0 Then
MsgBox("There were no 'Intents' found in the view named " & oView.Name & vbCrLf & _
"Skipping to the next View (if any).", , "")
Continue For
ElseIf oIntents.Count = 1 Then
MsgBox("There was only 1 'Intent' found in the view named " & oView.Name & vbCrLf & _
"Skipping to the next View (if any).", , "")
Continue For
Else
MsgBox("There were " & oIntents.Count & " 'Intents' found for view named " & oView.Name,,"")
End If
' To Set the value Of 'Placement' based on first Centermark's position
' Dim o1stPt As GeometryIntent = oIntents.Item(1)
' Dim oPlacement As Point2d = o1stPt.PointOnSheet.Copy
' oPlacement.X = (oPlacement.X - 1)
Dim oPlacement As Point2d = oTG.CreatePoint2d(1, 1)
Try
oOrdDimSet = oOrdDimSets.Add(oIntents, oPlacement, DimensionTypeEnum.kVerticalDimensionType)
Catch oEx As Exception
MsgBox("Failed to 'Add' OrdinateDimensionSet to specified Centermarks." & vbCrLf & _
vbCrLf & "Error Message:" & vbCrLf & oEx.Message & vbCrLf & _
vbCrLf & "Error StackTrace:" & vbCrLf & oEx.StackTrace & vbCrLf & _
vbCrLf & "Error Source:" & vbCrLf & oEx.Source,vbExclamation, "")
End Try
Next
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.
If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS
Wesley Crihfield

(Not an Autodesk Employee)