using System;
using System.Collections.Generic;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using AcBr = Autodesk.AutoCAD.BoundaryRepresentation;
[assembly: CommandClass(typeof(Rivilis.SolidOffset))]
namespace Rivilis
{
public class SolidOffset
{
[CommandMethod("Sol3dOffset")]
public void MyCommand()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
if (doc == null) return;
Editor ed = doc.Editor;
PromptEntityOptions prEnOpt =
new PromptEntityOptions("\nВыберите 3DSOLID: ");
prEnOpt.SetRejectMessage("Это не 3DSOLID!");
prEnOpt.AddAllowedClass(typeof(Solid3d), true);
PromptEntityResult rsEn = ed.GetEntity(prEnOpt);
if (rsEn.Status != PromptStatus.OK) return;
PromptDistanceOptions prDistOpt =
new PromptDistanceOptions("\nУкажите величину смещения: ");
prDistOpt.DefaultValue = 0;
prDistOpt.UseDefaultValue = true;
PromptDoubleResult rsOff = ed.GetDistance(prDistOpt);
if (rsEn.Status != PromptStatus.OK && rsEn.Status != PromptStatus.None) return;
double offset = rsOff.Value;
ObjectId idSol3d = rsEn.ObjectId;
using (Solid3d sol3d = idSol3d.Open(OpenMode.ForWrite) as Solid3d)
{
ObjectId[] ids = new ObjectId[] { sol3d.ObjectId };
SubentityId subentId = new SubentityId(SubentityType.Null, IntPtr.Zero);
FullSubentityPath path = new FullSubentityPath(ids, subentId);
List<SubentityId> subids = new List<SubentityId>();
using (AcBr.Brep brep = new AcBr.Brep(path)) {
foreach (AcBr.Face face in brep.Faces) {
subids.Add(face.SubentityPath.SubentId);
}
}
sol3d.OffsetFaces(subids.ToArray(), offset);
}
}
[CommandMethod("Sol3dOffset1")]
public void MyCommand1()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
if (doc == null) return;
Editor ed = doc.Editor;
PromptEntityOptions prEnOpt =
new PromptEntityOptions("\nВыберите 3DSOLID: ");
prEnOpt.SetRejectMessage("Это не 3DSOLID!");
prEnOpt.AddAllowedClass(typeof(Solid3d), true);
PromptEntityResult rsEn = ed.GetEntity(prEnOpt);
if (rsEn.Status != PromptStatus.OK) return;
PromptDistanceOptions prDistOpt =
new PromptDistanceOptions("\nУкажите величину смещения: ");
prDistOpt.DefaultValue = 0;
prDistOpt.UseDefaultValue = true;
PromptDoubleResult rsOff = ed.GetDistance(prDistOpt);
if (rsEn.Status != PromptStatus.OK && rsEn.Status != PromptStatus.None) return;
double offset = rsOff.Value;
ObjectId idSol3d = rsEn.ObjectId;
using (Solid3d sol3d = idSol3d.Open(OpenMode.ForWrite) as Solid3d)
{
sol3d.OffsetBody(offset);
}
}
}
}