how to count circles?

martinhoos
Advocate
Advocate

how to count circles?

martinhoos
Advocate
Advocate

Hello all,

I need your help! We produce some steel metal plates with a punching maschine. It will be great to calculate the manufacturing costs with ilogic.

First of all, I have to say, that we don't buildt our cad parts only by the drilling-tool, often we use only simple circles. In this case I can't count the punchstamps.

It will be greate, to count the circles and get the diameter of the circles, so I can calculate the time to punch this in and the lengths to subtract minus the inner contour.     

I get a code, that gives me the length of the inner and the outer contour.

 

Thanks a lot in advance for your help....

 

Best regards from germany

Martin

 

Herstellkosten - iLogic.jpg

 

0 Likes
Reply
Accepted solutions (1)
1,076 Views
6 Replies
Replies (6)

HermJan.Otterman
Advisor
Advisor

You can go through:

 

ActiveDocument.ComponentDefinition.SurfaceBodies.

 

look at all SurfaceBodies   .Faces.SurfaceType = kCylinderSurface

when it is a hole somewhere in the middle of a plate, it has only two edges.

(when the hole is crossing a bend or so, the cilinder could have more edges)

 

from the Geamerty.Radius you can get the dimension

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes

martinhoos
Advocate
Advocate

Hello Herm, thank you for the reply... sounds good. Can you give me a Little code, because i can not buildt it by myselfe - only copy and past and try  🙂

Thank you very much...

Regards Martin

0 Likes

bshbsh
Collaborator
Collaborator
Accepted solution

lame vba code

Public Sub CircleCount()
    If ThisApplication.ActiveEditDocument Is Nothing Then
        MsgBox ("No active document, exiting.")
        Exit Sub
    Else
        If ThisApplication.ActiveEditDocument.DocumentType = kPartDocumentObject Then
            If ThisApplication.ActiveEditDocument.ComponentDefinition.Type = kSheetMetalComponentDefinitionObject Then
                Dim InvDoc As Document
                Set InvDoc = ThisApplication.ActiveEditDocument
                If InvDoc.ComponentDefinition.HasFlatPattern = True Then
                    Dim FP As FlatPattern
                    Set FP = InvDoc.ComponentDefinition.FlatPattern
                    Dim D As Double
                    Dim CA As Variant
                    Dim CircleEdges As Collection
                    Set CircleEdges = New Collection
                    For Each Edge In FP.TopFace.Edges
                        If Edge.GeometryType = kCircleCurve Then
                            D = Round(1000000 * Edge.Geometry.Radius) / 1000000
                            D = 10 * 2 * D 'diameter rounded. in mm units
                            n = 0
                            For i = 1 To CircleEdges.Count
                                CA = CircleEdges.Item(i)
                                If CA(1) = D Then
                                    CA(0) = CA(0) + 1
                                    n = CA(0)
                                    CircleEdges.Remove (i)
                                    CircleEdges.Add CA
                                    Exit For
                                End If
                            Next
                            If n = 0 Then
                                CircleEdges.Add Array(1, D, 3.141592654 * D)
                            End If
                        End If
                    Next
                    If CircleEdges.Count > 0 Then
                        Dim Strng As String
                        Dim TL As Double
                        Strng = ""
                        TL = 0
                        For i = 1 To CircleEdges.Count
                            TL = TL + CircleEdges.Item(i)(0) * CircleEdges.Item(i)(2)
                            Strng = Strng & CStr(CircleEdges.Item(i)(0)) & "x Diameter=" & CStr(CircleEdges.Item(i)(1)) & "mm; Circumference=" & CStr(CircleEdges.Item(i)(2)) & "mm" & vbNewLine
                        Next
                        MsgBox (Strng & vbNewLine & "Total Cut Length=" & CStr(TL) & "mm")
                    Else
                        MsgBox ("No circular edges found.")
                    End If
                Else
                    MsgBox ("Active document has no flat pattern, exiting.")
                End If
            Else
                MsgBox ("Active document is not a sheetmetal part, exiting.")
                Exit Sub
            End If
        Else
            MsgBox ("Active document is not a part document, exiting.")
            Exit Sub
        End If
    End If
End Sub

bradeneuropeArthur
Mentor
Mentor

Hi,

 

Please take a look.

 

Public Sub Cil()

Dim a As PartDocument
Set a = ThisDocument

Dim b As SurfaceBodies
Set b = a.ComponentDefinition.SurfaceBodies

Dim c As SurfaceBody
Set c = b.Item(1)

Dim d As Faces
Set d = c.Faces

Dim f As Face

MsgBox d.Count
Dim i As Integer
For Each f In d
If f.SurfaceType = kCylinderSurface Then

i = i + 1
End If


Next
MsgBox i & " Cilinders"
'MsgBox b.Count
End Sub

Regards,

Arthur Knoors

Autodesk Affiliations:

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: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 !

0 Likes

martinhoos
Advocate
Advocate

Hello bshbsh - thanks for your reply - thats it!

Regards Martin

 

0 Likes

mucip
Advocate
Advocate

Hi,

Well, is there way to get diameter of this surfaces and mate this surface holes with other parts in assembly?

I need to get diameter of circler holes. If the diameter is 50mm then I want to mate this hole with round rod?

 

Any idea please?...

 

Regards,

Mucip:)

0 Likes