Entities sketch analysis

Entities sketch analysis

AlbertoOutline
Participant Participant
816 Views
2 Replies
Message 1 of 3

Entities sketch analysis

AlbertoOutline
Participant
Participant

Hi everyone,

I'm writing a VBA program to realize an automatic drilling of sheet metal. I need to analyze the entities in the sketch and understand if these entities are internal, external, or intersecting with a closed profile of any shape.

I attach an example. In this sketch, there are four entities:
- One entity is the outline of my profile
- 3 circle entities

How do I analyze each circle entity with profile entity to know if it is inside, outside, or intersecting the profile?

 

Circle1 and Profile ----> Internal

Circle2 and Profile ----> Intersecting

Circle3 and Profile ----> External

Thanks in advance to anyone who can help me

 

-----------------------------------------

 

Salve a tutti, 

sto scrivendo un programma VBA per realizzare una foratura automatica di reti. Ho la necessità di analizzare delle entità nello schizzo e capire se queste sono interne, esterne o si intersecano con un profilo chiuso di qualsiasi forma.

 

Allego un esempio. In questo schizzo ci sono 4 entità:

1 entità che rappresenta il mio contorno del profilo

3 entità cerchio

 

Come faccio ad analizzare le entità cerchio rispetto all'entità profilo e capire se il cerchio è interno, esterno o interseca il profilo?

 

Circle1 e Profile ----> Interno

Circle2 e Profile ----> Intersecante

Circle3 e Profile ----> Esterno

 

Grazie in anticipo a chiunque possa aiutarmi

 

 

0 Likes
Accepted solutions (1)
817 Views
2 Replies
Replies (2)
Message 2 of 3

wayne.brill
Collaborator
Collaborator
Accepted solution

Hi Alberto,

 

Here is a VBA example I worked up. It meets your requirment as I understand it. If this does not provide a solution upload an ipt that I can use to research.

 

I did not find an easier way. This example uses ProfilePath objects. It iterates through and gets the circles. For each ProfilePath that is a circle it checks to see if it adds material. If it adds material then it is outside or partially outside. (This is one idea that needs testing) If it adds material then all the other ProfilePaths are looped through. If it has line segments then the lines are tested to see if they intersect the circle. It will highlight the circles that are inside, outside and the ones that intersect.

 

 

Public Sub Sketch_Profile_location_Test()
    Dim oPrtDoc As PartDocument
    Set oPrtDoc = ThisApplication.ActiveDocument
    
    Dim oSketch As PlanarSketch
    Set oSketch = oPrtDoc.ComponentDefinition.Sketches(1)

    Dim oProfile As Profile
    Set oProfile = oSketch.Profiles.AddForSolid

    Dim oProfilePath As ProfilePath
    
    Dim bCircleNotOutside As Boolean
    bCircleNotOutside = True
 
    Dim oProfilePath_2 As ProfilePath
    Dim oProfileEnt As ProfileEntity
    Dim oProfileEnt_2 As ProfileEntity
    
    Dim oCircleCurve As Circle2d
    Dim oLineSegment As LineSegment2d
    Dim oOjectsCurveEnum As ObjectsEnumerator
 
    Dim oCirclesSelectInside As ObjectCollection
    Set oCirclesSelectInside = ThisApplication.TransientObjects.CreateObjectCollection
    
    Dim oCirclesSelectOutside As ObjectCollection
    Set oCirclesSelectOutside = ThisApplication.TransientObjects.CreateObjectCollection
    
    Dim oCirclesSelectIntersect As ObjectCollection
    Set oCirclesSelectIntersect = ThisApplication.TransientObjects.CreateObjectCollection
    
    ' Go Through ProfilePath to find the circles
    For Each oProfilePath In oProfile
    ' The ProfilePath with the circles have a count of 1
    If oProfilePath.count = 1 Then
    'Make sure it is a circle
    If oProfilePath(1).CurveType = kCircleCurve2d Then
    ' In my tests if the ProfilePath AddMaterial = True then
    ' it is completely outside or partially outside
    If oProfilePath.AddsMaterial = True Then
       
        'Go through each ProfilePath to find the lines
        For Each oProfilePath_2 In oProfile
        
        For Each oProfileEnt In oProfilePath_2
            If oProfileEnt.CurveType = kLineSegmentCurve2d Then
              Set oLineSegment = oProfileEnt.curve
              Set oOjectsCurveEnum = oLineSegment.IntersectWithCurve(oProfilePath(1).curve)
              If Not oOjectsCurveEnum Is Nothing Then
               bCircleNotOutside = True
               MsgBox ("A Circle INTERSECTS")
               Call oCirclesSelectIntersect.Add(oProfilePath(1).SketchEntity)
               Exit For
              Else
                bCircleNotOutside = False
              End If
            End If
        Next oProfileEnt
        
        If Not bCircleNotOutside Then
            MsgBox ("A Circle is OUTSIDE")
            bCircleNotOutside = True
            Call oCirclesSelectOutside.Add(oProfilePath(1).SketchEntity)
        End If
        Next oProfilePath_2
    Else
        MsgBox ("Circle is INSIDE")
        Call oCirclesSelectInside.Add(oProfilePath(1).SketchEntity)
    End If 'oProfilePath.AddsMaterial = True
    End If 'oProfilePath(1).CurveType = kCircleCurve2d
    End If 'oProfilePath.count = 1
    Next oProfilePath

    Call oPrtDoc.SelectSet.SelectMultiple(oCirclesSelectInside)
    MsgBox ("Circles inside selected")
    oPrtDoc.SelectSet.Clear
    Call oPrtDoc.SelectSet.SelectMultiple(oCirclesSelectOutside)
    MsgBox ("Circles outside selected")
    oPrtDoc.SelectSet.Clear
    Call oPrtDoc.SelectSet.SelectMultiple(oCirclesSelectIntersect)
    MsgBox ("Circles intersected selected")
    
End Sub

 

Thanks,

Wayne



Wayne Brill
Developer Technical Services
Autodesk Developer Network

Message 3 of 3

AlbertoOutline
Participant
Participant
Thank you very much.... great soluction!
0 Likes