Centralize Dimension Text

Centralize Dimension Text

Anonymous
Not applicable
1,352 Views
10 Replies
Message 1 of 11

Centralize Dimension Text

Anonymous
Not applicable

Hello, I am trying to edit the text on a dimension and at the same time center justify the text.  I am able to do this, but when I add the line of code (oDim2.Text.FormattedText = oDim2.Text.VerticalJustification), the dimension appears justified with the text I added, but it has an unwanted series of trailing numbers (seen in the attached image). Any ideas of how to correct this?  Thank you!

 

Dim oDim2 As GeneralDimension
oDim2=oGeneralDims.AddLinear(oPt2,oSheet.CreateGeometryIntent(oBH),oSheet.CreateGeometryIntent(oTH))
String1 = (Parameter("PLATE MAG.iam.NO_OF_HOLES")/2)-1 & " SPACES @ " & RoundToFraction(Parameter("PLATE MAG.iam.INNER_LENGTH_HOLE_SPACING"),1/16,RoundingMethod.Round) & vbCrLf & " = "
oDim2.text.FormattedText = oDim2.Text.VerticalJustification
oDim2.text.formattedtext = String1 & oDim2.text.FormattedText
oDim2.CenterText
0 Likes
1,353 Views
10 Replies
Replies (10)
Message 2 of 11

bradeneuropeArthur
Mentor
Mentor
I have written an add in to achieve the same.
If wanted I can share it with you.

Send me a private message how I can reach you.

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 11

bradeneuropeArthur
Mentor
Mentor

Hi,

 

You will have to set the precision to "0" when reference the parameter I think.

 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 4 of 11

danmachen
Advocate
Advocate

This code is available in the native Inventor API/ samples.

 

http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-DE98632B-3DC0-422B-A1C6-8A5A15C99E11

 

Check out the others there. You can remove the 'set' to make most of them work out of the box.

 

Here is the snippet directly from there (but with a few updates)

 

doc = ThisDoc.Document

If doc.DocumentType = kDrawingDocumentObject Then
    ' Set a reference to the active drawing document
    Dim oDoc As DrawingDocument
    oDoc = ThisApplication.ActiveDocument

    ' Set a reference to the active sheet
    Dim oSheet As Sheet
    oSheet = oDoc.ActiveSheet

    Dim oDrawingDim As DrawingDimension

    ' Iterate over all dimensions in the drawing and
    ' center them if they are linear or angular.

    For Each oDrawingDim In oSheet.DrawingDimensions
        If TypeOf oDrawingDim Is LinearGeneralDimension Or _
           TypeOf oDrawingDim Is AngularGeneralDimension Then
            Call oDrawingDim.CenterText
        End If
    Next


Else If doc.DocumentType = kAssemblyDocumentObject Then
MessageBox.Show("This is an assembly file.", "iLogic")

Else If doc.DocumentType = kPartDocumentObject Then
MessageBox.Show("This is a part file.", "iLogic")

End If

 

 

 

 

 

 

Dan Machen
Autodesk Inventor 2019 Certified Professional
Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

Ideas that need support:
Circular / Rectangular Point Matrix
Allow Axis & Plane Selection on Rectangular / Circular pattern
Graphical iLogic Programming
Message 5 of 11

bradeneuropeArthur
Mentor
Mentor

Hi,

 

The dimensions to center is not his problem.

 

The visually is the problem. 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 6 of 11

dgreatice
Collaborator
Collaborator

Hi All,

 

I think he just wrong code in :

 

oDim2.text.FormattedText = oDim2.Text.VerticalJustification
oDim2.text.formattedtext = String1 & oDim2.text.FormattedText

 

it must be :

 

oDim2.text.FormattedText = String1

oDim2.Text.VerticalJustification = 'kAlignTextBaseline or kAlignTextLower or kAlignTextMiddle or kAlignTextUpper <-- choose one

and add too :

oDwgDim.Text.HorizontalJustification = 'kAlignTextCenter kAlignTextLeft kAlignTextRight <-- choose one

 

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
0 Likes
Message 7 of 11

bradeneuropeArthur
Mentor
Mentor

Hi,

 

He has also added parameters to the dimension format.

this is to be defined different I think.

When I read the formatted text it is different.

So please upload the necessary information.

 

Thanks,

 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 8 of 11

Anonymous
Not applicable

@dgreaticethis format allowed me to run the code without errors and without additional text being generated into the dimension, but it still did not center justify the text.  I'm not sure if I can center justify the text AND split it into two lines, but it is acceptable as is and I suppose it will have to do.  Thank you

0 Likes
Message 9 of 11

dgreatice
Collaborator
Collaborator
Can you give a example about justify the text with screenshoot? We will compare what do you want about justify a text with first uploading capture from you.
Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
0 Likes
Message 10 of 11

Anonymous
Not applicable

By justified I mean centered within the text box, as seen by comparing the two images attached here.

0 Likes
Message 11 of 11

dgreatice
Collaborator
Collaborator
Now, can i see you new code after i revised you code?

I think at last code with :
oDim2.CenterText
oDim2.Text.HorizontalJustification = kAlignTextCenter


Is enough.
Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
0 Likes