Fit text to drawing dimensions.

Fit text to drawing dimensions.

kv5053545
Advocate Advocate
725 Views
5 Replies
Message 1 of 6

Fit text to drawing dimensions.

kv5053545
Advocate
Advocate

Hello, I have been working on making automatic dimensions in a .dwg document but I have not been able to center the text of the dimensions, since the occurrences can vary in size and add more, I do not know if you can help me to center the text so that it is always in the center regardless of the size of the occurrence.

Since if I try to give size to the text on some occasions it is put with another dimension or it is too small, I attach the code that I am working on.

 

Sub Main()
       
        If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub

        Dim oDDoc As DrawingDocument = ThisDoc.Document 
        Dim oStMgr As DrawingStylesManager = oDDoc.StylesManager 
        Dim oDimStyles As DimensionStylesEnumerator = oStMgr.DimensionStyles   
        Dim oDimStyle As DimensionStyle = oDimStyles.Item("Default (ANSI)") 

        oDimStyle.ArrowheadType = ArrowheadTypeEnum.kBlankArrowheadType   
        oDimStyle.ArrowheadSize = 0.2286
        oDimStyle.ArrowheadHeight = 0.08 

        oDimStyle.Extension = 0.4572 
        oDimStyle.Gap = 0.000 
        oDimStyle.Spacing = 0.000  

        Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument 

        Dim oDStyle As DimensionStyle = oDrawDoc.StylesManager.ActiveStandardStyle.ActiveObjectDefaults.LinearDimensionStyle

        Dim sFontSize As String = oDStyle.TextStyle.FontSize

        Dim x As Double
        x = 0.25
        oDStyle.TextStyle.FontSize = x
    End Sub

 

image.png

0 Likes
Accepted solutions (1)
726 Views
5 Replies
Replies (5)
Message 2 of 6

m_baczewski
Advocate
Advocate
Accepted solution

Give it a try as I mentioned, at this point it should go through all the dimensions and center their positions.

Sub Main()
       
        If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub

        Dim oDDoc As DrawingDocument = ThisDoc.Document 
        Dim oStMgr As DrawingStylesManager = oDDoc.StylesManager 
        Dim oDimStyles As DimensionStylesEnumerator = oStMgr.DimensionStyles   
        Dim oDimStyle As DimensionStyle = oDimStyles.Item("Default (ANSI)") 

        oDimStyle.ArrowheadType = ArrowheadTypeEnum.kBlankArrowheadType   
        oDimStyle.ArrowheadSize = 0.2286
        oDimStyle.ArrowheadHeight = 0.08 

        oDimStyle.Extension = 0.4572 
        oDimStyle.Gap = 0.000 
        oDimStyle.Spacing = 0.000  

        Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument 

        Dim oDStyle As DimensionStyle = oDrawDoc.StylesManager.ActiveStandardStyle.ActiveObjectDefaults.LinearDimensionStyle

        Dim sFontSize As String = oDStyle.TextStyle.FontSize

        Dim x As Double
        x = 0.25
        oDStyle.TextStyle.FontSize = x

        Dim oDimensions As DrawingDimensions
        oDimensions = oDDoc.ActiveSheet.DrawingDimensions

        Dim oDrawDim As DrawingDimension

        For Each oDrawDim In oDimensions
           If TypeOf oDrawDim Is LinearGeneralDimension
              Call oDrawDim.CenterText
           End If
        Next
End Sub

 

Message 3 of 6

kv5053545
Advocate
Advocate

Hi @m_baczewski , I was trying the code you provided but, I keep getting the same thing that the dimensions are put to one side of the dimension in a way that I understand that is the size of the text but if I put it smaller to make a smaller assembly is not reached to read by the same thing that is very small, is there any way to make the text resize if it goes out so to speak of the range of the arrows? 

kv5053545_0-1692986084319.png

 

0 Likes
Message 4 of 6

m_baczewski
Advocate
Advocate

You can move the dimension text to the left side, for example of the code looks like this:

Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument
Dim oDimensions As DrawingDimensions
oDimensions = oDoc.ActiveSheet.DrawingDimensions

oDimension1 = oDimensions.Item(12)
oDimension1.Text.Origin = "Yours new position dimension as Point2d"

Try changing the size of the dimension arrows.You can also consider creating a drawing that will be more legible.

0 Likes
Message 5 of 6

kv5053545
Advocate
Advocate

Hi @m_baczewski,

In the end, I didn't get the text to fit automatically, I decided to let the user choose the text size (based on another post here in the forum).
This rule only changes the text size, and the rule you provided I used to leave the values from the default style editor.

    Try
        Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
		'Get the active linear dimension style in the document
        Dim oDStyle As DimensionStyle = oDoc.StylesManager.ActiveStandardStyle.ActiveObjectDefaults.LinearDimensionStyle 
		'Get current font size of dimension style
        Dim sFontSize As String = oDStyle.TextStyle.FontSize 
        
		'Display an input dialog box for the user to enter the new font size.
        Dim oInput As String
        oInput = InputBox("Active Dimension style = " & oDStyle.Name & vbLf & vbLf & "Enter a new font size in mm.", "Text size", Format(sFontSize / 0.1, "#0.0"))
        
        ' Check if the input is an integer (no decimal point)
        If IsNumeric(oInput) AndAlso Not oInput.Contains(".") Then
            ' Append ".0" to the input
            oInput = oInput & ".0"
        End If
        
		'Update dimension style font size with user input
        oDStyle.TextStyle.FontSize = CDbl(oInput) * 0.1

		
    Catch
		
    End Try
0 Likes
Message 6 of 6

jaime75
Contributor
Contributor

o que eu  preciso é o contrario, preciso que quando o espaço para o texto for muito pequeno o texto seja automaticamente movido para a direita ou para a esquerda da linha 

0 Likes