How to check rotated dimension is horizontal or vertical

How to check rotated dimension is horizontal or vertical

tim11_manhhieu
Advocate Advocate
617 Views
8 Replies
Message 1 of 9

How to check rotated dimension is horizontal or vertical

tim11_manhhieu
Advocate
Advocate

I have searched that there seems to be no direct method to determine whether the rotated dimension is horizontal or vertical, and if base on the text position and line dimension positions to calculate, there also seems to be no method to get the coordinates.

0 Likes
Accepted solutions (1)
618 Views
8 Replies
Replies (8)
Message 2 of 9

Ed__Jobe
Mentor
Mentor

This thread has the solution. Although it's in C#, you should be able to understand the principles.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 3 of 9

tim11_manhhieu
Advocate
Advocate

There is no solution in that article.

The article mentions rotation, but VBA does not support it.

I have to ask the user to input the type of dimension.

0 Likes
Message 4 of 9

Ed__Jobe
Mentor
Mentor

@tim11_manhhieu wrote:

There is no solution in that article.


That thread has two solutions as summarized in this post, and an AcadDimRotated object does have a Rotation property. Here's a sample to get you started.

 

Public Function IsHoriz(ent As AcadEntity) As String
    
    Select Case ent.ObjectName
        Case Is = "acDimRotated"
            Dim dr As AcadDimRotated
            Set dr = ent
            If dr.Rotation = 0 Or dr.Rotation = PI Then
                IsHoriz = "horizontal"
            ElseIf dr.Rotation = PI / 2 Or dr.Rotation = 3 * PI / 2 Then
                IsHoriz = "vertical"
            Else
                IsHoriz = "n/a"
            End If
            
        Case Is = "acDimAligned"
            'You can add the code for an aligned dimension.
        Case Else
            IsHoriz = "Error: Not a dimension object."
        
    End Select
End Function

Public Function PI() As Double
  PI = Atn(1) * 4
End Function

 

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 5 of 9

tim11_manhhieu
Advocate
Advocate

thanks for your respond.

I tested, both case Horizontal or Vertical, dr.Rotation return zero 0.

 

 

tim11_manhhieu_0-1739751699184.png

 

0 Likes
Message 6 of 9

Ed__Jobe
Mentor
Mentor

It’s no wonder you get 0, you commented out all the code! Dr is an object that needs to be instantiated. When you comment out the code that sets it, it is null. So all its properties will be default values. Use the function as I wrote it and call it from your main method. 

Sub Main
  Dim ent As AcadEntity
  Dim results As String
  ' code to select an entity 
  results = IsHoriz(ent)
  Select Case = results 
    Case = "horizontal"
      'Do something 
    Case = "vertical"
      'Do something
  End Select
End Sub 

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 7 of 9

tim11_manhhieu
Advocate
Advocate

I modified code but it is not working.

 

tim11_manhhieu_0-1739847944641.png

Option Explicit

Sub Main()

    Dim ent As acadEntity
    Dim results As String
    Dim pt As Variant
    
    ThisDrawing.Utility.GetEntity ent, pt, "Pick dim: "
    
    results = IsHoriz(ent)
    
    Select Case results
    
    Case Is = "horizontal"
        Debug.Print "horizontal"
    Case Is = "vertical"
        Debug.Print "vertical"
    
    End Select

End Sub

Public Function IsHoriz(ent As acadEntity) As String
    
    Select Case ent.ObjectName
    
        Case Is = "AcDbRotatedDimension"
        
            Dim dr As AcadDimRotated
            Set dr = ent
            If dr.Rotation = 0 Or dr.Rotation = PI Then
                IsHoriz = "horizontal"
            ElseIf dr.Rotation = PI / 2 Or dr.Rotation = 3 * PI / 2 Then
                IsHoriz = "vertical"
            Else
                IsHoriz = "n/a"
            End If
            
        Case Else
            IsHoriz = "Error: Not a dimension object."
        
    End Select
    
End Function

Public Function PI() As Double
    PI = Atn(1) * 4
End Function
0 Likes
Message 8 of 9

Ed__Jobe
Mentor
Mentor
Accepted solution

Although the AcadDimRotated object has a Rotation property, it seems to always be zero. So there's no way to figure out horizontal or vertical in ActiveX. You would need to use C# or possibly lisp.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 9 of 9

tim11_manhhieu
Advocate
Advocate

thank you.

0 Likes