Welcome!
I concur with my estimable colleague and would also add the following:
http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=1911627
http://help.autodesk.com/view/ACD/2017/FRA/?guid=GUID-BA686431-C8BF-49F2-946E-9CEB2F7AE4FA
https://www.theswamp.org/index.php?topic=32381.0
Reading between the lines, I"m afraid there are no easy short cuts:
Here is the code which shows you how to create and insert block references:
http://docs.autodesk.com/ACD/2014/ENU/index.html?url=files/GUID-2656E245-6EAA-41A3-ABE9-742868182821...
This will give you some ideas:
- You'd want to determine the geometric extents of your existing block reference and then you'd want to test if the extents of the newblock will still fit in the drawing and then decide whether to insert it or not. (That's how I'd approach the problem).
The following code will give you some ideas of how to insert block references:
WARNING: UNTESTED:
namespace PracticePlugins
{
// This class is instantiated by AutoCAD for each document when
// a command is called by the user the first time in the context
// of a given document. In other words, non static data in this class
// is implicitly per-document!
public class MyCommands
{
// The CommandMethod attribute can be applied to any public member
// function of any public class.
// The function should take no arguments and return nothing.
// If the method is an intance member then the enclosing class is
// intantiated for each document. If the member is a static member then
// the enclosing class is NOT intantiated.
//
// NOTE: CommandMethod has overloads where you can provide helpid and
// context menu.
// Modal Command with localized name
[CommandMethod("InsertBlockReference")]
public static void DisplayLayerNames3()
{
Point3d blockReferencePosition = InsertBlockReferenceHelpers.GetPoint("\n Please choose insertion point for block reference");
// obviously you'll add in the name of the block in place of the "string" below:
InsertBlockReferenceHelpers.InsertBlockReference("NameOfBlock", blockReferencePosition);
}
}
public static class InsertBlockReferenceHelpers
{
static public void InsertBlockReference(string blockName, Point3d insertionPoint)
{
Database db = Application.DocumentManager.MdiActiveDocument.Database;
Document doc = Application.DocumentManager.MdiActiveDocument;
using (DocumentLock docLock = doc.LockDocument())
{
using (Transaction myT = db.TransactionManager.StartTransaction())
{
//Get the block definition "Check".
BlockTable bt =
db.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable;
BlockTableRecord blockDef =
bt[blockName].GetObject(OpenMode.ForRead) as BlockTableRecord;
//Also open modelspace - we'll be adding our BlockReference to it
BlockTableRecord ms =
bt[BlockTableRecord.ModelSpace].GetObject(OpenMode.ForWrite)
as BlockTableRecord;
//Create new BlockReference, and link it to our block definition
using (BlockReference blockRef =
new BlockReference(insertionPoint, blockDef.ObjectId))
{
//Add the block reference to modelspace
ms.AppendEntity(blockRef);
myT.AddNewlyCreatedDBObject(blockRef, true);
//Iterate block definition to find all non-constant
// AttributeDefinitions
foreach (ObjectId id in blockDef)
{
DBObject obj = id.GetObject(OpenMode.ForRead);
AttributeDefinition attDef = obj as AttributeDefinition;
if ((attDef != null) && (!attDef.Constant))
{
//This is a non-constant AttributeDefinition
//Create a new AttributeReference
using (AttributeReference attRef = new AttributeReference())
{
attRef.SetAttributeFromBlock(attDef, blockRef.BlockTransform);
// not setting the attribute value to anything.
//Add the AttributeReference to the BlockReference
blockRef.AttributeCollection.AppendAttribute(attRef);
myT.AddNewlyCreatedDBObject(attRef, true);
}
}
}
}
//Our work here is done
myT.Commit();
}
}
}
public static Point3d GetPoint(string userInstructions)
{
// asks the user to select a point
// throws an exception if he cancels
// repeats till he gets it right
// check if point is (0,0,0)
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
PromptPointResult pPtRes = null;
PromptPointOptions pPtOpts = new PromptPointOptions("");
Point3d ptStart;
// Prompt for the start point
pPtOpts.Message = userInstructions;
pPtRes = doc.Editor.GetPoint(pPtOpts);
if (pPtRes.Status == PromptStatus.OK)
{
ptStart = pPtRes.Value;
}
else
{
throw new Autodesk.AutoCAD.Runtime.Exception(Autodesk.AutoCAD.Runtime.ErrorStatus.UserBreak, "Looks like there was an error when asked to click a point");
}
return ptStart;
}
}
}
good luck and i hope it helps.
rgds
Ben