
To Create something similar as above, I have quickly written the code, there code be some redundancies.
[CommandMethod("TCY")]
public static void createTCY()
{
// Get the current document and database, and start a transaction
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
// Open the Block table record for read
BlockTable acBlkTbl;
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
OpenMode.ForRead) as BlockTable;
// Open the Block table record Model space for write
BlockTableRecord acBlkTblRec;
acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
OpenMode.ForWrite) as BlockTableRecord;
// Create a 3D solid Inclined
using (Solid3d acSol3D = new Solid3d())
{
//Switch UCS
Matrix3d curUCSMatrix = acDoc.Editor.CurrentUserCoordinateSystem;
CoordinateSystem3d curUCS = curUCSMatrix.CoordinateSystem3d;
CoordinateSystem3d newUCS = new CoordinateSystem3d(new Point3d(10, 10, 10), curUCS.Xaxis, curUCS.Zaxis);
Matrix3d newUCSMatrix = Matrix3d.AlignCoordinateSystem(curUCS.Origin, curUCS.Xaxis, curUCS.Yaxis, curUCS.Zaxis, newUCS.Origin, newUCS.Xaxis, newUCS.Yaxis, newUCS.Zaxis);
acDoc.Editor.CurrentUserCoordinateSystem = newUCSMatrix;
using (Line l = new Line())
{
l.StartPoint = new Point3d(10, 10, 10);
l.EndPoint = new Point3d(120.0, -30.0, 120.0);
acDoc.Editor.CurrentUserCoordinateSystem = curUCSMatrix;
// Create an in memory circle
using (Circle acCirc = new Circle())
{
acCirc.Center = new Point3d(10.0, 10.0, 0);
acCirc.Radius = 60;
// Adds the circle to an object array
DBObjectCollection acDBObjColl = new DBObjectCollection();
acDBObjColl.Add(acCirc);
// Calculate the regions based on each closed loop
DBObjectCollection myRegionColl = new DBObjectCollection();
myRegionColl = Region.CreateFromCurves(acDBObjColl);
Region acRegion = myRegionColl[0] as Region;
// Add the new object to the block table record and the transaction
ObjectId regionId = acBlkTblRec.AppendEntity(acRegion);
acTrans.AddNewlyCreatedDBObject(acRegion, true);
acRegion = acTrans.GetObject(regionId, OpenMode.ForRead) as Region;
//Solid creation by curve
acSol3D.ExtrudeAlongPath(acRegion, l, 0.0);
// Add the new object to the block table record and the transaction
acBlkTblRec.AppendEntity(acSol3D);
acTrans.AddNewlyCreatedDBObject(acSol3D, true);
} // Dispose of the in memory circle not appended to the database
}
}
// Save the new objects to the database
acTrans.Commit();
}
}