How To Count Circle by Specific Diamter in Drawing

How To Count Circle by Specific Diamter in Drawing

tim11_manhhieu
Enthusiast Enthusiast
189 Views
4 Replies
Message 1 of 5

How To Count Circle by Specific Diamter in Drawing

tim11_manhhieu
Enthusiast
Enthusiast

I'm trying to count all circle diameter 32.5 to double check.

Below is my minimum code, or if you have better code that would be great.

 

tim11_manhhieu_0-1738817973312.png

 

 

Option Explicit

Sub CountCircles()

    Dim oDoc As DrawingDocument
    Dim oDrawView As DrawingView
    
    Set oDoc = ThisApplication.ActiveDocument
    Set oDrawView = oDoc.ActiveSheet.DrawingViews.item(1)

    Dim oCurve As DrawingCurve
    Dim count As Integer

    For Each oCurve In oDrawView.DrawingCurves
        If oCurve.CurveType = kCircleCurve Then
        
            'HOW TO CALCULATE CIRCLE's DIAMETER
            'If Abs(oSegment.endPoint.x - oSegment.startPoint.x) * 2 = 32.5 Then
                'count = count + 1
            'End If
        
        End If
    Next
    
MsgBox count
  
End Sub

 

 

 

0 Likes
190 Views
4 Replies
Replies (4)
Message 2 of 5

tim11_manhhieu
Enthusiast
Enthusiast

I think I figured it out but there are some problems. Is there something wrong?

 

1) Why quantity of Φ32.5 is 1126, the right value 1126/2 = 563.

tim11_manhhieu_0-1738817335820.png

 

2) but when i count Φ13, the quantity is 10 (this is right value, no need to divide 2)

 

tim11_manhhieu_1-1738817408108.png

 

3) when i changed to Φ31.6, the quantity is zero, the right value is 1. 

 

tim11_manhhieu_2-1738817446437.png

 

4) when i changed to Φ32.9, the quantity is double, the right value is 1

(Hole Φ32.9 is concentric with hole Φ31.6 and is on the back side)

 

tim11_manhhieu_3-1738817562209.png

 

 

Option Explicit

Sub zzzz()

Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oSheet As sheet
Set oSheet = oDoc.ActiveSheet

Dim oView As DrawingView
Set oView = oSheet.DrawingViews.item("1")

Dim oDrawingCurve As DrawingCurve

Dim count As Integer
Dim diameter As Double
Dim specificDiameter As Double

specificDiameter = 32.5

For Each oDrawingCurve In oView.DrawingCurves

    If oDrawingCurve.CurveType = kCircleCurve Then
        
        diameter = oDrawingCurve.Segments.item(1).Geometry.Radius * 200
 
        If diameter = specificDiameter Then
             count = count + 1
        End If
    
    End If

Next

Debug.Print count

End Sub

 

0 Likes
Message 3 of 5

marcin_otręba
Advisor
Advisor

hi,

 

maybe you could post your drawing with model here ? i checked your code with my model and it works fine when i remove doubles decimal length error using:

 

If Round(diameter, 5) = Round(specificDiameter, 5) Then

 

in line 28.

 

in ilogic or vb you can use compareto function:

 

  If diameter.CompareTo(specificDiameter)=0  Then

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

Message 4 of 5

tim11_manhhieu
Enthusiast
Enthusiast

Thanks for your enthusiasm,
when I use the software's default template, the result is correct,

but when I use my company's template, the result is wrong.
I don't understand why and I probably don't have the interest to find out why.

Because it's an unnecessary waste of time.
Thanks again.

0 Likes
Message 5 of 5

JelteDeJong
Mentor
Mentor

for anyone who finds this interesting. Keep in mind that "oDrawingCurve.Segments.item(1).Geometry.Radius" gives a value in Cm. You need to convert the value yourself to the correct units.

Jelte de Jong
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.

EESignature


Blog: hjalte.nl - github.com