Public Class AddTextToPrefix
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
_
Public Sub AddToDimPrefix()
' Create a new prompt
Dim promptOptions As PromptSelectionOptions = New PromptSelectionOptions()
' We want to select only one dimension at a time
promptOptions.SingleOnly = True
' Prompt string
promptOptions.MessageForAdding = "Select a dimension to add text to."
' Display the prompt
Dim promptResult As PromptSelectionResult = ed.GetSelection(promptOptions)
Using trans As Transaction = db.TransactionManager.StartTransaction()
Try
' Get the selected items
Dim objIDs() As ObjectId = promptResult.Value.GetObjectIds
' We are interested in only the first one (should be only one)
Dim objID As ObjectId = objIDs(0)
' Open the object for reading
Dim obj As Object = trans.GetObject(objID, OpenMode.ForRead)
' Check that we have a dimension object
If TypeOf (obj) Is Dimension Then
' It is a dimension object, now we want only Aligned or rotated (linear dimensions)
If TypeOf (obj) Is AlignedDimension Or TypeOf (obj) Is RotatedDimension Then
' We want the dimension not the object type, so we convert types
Dim textDim As Dimension = CType(obj, Dimension)
' Create the prefix string
' *** Setting the prefix in .Net currently sets the suffix (BUG) ****
' Upgrade the dimension object to write
textDim.UpgradeOpen()
' This ends up in the suffix
Dim textPrefix As String = "Prefix"
End If
End If
Else
' We selected the wrong kind of dimension
ed.WriteMessage(ControlChars.CrLf + "You must select a linear dimension.")
End If
Else
' We selected something other than a dimension
ed.WriteMessage(ControlChars.CrLf + "You must select a linear dimension.")
End If
Catch
Finally
' Commit the transaction
trans.Commit()
End Try
End Using
End Sub
End Class
Public Class AddTextToPrefix
<CommandMethod("DOV")> _
Public Sub AddToDimPrefix() ' Create a new prompt
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim promptOptions As PromptSelectionOptions = New PromptSelectionOptions() ' We want to select only one dimension at a time
promptOptions.SingleOnly = True ' Prompt string
promptOptions.MessageForAdding = "Select a dimension to add text to." ' Display the prompt
Dim promptResult As PromptSelectionResult = ed.GetSelection(promptOptions)
Using trans As Transaction = db.TransactionManager.StartTransaction()
Try ' Get the selected items
Dim objIDs() As ObjectId = promptResult.Value.GetObjectIds ' We are interested in only the first one (should be only one)
Dim objID As ObjectId = objIDs(0) ' Open the object for reading
Dim obj As Entity = trans.GetObject(objID, OpenMode.ForWrite, True)
'Dim obj As Object = trans.GetObject(objID, OpenMode.ForWrite) ' Check that we have a dimension object
If TypeOf (obj) Is Dimension Then ' It is a dimension object, now we want only Aligned or rotated (linear dimensions)
If TypeOf (obj) Is AlignedDimension Or TypeOf (obj) Is RotatedDimension Then ' We want the dimension not the object type, so we convert types
Dim textDim As Dimension = obj 'CType(obj, Dimension)
' Create the prefix string
' *** Setting the prefix in .Net currently sets the suffix (BUG) ****
' Upgrade the dimension object to write
'textDim.UpgradeOpen()
' This ends up in the suffix
Dim textPrefix As String = "SomePrefix-"
Dim textSuffix As String = "-SomeSuffix"
textDim.DimensionText = textPrefix & "<>" & textSuffix
'textDim.Suffix = Left$(textPrefix, 4)
ed.Regen()
trans.Commit()
Else ' We selected the wrong kind of dimension
ed.WriteMessage(ControlChars.CrLf + "You must select a linear dimension.")
End If
Else ' We selected something other than a dimension
ed.WriteMessage(ControlChars.CrLf + "You must select a linear dimension.")
End If
Catch ex As Exception
ed.WriteMessage(ex.Message)
Finally ' Commit the transaction
End Try
End Using
End Sub
End Class
~'J'~
Hi I am not sure whether you got it fixed, but some I figured it out instead of using & as a string combine operator use + then it works fine
Dim PrefiXX AsString = "%%C"
YourDim.DimensionText = PrefiXX + "<>"
Should produce the results as a diameter dimension
I hope this might help to the one who looking for it.
Cheers..