How to get the edge and face of all the solid bodies ?

Vinod Kettay

How to get the edge and face of all the solid bodies ?

Hello,

I am trying to get all the edges and the faces corresponding to all the solid bodies present in the CATIA 3D part using VB.NET 2010

Can someone help me with a sample code or API's which I can use to get this data.

Thanks,

Amitabh Mukherjee

Fernando Petre

RE: How to get the edge and face of all the solid bodies ?
(in response to Vinod Kettay)

Hi

I'm sure the bellow example code in CATScript you can implement in VS....

Sub CATMain()

Dim objSel As Selection
Set objSel = CATIA.ActiveDocument.Selection
objSel.Search ("Type=Edge,all")
objcount = objSel.Count

MsgBox objcount

End Sub

 

Best regards

Fernando

https://picasaweb.google.com/102257836106335725208

https://picasaweb.google.com/103462806772634246699/

Eric Neuville

RE: How to get the edge and face of all the solid bodies ?
(in response to Fernando Petre)

When I looked at this recently I noticed it also select edges of sketches inside the solid.

I change the color of the solid edges and add color to the selection= did not work.

I also put the sketches on another layer and restrict layer in selection = did not work

Playing with visible parameter... no more luck.

V6 2013x gives same results as R20.

solution might be to copy past solid as result (no more sketches) and select edges from that isolated body only, or look in the BREP name of the edge and remove the one from the sketches...

Fernando Petre

RE: How to get the edge and face of all the solid bodies ?
(in response to Eric Neuville)



In Reply to Eric Neuville:

When I looked at this recently I noticed it also select edges of sketches inside the solid.



You are right.

Try this

 

Sub CATMain()

CATIA.ActiveDocument.Selection.Clear
Set osel = CATIA.ActiveDocument.Selection
osel.Search "Type=Topology.Face,all"

Dim oFoundEdges
Set oFoundEdges = CreateObject("Scripting.Dictionary")

For j = 1 To osel.Count
sEdgeName = osel.Item(j).Value.name

Dim aEdgeName
aEdgeName = Split(sEdgeName, "face")
sEdgeName = "face" & aEdgeName(UBound(aEdgeName))
If InStr(sEdgeName, sFaceName1) and InStr(sEdgeName, sFaceName2) Then

Dim Edge
Set Edge = osel.Item(j).Value
oFoundEdges.Add j, Edge
iFoundEdges = iFoundEdges + 1
End If
Next
osel.Clear

If Not iFoundEdges = 0 Then
For j = 1 To oFoundEdges.Count
osel.Add oFoundEdges.Item(j)
Next

MsgBox oFoundEdges.Count

Else
MsgBox "No edges found"
End If

End Sub

 

Best regards

Fernando

https://picasaweb.google.com/102257836106335725208

https://picasaweb.google.com/103462806772634246699/

Vinod Kettay

RE: How to get the edge and face of all the solid bodies ?
(in response to Fernando Petre)

I used the following code to get all the edge names and the face names in a given 3D Part. Thank you all for the pointer.

Using the .Value property , I can get hold of the 2D face and the 1D edge objects.Now I need to know if there is a way I can determine the start point and end point in 3D coordinates for each of these edges and also get the edge and face types.

Sub CATMain()
' get selected edge (using Edge class is crucial)
Dim CATIA As INFITF.Application        
CATIA = System.Runtime.InteropServices.Marshal.GetActiveObject("CATIA.Application")        'CATIA = GetObject(, "CATIA.Application")        
If CATIA Is Nothing Then CATIA = CreateObject("CATIA.Application")
CATIA.ActiveDocument.Selection.Clear()
Dim osel As Selection
osel = CATIA.ActiveDocument.Selection
osel.Search("Type=Topology.Face,all")
Dim sFaceName As String = ""
Dim sEdgeName As String = ""        
Dim oFace As Face = Nothing        
Dim oEdge As Edge = Nothing
For j = 1 To osel.Count
sFaceName = osel.Item(j).Value.Name            
oFace = DirectCast(osel.Item(j).Value, Face)            
Next       
 osel.Clear()
osel = CATIA.ActiveDocument.Selection
osel.Search("Type=Topology.Edge,all")
For j = 1 To osel.Count
 sEdgeName = osel.Item(j).Value.Name            
oEdge = DirectCast(osel.Item(j).Value, Edge)           
 Next        

osel.Clear()
MsgBox("Completed")

End Sub

Thanks,
Amitabh