.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Dimension prefix bug - putting text in suffix instead

4 REPLIES 4
Reply
Message 1 of 5
etorola
413 Views, 4 Replies

Dimension prefix bug - putting text in suffix instead

There seems to be a bug in the managed wrappers for dimensions.

I have tried this on both aligned and rotated dimensions.

The code below tries to set the text in the prefix of a dimension object, but the text ends up in the suffix instead.


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
4 REPLIES 4
Message 2 of 5
foruma000256
in reply to: etorola

Where did you apply the text to the dimension? I see you open the dimension, and create the text variable, but not put the two together. Am I missing something?

jvj
Message 3 of 5
etorola
in reply to: etorola

Sorry, I edited the code before posting as there was a lot of other extraneous stuff in there.

......
' This ends up in the suffix
Dim textPrefix As String = "Prefix"

*' Add this next line*
*textDim.Prefix = textPrefix*

End If
.......
Message 4 of 5
Hallex
in reply to: etorola

This one works for me nice
(A2008)

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'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 5 of 5
jamkhp
in reply to: etorola

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..

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost