Hello,
I am quite new to the .NET api, so a lot of things arent clear to me and i can't find what am i doing wrong.
In short: I am traversing a 3dsolid with the BREP api, i am checking for the faces' normals and once i get to the face i am looking for, i want to "convert" it to a region. I can't seem to find a straightforward way of creating a region entity from the face's geometry.
Through a lot of reading i found out that there is quite a difference between the Geometry and DatabaseServices entities. There is not much information about creating a DBEntity from a Geometry entity.
I tried to "convert" the face's edges to DBCurves using:
Curve3d curve = edge.Curve;
Curve dbCurve = Curve.CreateFromGeCurve(curve);
The idea was to "convert" all of the face's edges to DBCurves then add all of them to a DBObjectCollection, and at the end use Region.CreateFromCurves(dbCurves). Unfortunately, this gives me a NotImplementedYet error on the CreateFromGeCurve method.
I am not sure exactly what is wrong. Either my approach is totally wrong, or my lack of knowledge of the .NET api is holding me back.
Is it possible to add DBEntities from Geometry entities, what are the best practices.. I have a lot of questions and i will be very grateful if you can guide me to some documentation and/or tutorials to read about the .NET api, because the ObjectARX documentation isn't as detailed as i would have hoped.
Thank you in advance
Solved! Go to Solution.
Solved by _gile. Go to Solution.
Hi,
You can use the Solid3.CopyFace() method with the SubEntityId of the face.
[CommandMethod("TEST")] public static void Test() { var doc = Application.DocumentManager.MdiActiveDocument; var db = doc.Database; var ed = doc.Editor; var options = new PromptEntityOptions("\nSelect solid 3d: "); options.SetRejectMessage("\nInvalid selection."); options.AddAllowedClass(typeof(Solid3d), false); var result = ed.GetEntity(options); if (result.Status != PromptStatus.OK) return; using (var tr = db.TransactionManager.StartTransaction()) { var solid = (Solid3d)tr.GetObject(result.ObjectId, OpenMode.ForWrite); var subentId = GetFaceSubentId(solid, Vector3d.XAxis); if (subentId != SubentityId.Null) { var entity = solid.CopyFace(subentId); entity.ColorIndex = 1; var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); curSpace.AppendEntity(entity); tr.AddNewlyCreatedDBObject(entity, true); } tr.Commit(); } } static SubentityId GetFaceSubentId(Solid3d solid, Vector3d direction) { SubentityId subEntId = SubentityId.Null; var entityPath = new FullSubentityPath( new ObjectId[] { solid.ObjectId }, new SubentityId(SubentityType.Null, IntPtr.Zero)); using (var brep = new Brep(entityPath)) { foreach (var face in brep.Faces) { var geomNurb = face.GetSurfaceAsNurb(); var weights = new DoubleCollection(); try { weights = geomNurb.Weights; } catch { } using (var dbNurb = new Autodesk.AutoCAD.DatabaseServices.NurbSurface( geomNurb.DegreeInU, geomNurb.DegreeInV, geomNurb.IsRationalInU && geomNurb.IsRationalInV, geomNurb.NumControlPointsInU, geomNurb.NumControlPointsInV, geomNurb.ControlPoints, weights, geomNurb.UKnots, geomNurb.VKnots)) { if (dbNurb.IsPlanar(out Point3d point, out Vector3d normal) && normal.IsCodirectionalTo(direction)) { subEntId = face.SubentityPath.SubentId; break; } } } } return subEntId; }
@doaiena wrote:
On another note, can you recommend sources from where to learn more about the .NET api. I'm having a hard time, finding a more in depth learning resource.
The ObjectARX: Managed .NET Reference Guide on this page is a quite good starting resource. you can also find some more undocumented APIs using Visual Studio Object Explorer or a .NET decompiler like IlSpy.
Can't find what you're looking for? Ask the community or share your knowledge.