There are many types of edges and faces, you must first determine what type it is then you can cast to it.
here's some sample code in Boo, you should be able to get the gist of what you need to do.
[CommandMethod('soltrav')]
public static def travsol():
""" Code to demonstrate traversal of a 3d solid using the Brep lib """
// Obtain the necessary objects, Database, editor and transaction
db as Database = HostApplicationServices.WorkingDatabase
ed as Editor = Application.DocumentManager.MdiActiveDocument.Editor
tr as Transaction = db.TransactionManager.StartTransaction()
try:
// Prompt for selection of a solid to be traversed
prEntOpt = PromptEntityOptions('Select a 3D solid: ')
prEntOpt.SetRejectMessage('\nPlease select only a 3D Solid')
prEntOpt.AddAllowedClass(typeof(Solid3d), true)
prEntRes as PromptEntityResult = ed.GetEntity(prEntOpt)
//FullSubentityPath fullSubPath = new FullSubentityPath(objIds, SubentityId.Null);
//Brep brp = new Brep(fullSubPath);
sol = cast(Solid3d, tr.GetObject(prEntRes.ObjectId, OpenMode.ForRead))
// Build the BRep topology object that will be traversed.
brp = Brep(sol)
cmplxCount = 0
shllCount = 0
fceCount = 0
lpCount = 0
edgCount = 0
// Get all the Complexes which are primary BRep elements and represent a
// conceptual topological entity of connected shell boundaries.
for cmplx as Complex in brp.Complexes:
ed.WriteMessage('\n\nComplex Count: {0}', ++cmplxCount)
// Get all the shells within a complex. Shells are secondary BRep entities
// that corresponds to a collection of neighboring surfaces on a solid
for shll as Shell in cmplx.Shells:
ed.WriteMessage('\nShell Count: {0}', ++shllCount)
ed.WriteMessage('\nShell Type: {0}', shll.ShellType.ToString())
// Get all the faces in a shell. Faces are primary BRep topological entities that directly
// correspond to face subentities on AutoCAD entities like solid, region and body
for fce as Autodesk.AutoCAD.BoundaryRepresentation.Face in shll.Faces:
ed.WriteMessage('\nFace Count: {0}', ++fceCount)
// Get all the boundary loops within a face (Secondary BRep entities and no corresponding
// AutoCAD entities/subentities).
for lp as BoundaryLoop in fce.Loops:
ed.WriteMessage('\nLoop Count: {0}', ++lpCount)
ed.WriteMessage('\nLoop Type: {0}', lp.LoopType.ToString())
// Get all the Edges in a loop (Edges are primary BRep entities and correspond to
// Geometric entities).
for edg as Edge in lp.Edges:
ed.WriteMessage('\nEdge Count: {0}', ++edgCount)
crv = edg.Curve as ExternalCurve3d
if crv.IsCircularArc:
ed.WriteMessage('\nEdge Type: CircularArc')
ca = crv.NativeCurve as CircularArc3d
ed.WriteMessage('\nStartPnt : {0}', ca.StartPoint.ToString())
ed.WriteMessage('\nEndPnt : {0}', ca.EndPoint.ToString())
ed.WriteMessage('\nStartAngle: {0}', ca.StartAngle.ToString())
ed.WriteMessage('\nEndAngle : {0}', ca.EndAngle.ToString())
ed.WriteMessage('\nCentre : {0}', ca.Center.ToString())
ed.WriteMessage('\nRadius : {0}\n', ca.Radius.ToString())
ca.Dispose()
elif crv.IsEllipticalArc:
ed.WriteMessage('\nEdge Type: EllipticalArc')
ea = crv.NativeCurve as EllipticalArc3d
ed.WriteMessage('\nStartPnt : {0}', ea.StartPoint.ToString())
ed.WriteMessage('\nEndPnt : {0}', ea.EndPoint.ToString())
ed.WriteMessage('\nStartAngle: {0}', ea.StartAngle.ToString())
ed.WriteMessage('\nEndAngle : {0}', ea.EndAngle.ToString())
ed.WriteMessage('\nCentre : {0}', ea.Center.ToString())
ed.WriteMessage('\nMajRadius : {0}', ea.MajorRadius.ToString())
ed.WriteMessage('\nMinRadius : {0}\n', ea.MinorRadius.ToString())
ea.Dispose()
elif crv.IsLineSegment:
ed.WriteMessage('\nEdge Type: LineSegment')
l = crv.NativeCurve as LineSegment3d
ed.WriteMessage('\nEdge Vertex 1: {0}', l.StartPoint.ToString())
ed.WriteMessage('\nEdge Vertex 2: {0}\n', l.EndPoint.ToString())
l.Dispose()
elif crv.IsDefined == false:
ed.WriteMessage('\nUndifined Curve entity - no data!')
crv.Dispose()
tr.Commit()
except ex as System.Exception:
ed.WriteMessage('\nException: {0}', ex.Message)
ensure:
tr.Dispose()