.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

how make new block referecnce select items

1 REPLY 1
Reply
Message 1 of 2
Anonymous
216 Views, 1 Reply

how make new block referecnce select items

Hi,
any body please help me on selected items to make new block refence as a given name.
1 REPLY 1
Message 2 of 2
_gile
in reply to: Anonymous

Hi,

Here's a quick and dirty snippet

{code}[CommandMethod("Test")]
public void Test()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptSelectionResult psr = ed.GetSelection();
if (psr.Status == PromptStatus.OK)
{
PromptPointResult ppr = ed.GetPoint("\nInsertion point: ");
if (ppr.Status == PromptStatus.OK)
{
Point3d insPt = ppr.Value.TransformBy(ed.CurrentUserCoordinateSystem);
Point3d origin = new Point3d(0.0, 0.0, 0.0);
Vector3d disp = insPt.GetVectorTo(origin);
using (Transaction tr = db.TransactionManager.StartTransaction())
{
ObjectId[] ss = psr.Value.GetObjectIds();
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForWrite);
string bName = String.Empty;
do
{
PromptResult pr = ed.GetString("\nBlock name: ");
if (pr.Status == PromptStatus.OK)
bName = pr.StringResult;
} while (bt.Has(bName));
if (bName != String.Empty)
{
BlockTableRecord btr = new BlockTableRecord();
btr.Name = bName;
bt.Add(btr);
tr.AddNewlyCreatedDBObject(btr, true);
foreach (ObjectId id in ss)
{
Entity ent = (Entity)tr.GetObject(id, OpenMode.ForWrite);
Entity copy = (Entity)ent.Clone();
btr.AppendEntity(copy);
tr.AddNewlyCreatedDBObject(copy, true);
copy.TransformBy(Matrix3d.Displacement(disp));
ent.Erase();
}
BlockReference blk = new BlockReference(insPt, btr.ObjectId);
btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
btr.AppendEntity(blk);
tr.AddNewlyCreatedDBObject(blk, true);
}
tr.Commit();
}
}
}
}{code}


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost