Danijel,
I've tried to pInvoke acdbEntUpd()
but have hit a wall. I'm obviously doing something wrong ...
[assembly: CommandClass(typeof(KdubTesting.TestCommands))]
namespace KdubTesting
{
// CodeHimBelongaKdub Jun 2008
public partial class Kdub_API
{
//==================================================================================
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl)]
public static extern int acdbEntUpd(long adsName);
/*
* If acdbEntUpd() succeeds, it returns RTNORM ( 5100 )
* otherwise, it returns RTERROR.(-5001 )
* When acdbEntUpd() fails, it sets the system variable ERRNO to a value
* that indicates the reason for the failure.
*/
//==================================================================================
[DllImport("acdb18.dll", CallingConvention = CallingConvention.Cdecl,
EntryPoint = "?acdbGetAdsName@@YA?AW4ErrorStatus@Acad@@AAY01JVAcDbObjectId@@@Z")]
public extern static ErrorStatus acdbGetAdsName(out long objName, ObjectId objId );
/*
* Acad::ErrorStatus acdbGetAdsName(
* ads_name& objName,
* AcDbObjectId obj
* );
* This function fills in objName with the ads_name that corresponds to the objId object ID.
* Returns Acad::eOk if successful.
* If objId is 0, then Acad::eNullObjectId is returned.
*/
//==================================================================================
}
// CodeHimBelongaKdub Jun 2008
public partial class TestCommands
{
[CommandMethod("EntUpd")]
static public void TestacdbEntUpd()
{
Document doc = AcadApp.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
PromptEntityResult res = ed.GetEntity("\nSelect an entity to Regen:");
ObjectId id = res.ObjectId;
long adsName;
ErrorStatus es;
AcadApp.SetSystemVariable("ERRNO", 0);
using(Transaction tr = db.TransactionManager.StartTransaction())
{
es = Kdub_API.acdbGetAdsName(out adsName, id);
ed.WriteMessage("\n adsName is {0} ", adsName);
ed.WriteMessage("\n ErrorStatus is {0} ", es);
int apiReturn = Kdub_API.acdbEntUpd(adsName);
ed.WriteMessage("\n api acdbEntUpd_Return is {0} ", apiReturn);
ed.WriteMessage("\n System variable ERRNO is {0} ", AcadApp.GetSystemVariable("ERRNO"));
tr.Commit();
}
ed.WriteMessage("\n Complete: System variable ERRNO is {0} ", AcadApp.GetSystemVariable("ERRNO"));
}
}
}
This is the result I'm getting :
Command: errno
Enter new value for ERRNO <0>:
Command: entupd
Select an entity to Regen:
adsName is 9158139860942894088
ErrorStatus is OK
api acdbEntUpd_Return is -5001
System variable ERRNO is 5
Complete: System variable ERRNO is 5
Command: errno
Enter new value for ERRNO <2>:
The acdbEntUpd generates an ERRNO of 5
When the routine returns to AutoCAD, the ERRNO command from the commandLine reports 2.
The 'Scrambled' name for acdbGetAdsName is the same in acdb17.dll 32bit and acdb18.dll 32bit ... so my DllImports should be suitable for AC 2007-AC2011 ( once I get the bug sorted. )
// Called Kerry or kdub in my other life.
Everything will work just as you expect it to, unless your expectations are incorrect. ~ kdub
Sometimes the question is more important than the answer. ~ kdub
NZST UTC+12 : class keyThumper<T> : Lazy<T>; another Swamper