Search Edges from the Solid face

Samarinder Singh

Search Edges from the Solid face

Hi,

I would like to select the edges from the selected face of the solid. I tried the following code but it doesn't seem to work. Thanks for any feedback.

Sub CATMain()
    Set partDocument1 = CATIA.ActiveDocument
    Dim objSel1, arryFilter1(0) 'As Selection
    arryFilter1(0) = "Face"
    Set objSel1 = partDocument1.Selection
    objSel1.Clear
    status1 = objSel1.SelectElement2(arryFilter1, "select any face", False)
    Call objSel1.Search("Type=Topology.Edge,sel")
    MsgBox objSel1.Count2 & " Edges are found from the selected face"
End Sub

Thanks,
Samarinder
Attachments

  • SearchEdges4mSolidFace.CATPart (72.5k)

Fernando Petre

RE: Search Edges from the Solid face
(in response to Samarinder Singh)

Hi,

 

I believe you need first to extract the surface then you can get the face from surface.

 

But you can get directly the edge from solid using

 

arryFilter1(0) = "Edge"

 

Hope will help you.

 

Best regards

Fernando

https://picasaweb.google.com/102257836106335725208

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

Samarinder Singh

RE: Search Edges from the Solid face
(in response to Fernando Petre)

Hi Fernando,

Thanks for the reply. I want to select the face and then automatically select its edges. I am able to do it from the surface features with no problem. If the face belongs to the solid then all edges of the solid will be selected. And that doesn't do any good.

I can try Edge selection as long as it allows me to select all contiguous tangent edges. So I am not sure if there is any API in Catia which allows you to select such tangent edges based upon one preselected edge. The main purpose for this automation is to eliminate extra mouse clicks in order to prepare the geometry for the machining. If all else fails, I can create extra geometry.

Regards,
Samarinder

Little Cthulhu

RE: Search Edges from the Solid face
(in response to Samarinder Singh)

Hi. 

 

Use "Topology.CGMEdge,sel" search query

Fernando Petre

RE: Search Edges from the Solid face
(in response to Little Cthulhu)

Hi,

 

Little is right, I completly forget about this kind of search (even if I was using selection1.Search("Topology.CGMVertex,sel") in another macro for electrical bundles )

 

 

Best regards

Fernando

https://picasaweb.google.com/102257836106335725208

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

Samarinder Singh

RE: Search Edges from the Solid face
(in response to Fernando Petre)

Thanks but "Type=Topology.CGMEdge,sel" didn't work in R21sp6. I'll try it later in R22sp4.

Regards,
Samarinder

Fernando Petre

RE: Search Edges from the Solid face
(in response to Samarinder Singh)

You are right, is working only for All and not for Sel (also in CATIA r18) but it will work in an extracted and selected element

 

Dim Language As String
Language="VBSCRIPT"

Sub CATMain()
Dim  colDocum        As Documents        
Dim  DocActivo       As Document         
Dim  part1              AS Part             
Dim  colBodies       As Bodies         
Dim  hSFact            As Factory          

Dim  colHBody            As HybridBodies    
Dim  OpenBody1         As HybridBody       
Dim  sStatus                As String       
Dim  mySelection        As Selection         
Dim InputObjectType(0)
InputObjectType(0) = "Face"   
Dim refBorde              As Reference 

Set DocActivo = CATIA.ActiveDocument
Set part1 = DocActivo.Part
Set mySelection = DocActivo.Selection
Set hSFact = part1.HybridShapeFactory
Set colBodies = part1.Bodies

Status = mySelection.SelectElement2(InputObjectType, "Select a Face or hit ESCAPE: ", True)
   If (Status = "Cancel") Then
    Exit Sub
   End If

Set refBorde = mySelection.Item(1).Value
Dim hybridShapeExtract1 as HybridShapeExtract
Set hybridShapeExtract1 = hSFact.AddNewExtract(refBorde)
    hybridShapeExtract1.PropagationType = 3
    hybridShapeExtract1.ComplementaryExtract = False
    hybridShapeExtract1.IsFederated = False
