This will get you started
static public void MakeBlockFromSS()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Transaction tr = db.TransactionManager.StartTransaction();
Editor ed = doc.Editor;
using (tr)
{
try
{
SelectionFilter sf = new SelectionFilter(
new TypedValue[] { new TypedValue(0, "LINE,ARC") }
);
PromptSelectionOptions pso = new PromptSelectionOptions();
pso.MessageForAdding = "\nSelect arc and lines >>";
PromptSelectionResult res = ed.GetSelection(pso, sf);
if (res.Status != PromptStatus.OK)
return;
SelectionSet main = res.Value;
if (main.Count==0)
return;
ObjectIdCollection oids = new ObjectIdCollection(main.GetObjectIds());
ObjectId idx = AddHatch(oids, "ANSI37", 20.0, 0.0);
if (idx == ObjectId.Null)
{
ed.WriteMessage("\nProblem with creating boundary\ncheck gaps between objects\nProgram exiting");
return;
}
oids.Add(idx);
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
PromptStringOptions psto = new PromptStringOptions( "\nEnter new block name: " );
psto.AllowSpaces = true;
string blkname = "";
do
{
PromptResult pr = ed.GetString(psto);
if (pr.Status != PromptStatus.OK)
return;
try
{
SymbolUtilityServices.ValidateSymbolName( pr.StringResult, false );
if (bt.Has(pr.StringResult))
ed.WriteMessage( "\nA layer with this name already exists." );
else
blkname = pr.StringResult;
}
catch
{
ed.WriteMessage( "\nInvalid block name." );
}
} while (blkname == "");
BlockTableRecord btr = new BlockTableRecord();
PromptPointOptions ppo = new PromptPointOptions("\nPick Insertion Point >>");
ppo.UseBasePoint = false;
PromptPointResult pres;
pres = ed.GetPoint(ppo);
if (pres.Status != PromptStatus.OK)
return;
btr.Origin = pres.Value;
btr.Name = blkname;
btr.Units = UnitsValue.Millimeters;
btr.Annotative = AnnotativeStates.True;
bt.UpgradeOpen();
ObjectId ltId = bt.Add(btr);
bt.DowngradeOpen();
tr.AddNewlyCreatedDBObject(btr, true);
btr.AssumeOwnershipOf(oids);
tr.Commit();
}
catch (System.Exception ex)
{
ed.WriteMessage("\n" + ex.Message + "\n" + ex.StackTrace);
return;
}
}
}
static public ObjectId AddHatch(ObjectIdCollection ids, string pattern, double scale, double angle)
{
ObjectId idx =ObjectId.Null;
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
Transaction tr = db.TransactionManager.StartTransaction();
using (tr)
{
try
{
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
Hatch hatch = new Hatch();
btr.AppendEntity(hatch);
tr.AddNewlyCreatedDBObject(hatch, true);
hatch.SetDatabaseDefaults();
hatch.SetHatchPattern(HatchPatternType.PreDefined, pattern);
hatch.PatternScale = scale;
hatch.PatternAngle = Math.PI * angle / 180.0;
hatch.Associative = true;
hatch.Annotative = AnnotativeStates.True;
hatch.AppendLoop(HatchLoopTypes.Outermost, ids);
hatch.EvaluateHatch(true);
idx = hatch.ObjectId;
tr.Commit();
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
ed.WriteMessage(ex.Message);
idx = ObjectId.Null;
}
}
return idx;
}
Change to your suit
~'J'~
_____________________________________
C6309D9E0751D165D0934D0621DFF27919