Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Obtain Edges of Selected Face in C# / Makro 1

Status
Not open for further replies.

user7

Computer
Sep 14, 2022
8
0
0
DE
thread560-350640

anyone having the solution still in mind for this problem:

I have a face, for which I would like to obtain all edges.

ActiveCatiaDocument.Selection.Add(_native_face);
ActiveCatiaDocument.Selection.Search("Type=Topology.Edge,sel");

delivers 0 elements in selection.

Solution in previous post "you need first to extract the face" - but link does not work anymore.

Thank you in advance
Best
Matt
 
Replies continue below

Recommended for you

_native_face is a MECMOD.Face
obtained like this:

Selection.Search("Type=Face,all"); //(sel is some body)
facei = Selection.Item(i).Reference
 
In the meantime, I found a solution for CAA - seems like an overkill to me, though...
Would be glad if anyone has a solution. The problem seems quite simple - Just get all Edges of a Face... Catia is truely special ;)


Code:
// pPathElement1 is the path on the face at hand
// CATIPrtPart_var spPart is the parentpart CATIPrtContainer->GetPart()

        CATBaseUnknown* pBaseUnknownSurface = pPathElement1->FindElement(CATSurface::ClassId());
	CATSurface_var spInputFaceSurface = pBaseUnknownSurface;
	CATIMmiMechanicalFeature_var spBaseFeatureOfInputFace = pBaseUnknownSurface;

	if (spBaseFeatureOfInputFace == NULL_var)
	{
		// Is it a selecting object?
		CATIMmiUseBRepAccess* pBRepAccess = NULL;
		hr = spInputFaceSurface->QueryInterface(IID_CATIMmiUseBRepAccess, (void**)&pBRepAccess);
		if (SUCCEEDED(hr))
		{
			hr = pBRepAccess->GetBRepSelectingFeature(spBaseFeatureOfInputFace);

			// get the cell of the input feature 
			CATCell_var spCellOfInputFace;
			pBRepAccess->GetBRepSelectingCell(spCellOfInputFace);

			CATBody_var spBodySolid = spPart->GetSolid();
			CATIMmiUseBRepDecodeServices_var spBRepDecodeServices;
			CATMmiUseServicesFactory::CreateBRepDecodeServices(spBRepDecodeServices);

			// get all edges (cells) of input face cell
			CATLISTP(CATCell) edgesOfInputFaceList;
			spCellOfInputFace->GetAllCells(edgesOfInputFaceList, 1);

			// loop through edges
			for (int e = 1; e < edgesOfInputFaceList.Size() + 1; e++)
			{
				CATCell_var sp_InputFaceEdgeCell = edgesOfInputFaceList[e];
				if (NULL_var == sp_InputFaceEdgeCell) continue;

				// find representative BRep for the neighbour cell
				CATIMmiUseBRepAccess_var cellRepAccess = NULL_var;
				spBRepDecodeServices->DecodeCellInBody(cellRepAccess, sp_InputFaceEdgeCell, spBodySolid)

                                CATPathElement* pPathElementXX = new CATPathElement(cellRepAccess);
                                /// do the magic with the path of the edge - for instance, add it to user selection
                        }
                 }
           }
 
How i see this :
If you want to findout nr. of all of your edges, use this : Selection.Search ("Topology.CGMEdge,all")

If you need for a specific face :
1 : if it's a face of a solid you need to use that face as a reference - make an extract-add to selection that surface and use "Type=Topology.Edge,sel"
2 : if you have multiple surfaces allready in the tree, then add those surfaces to selection

If i am giving you the wrong direction maybe someone else could correct me.


 
Thank you for your response.

I would like to obtain the edges only of one certain face.
For instance, here, this face in question is selected randomly by search:

Code:
Selection selection = ((INFITF.Application)Marshal.GetActiveObject("Catia.Application")).ActiveDocument.Selection;
selection.Clear();
selection.Selection.Search("Type=Face,all");
MECMOD.Face aFace = (MECMOD.Face)selection.Selection.Item(1).Reference; //simply the first face in the selection is taken

// now, with this starting point - I would like to get a list of "Edge" objects for this face

selection.Clear();
selection.Add(aFace);
selection.Search("Type=Topology.Edge,sel");
int c1 = selection.Count; // c1 = 0

selection.Clear();
selection.Add(aFace);
selection.Search("Type=Topology.CGMEdge,sel");
int c2 = selection.Count; // c2 = 0

maybe what you said in (1) is the missing piece in my code. Any ideas on how to "make an extract-add" to the face 'aFace' i have?
 
First time i made a code in C# but challenge accepted :

{
PartDocument partDocument1 = (PartDocument)catia.ActiveDocument;
Document partDocument = (Document)partDocument1;

Selection osel2 = (Selection)partDocument.Selection;
string status2;

Face face1 = null;
status2 = osel2.SelectElement2(new object[] { "Face" }, "Select face ", false);
if (status2 == "Normal" && osel2.Count == 1)
{
face1 = (Face)osel2.Item(1).Value;
}

Reference reference1 = (Reference)face1;

Part part1 = (Part)partDocument1.Part;
HybridShapeFactory hybridShapeFactory1 = (HybridShapeFactory)part1.HybridShapeFactory;
Bodies bodies1 = (Bodies)part1.Bodies;
Body body1 = (Body)bodies1.Item("PartBody");
Shapes shapes1 = (Shapes)body1.Shapes;



HybridShapeExtract hybridShapeExtract1 = (HybridShapeExtract)hybridShapeFactory1.AddNewExtract(reference1);
hybridShapeExtract1.PropagationType = 3;
hybridShapeExtract1.ComplementaryExtract = false;
hybridShapeExtract1.IsFederated = false;

HybridBodies hybridBodies1 = (HybridBodies)part1.HybridBodies;
HybridBody hybridBody1 = (HybridBody)hybridBodies1.Item("Geometrical Set.1");
hybridBody1.AppendHybridShape(hybridShapeExtract1);

part1.InWorkObject = hybridShapeExtract1;
part1.Update();

Reference reference2 = (Reference)part1.CreateReferenceFromObject(hybridShapeExtract1);
HybridShapeSurfaceExplicit hybridShapeSurfaceExplicit1 = (HybridShapeSurfaceExplicit)hybridShapeFactory1.AddNewSurfaceDatum(reference2);
hybridBody1.AppendHybridShape(hybridShapeSurfaceExplicit1);

part1.InWorkObject = hybridShapeSurfaceExplicit1;
part1.Update();

Selection selection1 = (Selection)catia.ActiveDocument.Selection;
selection1.Clear();
selection1.Add(hybridShapeSurfaceExplicit1);
object refsel = selection1.Item(1).Value;
selection1.Search("Topology.CGMEdge,sel");

}

There are unnecessary /dublicated stuff but you can change and adapt as per your need .
Hope it will help !
Best regards
 
Thank you for your suggestion!
Not too bad for the first C# shot.

This works perfectly fine!
Only thing one copying the code above must verify is the naming of the primary body "PartBody" and the geometrical set "Geometrical Set.1" which can vary.

Still think it's crazy that we require 50 lines of code in order to obtain the edges of a face. When comparing with SiemensNX for instance this is insane!
 
That part with partbody is not necessary.
For geoset you can add one random to use : HybridBody hybridBody1 = (HybridBody)hybridBodies1.Add();


 
Status
Not open for further replies.
Back
Top