Set refBorde = hybridShapeExtract1
hybridShapeExtract1.Name ="Extracted_Face"

''''' Create Open Body
Dim HB1 As HybridBodies
Set HB1 = CATIA.ActiveDocument.Part.HybridBodies
Dim Hierarchie1, ImKoerper As HybridBody
Set Hierarchie1 = HB1.Add
Hierarchie1.Name = "Extracted_Elements"
''''''''
Set colHBody = part1.HybridBodies
Set OpenBody1 = part1.InWorkObject       
OpenBody1.AppendHybridShape hybridShapeExtract1
part1.InWorkObject = hybridShapeExtract1

part1.Update
mySelection.Clear
mySelection.Add(hybridShapeExtract1)

Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument

Dim selection1 As Selection
Set selection1 = partDocument1.Selection

selection1.Search "Topology.CGMEdge,sel"

    MsgBox selection1.Count2 & " Edges are found from the selected face"

End Sub

 

Best regards

Fernando

https://picasaweb.google.com/102257836106335725208

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

Alexandre Desaulniers

RE: Search Edges from the Solid face
(in response to Fernando Petre)
Edited By:
Alexandre Desaulniers[DBM Reflex] @ May 10, 2013 - 01:32 PM (America/Eastern)
Alexandre Desaulniers[DBM Reflex] @ May 10, 2013 - 01:34 PM (America/Eastern)

Alexandre Desaulniers

RE: Search Edges from the Solid face
(in response to Alexandre Desaulniers)

Doesn't work in R19 SP6

Alexandre Desaulniers

RE: Search Edges from the Solid face
(in response to Alexandre Desaulniers)

I found a creative way (to say the least) of finding edges from selected surface on a solid.

 

Tried on a face of the Partbody

 

Woks by analysing all the edges of the solid to see if they match the face definition (BRep name)

 

Doesnt seem to work on an extract of the Partbody (will look into it later)

 

Long process if your solid is complex

 

 

Have Fun!!

 

Sub catmain()

Set partDocument1 = CATIA.ActiveDocument

Dim part1 As Part
Set part1 = partDocument1.Part

Dim oSel 'As Selection
Set oSel = CATIA.ActiveDocument.Selection

Dim InputObjectType(0) As Variant
InputObjectType(0) = "Face"

Dim Status As String
Status = oSel.SelectElement2(InputObjectType, "Select a Face or hit ESCAPE: ", True)
   If (Status = "Cancel") Then
    Exit Sub
End If

Dim oFace As Face
Set oFace = oSel.Item(1).Value

Dim FaceParent
Set FaceParent = oFace.Parent

Dim aFaceName As Variant
aFaceName = Split(oFace.Name, "Selection_RSur:(Face:(")

Dim sFaceName1 As String
sFaceName1 = aFaceName(UBound(aFaceName))

aFaceName = Split(sFaceName1, ";" & FaceParent.Name & ";")
sFaceName1 = aFaceName(0)

Dim sFaceName2 As String
sFaceName2 = aFaceName(UBound(aFaceName))

oSel.Clear
oSel.Add FaceParent
oSel.Search ("Topology.Edge,sel")

Dim sEdgeName As String

Dim iFoundEdges As Integer
iFoundEdges = 0

Dim oFoundEdges As Collection
Set oFoundEdges = New Collection

For i = 1 To oSel.Count
sEdgeName = oSel.Item(i).Value.Name
Dim aEdgeName As Variant
aEdgeName = Split(sEdgeName, "face")
sEdgeName = "face" & aEdgeName(UBound(aEdgeName))
If sEdgeName Like "*" & sFaceName1 & "*" & sFaceName2 & "*" Then
    Dim Edge As Edge
    Set Edge = oSel.Item(i).Value
    oFoundEdges.Add Edge
    iFoundEdges = iFoundEdges + 1
End If
Next i
oSel.Clear

If Not iFoundEdges = 0 Then
    For i = 1 To oFoundEdges.Count
        oSel.Add oFoundEdges.Item(i)
    Next i
    MsgBox iFoundEdges & " Edge(s) found"
Else
    MsgBox "No Edge found"
End If

End Sub

Edited By:
Alexandre Desaulniers[DBM Reflex] @ May 10, 2013 - 02:28 PM (America/Eastern)

Samarinder Singh

RE: Search Edges from the Solid face
(in response to Alexandre Desaulniers)

Hi Alexandre,

Thanks for the help. I thought about this approach but I didn't know how to check the BRep values for the matching edges. Also it could take really long time to perform a search on the complex shapes where solids can have literally over thousands of edges. So it would be nice if DS releases some API for the boundary edges from the selected face of any given solid/surface.

Regards,
Samarinder

Little Cthulhu

RE: Search Edges from the Solid face
(in response to Fernando Petre)
Samarinder, remove "Type=" from your query and it should work.

Alexandre, BREP's are interesting, but were discussed in a very detailed way a couple of years ago by Mike Berry. This approach is slow as you must use internal object's id to identify it (and not it's name, like you do) and it can be retrieved with KW only, so we waste time on evaluating formulas. Double search works way faster in most cases, especially with HSOSynchronized set to false.
Also note that a query may fail because of the last delimiter symbol before scope modifier: in R22 it is ",sel" while in older releases I had to use ";sel". Again, I made a very detailed post on universal search query syntax not a long time ago.

I feel I should make myself clear, Alexandre, I have nothing against you suggesting ideas. In fact providing an alternative is a great thing, but it looks to me that you're reinventing a wheel.
Edited By:
Little Cthulhu[Sikorsky Aircraft] @ May 10, 2013 - 11:13 PM (Europe/Moscow)

Samarinder Singh

RE: Search Edges from the Solid face
(in response to Little Cthulhu)

Hi LC,

I tried and none of the following statements work in R22sp4. And objSel1.Count2 shows 0 in all cases.

objSel1.Search "Topology.CGMEdge,sel"

Call objSel1.Search ("Topology.CGMEdge,sel")

objSel1.Search "Topology.Edge,sel"

Call objSel1.Search ("Topology.Edge,sel")

Regards,
Samarinder

Little Cthulhu

RE: Search Edges from the Solid face
(in response to Samarinder Singh)

You did select a feature from which you want to retrieve edges BEFORE running search query, right?

Samarinder Singh

RE: Search Edges from the Solid face
(in response to Little Cthulhu)

Yes, I selected the face from the solid before running the search query.

Regards,
Samarinder

Little Cthulhu

RE: Search Edges from the Solid face
(in response to Samarinder Singh)

What about ";sel"?

Samarinder Singh

RE: Search Edges from the Solid face
(in response to Little Cthulhu)

Nope. It didn't work either.

Regards,
Samarinder

Little Cthulhu

RE: Search Edges from the Solid face
(in response to Samarinder Singh)
Please, post a picture of your model and specification tree with face selected (I will have access to R22 only on monday)

Samarinder Singh

RE: Search Edges from the Solid face
(in response to Little Cthulhu)

Thanks for the help and here is the r21 sample part and snapshot.

Regards,
Samarinder
Attachments

  • Part5.CATPart (205.9k)
  • 5-11-2013 2-05-59 PM.png (29.6k)
Edited By:
Samarinder Singh[CUTPATH] @ May 11, 2013 - 02:06 PM (America/Pacific)

Alexandre Desaulniers

RE: Search Edges from the Solid face
(in response to Samarinder Singh)

The BRep search for edges was meant to be a test on my part... for fun if you will ... to see if I could get it working

 

I don't really use BReps but Little I would like to get links to Mike's post and yours for reading.

 

Little Cthulhu

RE: Search Edges from the Solid face
(in response to Alexandre Desaulniers)

Search: 

http://www.coe.org/p/fo/st/topic=113&post=77824#p77824

 

BREPs (can't find posts I was referring to, below goes an extract from CAA-RADE docs): 

http://www.maruf.ca/files/caadoc/CAAMmrTechArticles/CAAMmrGenericNaming.htm

Noah Bettin

RE: Search Edges from the Solid face
(in response to Samarinder Singh)

Are you allowed to create any geometry? Not as clean as what you want but that's what I do. Get the face reference, add it as a surfacedatum, make an extract, select the extract.

 

                Dim sel_SourceFaceToProject As Selection
                sel_SourceFaceToProject = myProductDocument.Selection
                sel_SourceFaceToProject.Clear()
                sel_SourceFaceToProject.Add(objCol.Item(i).Value)

                'get the source part info from selection
                Dim sourcePartProduct As Product
                sourcePartProduct = sel_SourceFaceToProject.Item2(1).LeafProduct

                Dim SourcePartDocument As PartDocument
                SourcePartDocument = sourcePartProduct.ReferenceProduct.Parent

                Dim SourcePart As Part
                SourcePart = SourcePartDocument.Part

                Dim SourcePartDocumentName As String
                SourcePartDocumentName = SourcePartDocument.Name

                Dim ref_SourceFaceToProject As Reference
                ref_SourceFaceToProject = sel_SourceFaceToProject.Item2(1).Reference

                'add to reference the product path
                Dim ProductPath As String
                Dim GeometryPath As String
                Dim pos As Integer
                Dim ref_GeomInProduct As Reference
                Dim brepName As String

                brepName = GetCorrectedBREPName(ref_SourceFaceToProject.Name)
                ref_SourceFaceToProject = targetPart.CreateReferenceFromBRepName(brepName, ref_SourceFaceToProject.Parent)

                ProductPath = GetInstanceAbsolutePath(sourcePartProduct, "")
                GeometryPath = SourcePart.Parameters.GetNameToUseInRelation(ref_SourceFaceToProject)
                GeometryPath = Replace(GeometryPath, "", "/")
                pos = InStrRev(GeometryPath, "/")
                'GeometryPath = Left(GeometryPath, pos - 1) & "/!" & Mid(GeometryPath, pos + 1, Len(GeometryPath) - pos + 1)
                ref_GeomInProduct = myProduct.CreateReferenceFromName(ProductPath & "!" & GeometryPath)
                'ref_GeomInProduct = myProduct.CreateReferenceFromName(ProductPath & GeometryPath)

                Dim targetHShapes As HybridShapes
                targetHShapes = targetHBody.HybridShapes

                'create Surface of source part surface
                Dim targetHSSExplicit As HybridShapeSurfaceExplicit
                targetHSSExplicit = targetHSFactory.AddNewSurfaceDatum(ref_SourceFaceToProject)
                targetHSSExplicit.Compute()
                'targetHSSExplicit.object =
                'targetHSSExplicit.surface =

                'create extract of source part surface
                Dim targetHSExtract As HybridShapeExtract
                targetHSExtract = targetHSFactory.AddNewExtract(ref_SourceFaceToProject)
                targetHSExtract.Compute()
                targetHSExtract.PropagationType = 3
                targetHSExtract.ComplementaryExtract = False
                targetHSExtract.IsFederated = False

                'add the extract to the geoset
                targetHBody = targetHBodies.Item("REFERENCE GEOMETRY")
                targetHBody.AppendHybridShape(targetHSExtract)
                targetPart.Update()
                targetPart.InWorkObject = targetHSExtract

Samarinder Singh

RE: Search Edges from the Solid face
(in response to Noah Bettin)

Noah,

Thanks for the reply. I can't create extra geometry in the customer-part. But I'll try your method in NCGeometry file which has copy of the solid linked to the customer-part.

Regards,
Samarinder