BrFace SubEntityPath Error

Getting an error while using BrFace SubentityPath

Steps:
  1. I have created simple cube from CreateBox API (Solid3d)
Solid3d acSol3D1 = CreateBox(20, 0, acCurDb, acTrans);
  1. getting Brep and BrFace from that Solid3d
Brep brp = new Brep(acSol3D1);
BrFace face = brp.Faces.ElementAt(5);
  1. Now I need SubEntityPath from face
var v = face.SubentityPath;
I am getting error here..
Please suggest if I am doing anything wrong here.

Comments

  • First, the object must first be stored in the drawing in order to get the ObjectId. Only then can the paths to the subobjects be obtained.
    Secondly, to get bRep, you should use the full path to the solid and not the solid itself, otherwise the paths to the subobjects will not be available.

    ///
    /// Get Brep on FullSubentityPath. It will be possible to extract SubentityPath from all faces
    /// The solid must be saved in the dwg. Otherwise, it will issue a regular Brep without SubentityPath
    ///
    public static Brep
    GetBrep(this Solid3d solid)
    {
    if (solid is null || solid.IsNull || solid.IsErased) return null;
    try
    {
    if (solid.ObjectId.IsNull) return new Brep(solid);
    ObjectId[] ids = new ObjectId[] { solid.ObjectId };
    SubentityId subentId = new(SubentityType.Null, IntPtr.Zero);
    return new Brep(new FullSubentityPath(ids, subentId));
    }
    catch (Rt.Exception) { return null; }
    }
  • Thanks! @avc
    it worked!!
    Is there any way to get face from blockreference (block instance on model space).
    TIA.