Well I have something working thanks to your suggestions.
In my DragJig.cs class
using System;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.GraphicsInterface;
[assembly: CommandClass(typeof(ClassLibrary.DragByID))]
namespace ClassLibrary
{
/// <summary>
/// Summary description for WestClass.
/// </summary>
public class DragByID
{
[ComVisible(true)]
public long myObjectID;
public double x;
public double y;
public double z;
private Point3d m_basePoint;
public DragByID()
{
// constructor
x = 0;
y = 0;
z = 0;
}
public bool DragIt()
{
Editor currentEditor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
m_basePoint = new Point3d(x, y, z);
ObjectId[] OIDs;
OIDs = new ObjectId[1];
OIDs[0]=(new ObjectId((int)myObjectID));
SelectionSet ssEnt = SelectionSet.FromObjectIds(OIDs);
//Initiate the drag callback delegate
DragCallback dragCallbackDelegate = this.FollowCursor;
//Start the drag operation
PromptDragOptions dragOptions = new PromptDragOptions(ssEnt, "\nSelect point: ", dragCallbackDelegate);
PromptPointResult destinationPointResult = currentEditor.Drag(dragOptions);
if (destinationPointResult.Status != PromptStatus.OK)
{
return false;
}
//Determine the final displacement matrix
Matrix3d transMat = Matrix3d.Displacement(m_basePoint.GetVectorTo(destinationPointResult.Value));
//transform the ss to the new location
this.TransformSelectionSet(ssEnt, transMat);
return true;
}
//DragCallback Delegate
public SamplerStatus FollowCursor(Point3d currentPoint, ref Matrix3d transMat)
{
transMat = Matrix3d.Displacement(m_basePoint.GetVectorTo(currentPoint));
return SamplerStatus.OK;
}
private void TransformSelectionSet(SelectionSet ss, Matrix3d transMat)
{
if (ss.Count == 0)
{
return;
}
Database targetDatabase = ss[0].ObjectId.Database;
Autodesk.AutoCAD.ApplicationServices.DocumentLock lockDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
using (Transaction trans = targetDatabase.TransactionManager.StartTransaction())
{
BlockTableRecord currentSpace = (BlockTableRecord)trans.GetObject(targetDatabase.CurrentSpaceId, OpenMode.ForWrite);
foreach (SelectedObject selectedObj in ss)
{
Entity selectedEntity = (Entity)trans.GetObject(selectedObj.ObjectId, OpenMode.ForRead);
Entity transformedEntity = selectedEntity.GetTransformedCopy(transMat);
currentSpace.AppendEntity(transformedEntity);
trans.AddNewlyCreatedDBObject(transformedEntity, true);
}
trans.Commit();
}
lockDoc.Dispose();
}
}
}
In my vba code module (for testing)
Public Sub TestBlockInsert()
Dim BlockRef As AcadBlockReference
Dim sBlockPath As String
Dim iP(2) As Double
iP(0) = 0: iP(1) = 0: iP(2) = 0
sBlockPath = "C:\TestBlock.dwg"
Set BlockRef = ThisDrawing.ModelSpace.InsertBlock(iP, sBlockPath, 1, 1, 1, 0)
BlockRef.Update
Call PlaceInsertBlock(BlockRef)
End Sub
Public Sub PlaceInsertBlock(oBRef As AcadBlockReference)
On Error GoTo Err_Handler
Dim Success As Boolean
Dim onet As Dragger.DragByID
Set onet = New Dragger.DragByID
onet.myObjectID = oBRef.ObjectID
onet.X = oBRef.insertionPoint(0)
onet.y = oBRef.insertionPoint(1)
onet.z = oBRef.insertionPoint(2)
Success = onet.DragIt
If ThisDrawing.GetVariable("LASTPROMPT") = ": *Cancel*" Then
oBRef.Delete
End If
Exit_Here:
If Not onet Is Nothing Then Set onet = Nothing
Exit Sub
Err_Handler:
InputBox "NETTest" & vbCrLf & Err.Description, Err.Source, Err.Number
Err.Clear
Resume Exit_Here
End Sub
That's a start. Now for rotate and scale.