2024-09-01 13:10:19 +02:00
|
|
|
|
#if ACAD24
|
|
|
|
|
using Autodesk.AutoCAD.Runtime;
|
|
|
|
|
using Autodesk.AutoCAD.EditorInput;
|
|
|
|
|
using Autodesk.AutoCAD.Geometry;
|
|
|
|
|
using Autodesk.AutoCAD.DatabaseServices;
|
|
|
|
|
using Autodesk.AutoCAD.Colors;
|
|
|
|
|
using AcAp = Autodesk.AutoCAD.ApplicationServices;
|
|
|
|
|
#elif BCAD
|
|
|
|
|
using Teigha.Runtime;
|
|
|
|
|
using Bricscad.EditorInput;
|
|
|
|
|
using Teigha.Geometry;
|
|
|
|
|
using Teigha.DatabaseServices;
|
|
|
|
|
using Teigha.Colors;
|
2024-09-01 13:27:00 +02:00
|
|
|
|
using AcAp = Bricscad.ApplicationServices;
|
2024-09-01 13:10:19 +02:00
|
|
|
|
#endif
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Boprs;
|
|
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
|
[assembly: CommandClass(typeof(Commands))]
|
|
|
|
|
namespace Boprs
|
|
|
|
|
{
|
|
|
|
|
internal class Commands
|
|
|
|
|
{
|
|
|
|
|
private Region UserCreateRegion(string msg)
|
|
|
|
|
{
|
|
|
|
|
AcAp.Document acDoc = AcAp.Application.DocumentManager.MdiActiveDocument;
|
|
|
|
|
Database acDb = acDoc.Database;
|
|
|
|
|
|
|
|
|
|
acDoc.Editor.WriteMessage("\n" + msg);
|
|
|
|
|
|
|
|
|
|
PromptSelectionResult res = acDoc.Editor.GetSelection();
|
|
|
|
|
|
|
|
|
|
if (res.Status != PromptStatus.OK || res.Value.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<LineSegment2d> segs = new List<LineSegment2d>();
|
|
|
|
|
|
|
|
|
|
using (Transaction acTrans = acDb.TransactionManager.StartTransaction())
|
|
|
|
|
{
|
|
|
|
|
foreach (ObjectId asObjId in res.Value.GetObjectIds())
|
|
|
|
|
{
|
|
|
|
|
Polyline asPoly = (Polyline)acTrans.GetObject(asObjId, OpenMode.ForWrite);
|
|
|
|
|
|
|
|
|
|
using (DBObjectCollection exploded = new DBObjectCollection())
|
|
|
|
|
{
|
|
|
|
|
asPoly.Explode(exploded);
|
|
|
|
|
|
|
|
|
|
foreach(DBObject dBObject in exploded)
|
|
|
|
|
{
|
|
|
|
|
Line asLine = (Line)dBObject;
|
|
|
|
|
segs.Add(new LineSegment2d(asLine.StartPoint.To2d(), asLine.EndPoint.To2d()));
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-09-04 09:04:07 +02:00
|
|
|
|
|
|
|
|
|
asPoly.Erase();
|
2024-09-01 13:10:19 +02:00
|
|
|
|
}
|
|
|
|
|
acTrans.Commit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Region.FromSegments(segs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private BoprType UserChooseBoprType()
|
|
|
|
|
{
|
|
|
|
|
AcAp.Document acDoc = AcAp.Application.DocumentManager.MdiActiveDocument;
|
|
|
|
|
|
|
|
|
|
PromptKeywordOptions keyPrompt = new PromptKeywordOptions("\nBoolean operation type: ");
|
|
|
|
|
keyPrompt.Keywords.Add("Unite");
|
|
|
|
|
keyPrompt.Keywords.Add("Intersect");
|
|
|
|
|
keyPrompt.Keywords.Add("Subtract");
|
|
|
|
|
keyPrompt.Keywords.Add("eXclusive");
|
|
|
|
|
keyPrompt.AllowNone = false;
|
|
|
|
|
|
|
|
|
|
PromptResult keywRes = acDoc.Editor.GetKeywords(keyPrompt);
|
|
|
|
|
|
|
|
|
|
switch (keywRes.StringResult.ToLower())
|
|
|
|
|
{
|
|
|
|
|
case "unite":
|
|
|
|
|
return BoprType.UNITE;
|
|
|
|
|
case "intersect":
|
|
|
|
|
return BoprType.INTERSECT;
|
|
|
|
|
case "subtract":
|
|
|
|
|
return BoprType.SUBTRACT;
|
|
|
|
|
case "exclusive":
|
|
|
|
|
return BoprType.EXCLUSIVE;
|
|
|
|
|
default:
|
|
|
|
|
return BoprType.INTERSECT;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[CommandMethod("boprtest")]
|
|
|
|
|
public void Subdivide()
|
|
|
|
|
{
|
|
|
|
|
AcAp.Document acDoc = AcAp.Application.DocumentManager.MdiActiveDocument;
|
|
|
|
|
|
|
|
|
|
Region subject = UserCreateRegion("Enter polylines for first polygon:");
|
2024-09-02 10:08:52 +02:00
|
|
|
|
|
2024-09-01 13:10:19 +02:00
|
|
|
|
Region clip = UserCreateRegion("Enter polylines for second polygon:");
|
|
|
|
|
|
|
|
|
|
if(subject == null || clip == null)
|
|
|
|
|
{
|
|
|
|
|
acDoc.Editor.WriteMessage("\nOne of the polyline selections was empty.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BoprType type = UserChooseBoprType();
|
2024-09-02 10:08:52 +02:00
|
|
|
|
|
2024-09-01 13:10:19 +02:00
|
|
|
|
BooleanOperation bopr = new BooleanOperation(subject, clip, type);
|
|
|
|
|
|
2024-09-04 14:36:34 +02:00
|
|
|
|
List <Contour> contours = bopr.Result.GetContourCopies();
|
|
|
|
|
|
|
|
|
|
foreach (Contour contour in contours)
|
|
|
|
|
{
|
|
|
|
|
contour.Draw();
|
|
|
|
|
}
|
2024-09-21 23:13:05 +02:00
|
|
|
|
|
|
|
|
|
acDoc.Editor.WriteMessage($"\nResult area: {bopr.Result.Area}");
|
2024-09-01 13:10:19 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|