Take a look to this code from forums.autodesk.com
Code:
using System;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.ApplicationServices;
using System.Reflection;
using System.IO;
using System.Collections;
using System.Runtime.InteropServices;
using System.Diagnostics;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.GraphicsInterface;
//using Autodesk.Aec.DatabaseServices;
namespace mvblockJig
{
public class JigExample : DrawJig
{
private Point3d previousCurserPosition;
private Point3d currentCurserPosition;
private Entity entityToDrag;
//private Autodesk.Aec.DatabaseServices.Entity entityToDrag;
private Database db = Application.DocumentManager.MdiActiveDocument.Database;
private Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
int mPromptCounter;
string sampstatus;
double rotationadj;
string jiginput;
string jigmsg;
[CommandMethod("placeMvBlock")]
public void StartJig()
{
// test block 113D_362336_MV
string blockname;
rotationadj = 0;
mPromptCounter = 0;
blockname = ed.GetString("Input Block Name").StringResult;
Autodesk.Aec.DatabaseServices.DictionaryMultiViewBlockDefinition mvbstyledict;
ObjectId bstyleID;
Autodesk.Aec.DatabaseServices.MultiViewBlockReference mvb;
mvb = new Autodesk.Aec.DatabaseServices.MultiViewBlockReference();
Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
mvbstyledict = new Autodesk.Aec.DatabaseServices.DictionaryMultiViewBlockDefinition(db);
bstyleID = mvbstyledict.GetAt(blockname);
mvb.BlockDefId = bstyleID;
entityToDrag = mvb;
previousCurserPosition = new Point3d(0, 0, 0);
sampstatus = "NoChange";
while (sampstatus == "NoChange")
{
Application.DocumentManager.MdiActiveDocument.Editor.Drag(this); //SamplerStatus then World draw runs from here
mvb.Rotation = rotationadj;
}
mPromptCounter = 1;
if (sampstatus == "OK")
{
using (Transaction myT = tm.StartTransaction())
{
BlockTable bt = (BlockTable)tm.GetObject(db.BlockTableId, OpenMode.ForRead, false);
BlockTableRecord btr = (BlockTableRecord)tm.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);
btr.AppendEntity(mvb);
tm.AddNewlyCreatedDBObject(mvb, true);
myT.Commit();
}
}
}
protected override SamplerStatus Sampler(JigPrompts prompts)
{
JigPromptPointOptions jigOpts = new JigPromptPointOptions();
jigOpts.UserInputControls = (UserInputControls.Accept3dCoordinates | UserInputControls.AcceptOtherInputString);
if (mPromptCounter == 0)
{
jigOpts.Message = "\nInsert point or ";
jigOpts.Keywords.Add("NAme", "NAme", "NAme", true, true);
jigOpts.Keywords.Add("Xscale", "Xscale", "Xscale", true, true);
jigOpts.Keywords.Add("Yscale", "Yscale", "Yscale", true, true);
jigOpts.Keywords.Add("Zscale", "Zscale", "Zscale", true, true);
jigOpts.Keywords.Add("Rotation", "Rotation", "Rotation", true, true);
jigOpts.Keywords.Add("Match", "Match", "Match", true, true);
jigOpts.Keywords.Add("Base", "Base", "Base", true, true);
PromptPointResult dres = prompts.AcquirePoint(jigOpts);
currentCurserPosition = dres.Value;
if (dres.Status == PromptStatus.Cancel)
{
sampstatus = "Cancel";
return SamplerStatus.Cancel;
}
if (currentCurserPosition != previousCurserPosition)
{
sampstatus = "OK";
return SamplerStatus.OK;
}
if (dres.StringResult != null)
{
// Here put switch case for keywords.
jigmsg = dres.StringResult;
switch (jigmsg)
{
case "NAme":
ed.WriteMessage("\nNAme");
sampstatus = "NoChange";
return SamplerStatus.NoChange;
case "Xscale":
ed.WriteMessage("\nXscale");
sampstatus = "NoChange";
return SamplerStatus.NoChange;
case "Yscale":
ed.WriteMessage("\nYscale");
sampstatus = "NoChange";
return SamplerStatus.NoChange;
case "Zscale":
ed.WriteMessage("\nZscale");
sampstatus = "NoChange";
return SamplerStatus.NoChange;
case "Rotation":
// Convert rad to degree rotationadj = (jigdbl * 3.14159265358979) / 180;
sampstatus = "NoChange";
mPromptCounter = 1;
return SamplerStatus.NoChange;
case "Match":
ed.WriteMessage("\nMatch");
sampstatus = "NoChange";
return SamplerStatus.NoChange;
case "Base":
ed.WriteMessage("\nBase");
sampstatus = "NoChange";
return SamplerStatus.NoChange;
default:
sampstatus = "NoChange";
return SamplerStatus.NoChange;
}
}
sampstatus = "NoChange";
return SamplerStatus.NoChange;
}
else if (mPromptCounter == 1)
{
jigOpts.UserInputControls = (UserInputControls.Accept3dCoordinates | UserInputControls.AcceptOtherInputString);
jigOpts.Keywords.Clear();
jigOpts.Message = "\nRotation: ";
PromptPointResult rres = prompts.AcquirePoint(jigOpts);
currentCurserPosition = rres.Value;
if (rres.StringResult != null)
{
jiginput = rres.StringResult.ToString();
mPromptCounter = 0;
sampstatus = "NoChange";
return SamplerStatus.NoChange;
}
if (rres.Status == PromptStatus.Error)
{
sampstatus = "Error";
return SamplerStatus.NoChange;
}
if (rres.Status == PromptStatus.Cancel)
{
sampstatus = "Cancel";
return SamplerStatus.Cancel;
}
if (rres.Status == PromptStatus.Keyword)
{
sampstatus = "Keyword";
return SamplerStatus.NoChange;
}
if (rres.Status == PromptStatus.Modeless)
{
sampstatus = "Modeless";
return SamplerStatus.NoChange;
}
if (rres.Status == PromptStatus.None)
{
sampstatus = "None";
return SamplerStatus.NoChange;
}
if (rres.Status == PromptStatus.Other)
{
sampstatus = "Other";
return SamplerStatus.NoChange;
}
sampstatus = "NoChange";
return SamplerStatus.NoChange;
}
else
{
sampstatus = "NoChange";
return SamplerStatus.NoChange;
}
}
protected override bool WorldDraw(WorldDraw draw)
{
if (mPromptCounter == 1)
{
Vector3d displacementVector = previousCurserPosition.GetVectorTo(currentCurserPosition);
entityToDrag.TransformBy(Matrix3d.Displacement(displacementVector));
previousCurserPosition = currentCurserPosition;
draw.Geometry.Draw(entityToDrag);
}
else
{
Vector3d displacementVector = previousCurserPosition.GetVectorTo(currentCurserPosition);
entityToDrag.TransformBy(Matrix3d.Displacement(displacementVector));
previousCurserPosition = currentCurserPosition;
draw.Geometry.Draw(entityToDrag);
}
return true;
}
}
}
It really works.