Message 1 of 4
EXPLODE command by C#

Not applicable
09-29-2020
03:44 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a below code that i have wrote based on the copy command ho i performed.
Please find the below code, Its working until the "getSelection" After that this code it not running.
Could anyone have a good suggestion for this would be appreciated. Please correct me where i am getting wrong.
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using System;
namespace AutoCAD_Libruary
{
public class Class1
{
[CommandMethod("XPLD", CommandFlags.UsePickSet)]
public void Commands()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction transXPLODE = db.TransactionManager.StartTransaction())
{
try
{
BlockTable btXPLODE;
btXPLODE = transXPLODE.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord btrXPLODE;
btrXPLODE = transXPLODE.GetObject(btXPLODE[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
object tileMode = Application.GetSystemVariable("TILEMODE");
if (System.Convert.ToInt16(tileMode) == 0)
{
Application.SetSystemVariable("TILEMODE", 1);
}
PromptSelectionResult psrXplode = ed.GetSelection(); /*SelectWindow(new Point3d(113000, 13000, 0), new Point3d(100000, -500, 0));*/
if (psrXplode.Status == PromptStatus.OK)
{
SelectionSet ssXplode = psrXplode.Value;
foreach (SelectedObject sObjXplode in ssXplode)
{
if (sObjXplode != null)
{
DBObjectCollection dbOBJcolXplode = new DBObjectCollection();
if (dbOBJcolXplode != null)
{
foreach (Entity entXplode1 in dbOBJcolXplode)
{
Entity entXplode = transXPLODE.GetObject(sObjXplode.ObjectId, OpenMode.ForRead) as Entity;
entXplode.Explode(dbOBJcolXplode);
if (entXplode != null)
{
foreach (DBObject objDB in dbOBJcolXplode)
{
Entity entXplodeAdd = objDB as Entity;
btrXPLODE.AppendEntity(entXplodeAdd);
transXPLODE.AddNewlyCreatedDBObject(entXplodeAdd, true);
}
}
}
}
}
}
}
}
catch (System.Exception ex)
{
ed.WriteMessage("Error" + ex.Message);
transXPLODE.Abort();
}
transXPLODE.Commit();
}
}
}
}