Message 1 of 11
Unable to cast COM object of type 'System.__ComObject' to class type 'Autodesk.AutoCAD.DatabaseServices.BlockReference'. Instances of types that represent COM components cannot be cast to types that d
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying use the Entity zig for rotation but I am getting error
Entity zig code:
namespace palet.Jig
{
public sealed class mod__BlockRotating : EntityJig
{
#region Fields
public int mCurJigFactorNumber = 1;
private double mRotation = 0.0; // Factor #1
#endregion
#region Constructors
public mod__BlockRotating(Entity ent)
: base(ent)
{
}
#endregion
#region Overrides
protected override bool Update()
{
switch (mCurJigFactorNumber)
{
case 1:
(Entity as BlockReference).Rotation = mRotation;
break;
default:
return false;
}
return true;
}
protected override SamplerStatus Sampler(JigPrompts prompts)
{
switch (mCurJigFactorNumber)
{
case 1:
JigPromptAngleOptions prOptions1 = new JigPromptAngleOptions("\nBlock rotation angle:");
prOptions1.BasePoint = (Entity as BlockReference).Position;
prOptions1.UseBasePoint = true;
prOptions1.Cursor = CursorType.RubberBand;
PromptDoubleResult prResult1 = prompts.AcquireAngle(prOptions1);
if (prResult1.Status == PromptStatus.Cancel) return SamplerStatus.Cancel;
if (prResult1.Value.Equals(mRotation))
{
return SamplerStatus.NoChange;
}
else
{
mRotation = prResult1.Value;
return SamplerStatus.OK;
}
default:
break;
}
return SamplerStatus.OK;
}
#endregion
#region Method to Call
public static bool Jig(BlockReference ent)
{
try
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
mod__BlockRotating jigger = new mod__BlockRotating(ent);
PromptResult pr;
do
{
pr = ed.Drag(jigger);
jigger.mCurJigFactorNumber++;
} while (pr.Status != PromptStatus.Cancel &&
pr.Status != PromptStatus.Error &&
pr.Status != PromptStatus.Keyword &&
jigger.mCurJigFactorNumber <= 1);
return pr.Status == PromptStatus.OK;
}
catch
{
return false;
}
}
#endregion
}
}
Error That I am getting when I use the function to call jig
System.InvalidCastException: 'Unable to cast COM object of type 'System.__ComObject' to class type 'Autodesk.AutoCAD.DatabaseServices.BlockReference'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.'
Then I realized that I am using
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;
AcadBlock a_BlkObj = default(AcadBlock);
AcadBlockReference a_BlockRefObj1 = default(AcadBlockReference);
AcadBlockReference a_BlockRefObj2 = default(AcadBlockReference);
mod__BlockRotating.Jig((Autodesk.AutoCAD.DatabaseServices.BlockReference)a_BlockRefObj1);
Then I realized that I am using Autodesk.AutoCAD.Interop.Common to add the Block.. due to which its throwing error.
Now I have ported most of my code to Autodesk.AutoCAD.Interop.Common and I want to use the Entity jig to rotate some of by blocks.
Is there any resolution for this?