Diamter Model Dimension Text Center

Diamter Model Dimension Text Center

tim11_manhhieu
Advocate Advocate
269 Views
5 Replies
Message 1 of 6

Diamter Model Dimension Text Center

tim11_manhhieu
Advocate
Advocate

Hi, i got error at line 22.
No text center method for diameter model dimension? 

and is there any shorter code, I want text center for linear dimension, angular dimension and diameter dimension.

thank you.

Option Explicit

Sub ModelDimensionTextCenter()

    Dim oPart As PartDocument
    Set oPart = ThisApplication.ActiveDocument
    
    Dim oLinears As LinearModelDimensions
    Set oLinears = oPart.ComponentDefinition.ModelAnnotations.ModelDimensions.LinearModelDimensions
    
    Dim oDiameters As DiameterModelDimensions
    Set oDiameters = oPart.ComponentDefinition.ModelAnnotations.ModelDimensions.DiameterModelDimensions
    
    Dim oLinear As LinearModelDimension
    Dim oDiameter As DiameterModelDimension
    
    For Each oLinear In oLinears
        oLinear.CenterText
    Next
    
    For Each oDiameter In oDiameters
        oDiameter.CenterText
    Next

End Sub

 

 

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

WCrihfield
Mentor
Mentor
Accepted solution

It looks like your original code is in VBA, instead of iLogic or vb.net, so I will try to copy your original code, modify it, and post it back here for you.  I do not use VBA now, but I used to.  Also, I see you are working with 'model' dimensions (3D Annotations), which are created within the model directly, instead of drawing dimensions.  Basically, the linear type (LinearModelDimension.CenterText) and angular type (AngularModelDimension.CenterText) both have the method for centering their text, but the diameter type (DiameterModelDimension) does not have that method, so you will not be able to do that with those.

 

Sub ModelDimensionTextCenter()
    Dim oPart As PartDocument
    Set oPart = ThisApplication.ActiveDocument
	Dim oModelDims As Inventor.ModelDimensions = oPart.ComponentDefinition.ModelAnnotations.ModelDimensions
    Dim oLinears As LinearModelDimensions
    Set oLinears = oModelDims.LinearModelDimensions
    Dim oAngulars As AngularModelDimensions
    Set oAngulars = oModelDims.AngularModelDimensions
    Dim oLinear As LinearModelDimension
    Dim oAngular As AngularModelDimension
    For Each oLinear In oLinears
        oLinear.CenterText()
    Next
    For Each oAngular In oAngulars
        oAngular.CenterText()
    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) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

C_Haines_ENG
Collaborator
Collaborator

Didn't like my solution? 😂

0 Likes
Message 4 of 6

WCrihfield
Mentor
Mentor

I'm sure your code is a solution also, but maybe just not for this specific task.  😄

Seems like you have been pretty active in this forum today.  Glad to see it.  It just happens that most of my replies are falling just after some of yours.  Not criticizing anything, just adding hopefully useful information to the discussions.

I have had to greatly slow down my engagement in the Autodesk Community area lately, due to multiple recent changes where I work, so only popping in once in a while now. Carry on. 👍

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 6

tim11_manhhieu
Advocate
Advocate

thanks for your respond, i am working on 3D model, not drawing :D.

0 Likes
Message 6 of 6

tim11_manhhieu
Advocate
Advocate

thanks for your solution.

0 Likes