Hi,
Entity.JoinEntities method does not work this way. It have to be called on one instance of entity and requires as argument an array of entities.
Here's an example:
[CommandMethod("TESTJOIN")]
public static void TestJoin()
{
var doc = Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
// Prompt the user to select the primary spline
var entityOptions = new PromptEntityOptions("\nSelect primary spline: ");
entityOptions.SetRejectMessage("\nMust be a spline.");
entityOptions.AddAllowedClass(typeof(Spline), true);
var entityResult = ed.GetEntity(entityOptions);
if (entityResult.Status != PromptStatus.OK)
return;
// Prompt the user to select the spline to join to the first one.
var filter = new SelectionFilter(new[]
{
new TypedValue(0, "SPLINE"),
new TypedValue(-4, "<NOT"),
new TypedValue(-4, "&"),
new TypedValue(70, 1),
new TypedValue(-4, "NOT>")
});
var selectionOptions = new PromptSelectionOptions();
selectionOptions.MessageForAdding = "\nSelect the spline to join: ":
var selection = ed.GetSelection(filter);
if (selection.Status != PromptStatus.OK)
return;
using (var tr = db.TransactionManager.StartTransaction())
{
// Open the first spline
var spline = (Spline)tr.GetObject(entityResult.ObjectId, OpenMode.ForWrite);
// Create an array with the other splines
var otherSplines = selection.Value
.GetObjectIds()
.Select(id => (Spline)tr.GetObject(id, OpenMode.ForWrite))
.ToArray();
try
{
// Join the selected splines to primary one
var indices = spline.JoinEntities(otherSplines);
// Erase the joined plines
foreach (int index in indices)
{
otherSplines[index].Erase();
}
}
catch(Autodesk.AutoCAD.Runtime.Exception ex) when (ex.ErrorStatus == ErrorStatus.NotApplicable)
{
ed.WriteMessage("\nThe first spline does not join to any selected ones");
}
catch(System.Exception ex)
{
ed.WriteMessage($"\n{ex.Message}");
}
tr.Commit();
}
}