Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

GetFaces of a specific Shape say Pad.1 Using Catia API 3

Status
Not open for further replies.

PrasannaNX

Automotive
Aug 5, 2014
31
Hi,

Could someone please guide me in creating a macro where i need to find all faces from a shape object through Catia APIs?
Below is the code where i am looping part document/bodies and initializing shape object from each body.
Here i want to get faces of each body using shape object.

Assume i have 3 part bodies with one pad shape in each.

If there is a different approach to find faces of a specific shape object, also please do mention.

Code:
Sub Main()
        Dim catApp As Application
        Dim catPartDoc As PartDocument
        Dim catPart As Part
        Dim catBodies As Bodies
        Dim catBdy As Body
        Dim catShp As Shape        

        catApp = GetObject(, "CATIA.Application")
        catPartDoc = catApp.ActiveDocument
        catPart = catPartDoc.Part
        catBodies = catPart.Bodies

        For Each catBdy In catBodies            
            For index = 1 To catBdy.Shapes.Count
                If (catBdy.Shapes.Item(index) IsNot Nothing) Then                         
                    catShp = catBdy.Shapes.Item(index)
                End If
            Next
        Next
  End Sub
 
Replies continue below

Recommended for you

Code:
Dim sel: set sel = CATIA.ActiveDocument.Selection
sel.Clear
sel.Add catShp
sel.Search "Topology.CGMFace,sel"
Dim i, faceRef
for i=1 to sel.Count
  set faceRef = sel.Item(i).Value
  ' use faceRef below
  ...
next
 
I didn't know what the “specific shape” was, so I made a sample to select a flat surface.

Code:
Option Explicit

Sub CATMain()

    Dim catApp As Application
    Set catApp = CATIA 'GetObject(, "CATIA.Application")
    
    Dim catPartDoc As PartDocument
    Set catPartDoc = catApp.ActiveDocument
    
    Dim catPart As part
    Set catPart = catPartDoc.part
    
    Dim sel As selection
    Set sel = catPartDoc.selection
        
    Dim catBodies As Bodies
    Set catBodies = catPart.Bodies
    
    
    ' find flat face
    Dim flatFaces As Collection
    Set flatFaces = New Collection
    
    Dim catBdy As Body
    Dim i As Long
    Dim elm As AnyObject
    
    catApp.HSOSynchronized = False
    
    For Each catBdy In catBodies
        sel.Clear
        sel.Add catBdy
        sel.Search "Topology.CGMFace,sel"
        
        For i = 1 To sel.Count2
            Set elm = sel.Item(i).Value
            If typename(elm) = "PlanarFace" Then
                flatFaces.Add elm
            End If
        Next
    Next
    sel.Clear
    
    catApp.HSOSynchronized = True


    ' select face
    catApp.HSOSynchronized = False
    
    For Each elm In flatFaces
        sel.Add elm
    Next
    
    catApp.HSOSynchronized = True


    MsgBox "Done"

End Sub
 
Thank you both, this is exactly what i am looking for.
Sorry for the newbie question.

Thanks,
Prasanna M
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor