.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Unload Xref?

19 REPLIES 19
Reply
Message 1 of 20
Techno Destructo
1322 Views, 19 Replies

Unload Xref?

How do you unload a Xref in C#.net
I can get the block def of the Xref, I just cant find where or how I unload if or reload it for that matter!
19 REPLIES 19
Message 2 of 20

Ok, heres what I figured out so far:

1. Get the Xrefs BlockTableRecord
2. set isunloaded = true

eg.
------------------------------------------------------------------------------------------
btr=(BlockTableRecord)trans.GetObject(bt[XrefName],OpenMode.ForWrite);
btr.IsUnloaded = true;

trans.Commit();
trans.Dispose();
------------------------------------------------------------------------------------------
I dont get any errors when I do this, so I think I am not closing out properly?
What am I missing?
Message 3 of 20

Ok, so I still havent figured this out but I have noticed that in the code I posted, if I run it then save the drawing, exit and reopen it. The Xref will be unloaded.
So I am missing something.
I thought the Trans.Commit(); updated the Block Table with the changes.
Could anybody give me some help?
I really doubt I am the first person who has tried this.
Message 4 of 20
Anonymous
in reply to: Techno Destructo

Setting a flag in a BlockTableRecord doesn't do anything other then set the
flag. The actual unloading must be done explicitly. I don't know if there
is any way to do this with .NET other then by executing an AutoCAD command
to unload the xref.

wrote in message news:5209902@discussion.autodesk.com...
Ok, so I still havent figured this out but I have noticed that in the code I
posted, if I run it then save the drawing, exit and reopen it. The Xref will
be unloaded.
So I am missing something.
I thought the Trans.Commit(); updated the Block Table with the changes.
Could anybody give me some help?
I really doubt I am the first person who has tried this.
Message 5 of 20
Anonymous
in reply to: Techno Destructo

What about this code?
[code]
using System;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;

[assembly: CommandClass(typeof(XrefLib.XrefClass))]

namespace XrefLib
{
public class XrefClass
{
// For AutoCAD 2006:
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi,
EntryPoint="?acedXrefUnload@@YA?AW4ErrorStatus@Acad@@PBD_NPAVAcDbDatabase@@@Z") ]
// For AutoCAD 2007:
// [DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode,
// EntryPoint="?acedXrefUnload@@YA?AW4ErrorStatus@Acad@@PB_W_NPAVAcDbDatabase@@@Z") ]
extern static int acedXrefUnload(string XrefBlockname, bool bQuiet, IntPtr db);

// For AutoCAD 2006:
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("acdb16.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
// For AutoCAD 2007:
// [System.Security.SuppressUnmanagedCodeSecurity]
// [DllImport("acdb17.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
extern static string acadErrorStatusText(int unnamed);

static private int XrefUnload(string XrefBlockname, bool bQuite, Database db)
{
return acedXrefUnload(XrefBlockname,bQuite,(db == null)?IntPtr.Zero:db.UnmanagedObject);
}

[CommandMethod("XUNLOAD")]
static public void XUnload()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptStringOptions pr = new PromptStringOptions("\nType XrefBlockName: "); pr.AllowSpaces = true;
PromptResult res = ed.GetString(pr);
if (res.Status == PromptStatus.OK)
{
if (XrefUnload(res.StringResult,true,HostApplicationServices.WorkingDatabase) !=0)
{
ed.WriteMessage("\nError in unloading xref <{0}>", res.StringResult);
}
}
}
}
}
[/code]
Message 6 of 20
Anonymous
in reply to: Techno Destructo

Yes calling acedXrefUnload() would do it.

When I responded, I was thinking within the context of the existing AutoCAD
.NET APIs only, not making your own wrapper for an unmanaged C++ function.

Nicely done. 🙂

wrote in message news:5210042@discussion.autodesk.com...
What about this code?
[code]
using System;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;

[assembly: CommandClass(typeof(XrefLib.XrefClass))]

namespace XrefLib
{
public class XrefClass
{
// For AutoCAD 2006:
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl,
CharSet = CharSet.Ansi,
EntryPoint="?acedXrefUnload@@YA?AW4ErrorStatus@Acad@@PBD_NPAVAcDbDatabase@@@Z")
]
// For AutoCAD 2007:
// [DllImport("acad.exe", CallingConvention =
CallingConvention.Cdecl, CharSet = CharSet.Unicode,
//
EntryPoint="?acedXrefUnload@@YA?AW4ErrorStatus@Acad@@PB_W_NPAVAcDbDatabase@@@Z")
]
extern static int acedXrefUnload(string XrefBlockname, bool bQuiet,
IntPtr db);

// For AutoCAD 2006:
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("acdb16.dll", CallingConvention = CallingConvention.Cdecl,
CharSet = CharSet.Ansi)]
// For AutoCAD 2007:
// [System.Security.SuppressUnmanagedCodeSecurity]
// [DllImport("acdb17.dll", CallingConvention =
CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
extern static string acadErrorStatusText(int unnamed);

static private int XrefUnload(string XrefBlockname, bool bQuite,
Database db)
{
return acedXrefUnload(XrefBlockname,bQuite,(db ==
null)?IntPtr.Zero:db.UnmanagedObject);
}

[CommandMethod("XUNLOAD")]
static public void XUnload()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptStringOptions pr = new PromptStringOptions("\nType
XrefBlockName: "); pr.AllowSpaces = true;
PromptResult res = ed.GetString(pr);
if (res.Status == PromptStatus.OK)
{
if
(XrefUnload(res.StringResult,true,HostApplicationServices.WorkingDatabase)
!=0)
{
ed.WriteMessage("\nError in unloading xref <{0}>",
res.StringResult);
}
}
}
}
}
[/code]
Message 7 of 20
Anonymous
in reply to: Techno Destructo

Thanks, Art! 🙂
Message 8 of 20

Thanks guys for the help.
Its a little over my head at the moment.
I wouldn't have thought something as simple as Unloading an Xref would have to be so complex.

I hope this is the only such case, but I fear its not.
Message 9 of 20
Anonymous
in reply to: Techno Destructo


Hi Guys, Searching 'xref' using the
'Object Browser' I found

'DetachXref'.

 

Did a test and this seems to work


db.DetachXref(blkDef.ObjectId);


 


gl-Paul


Yes calling acedXrefUnload()
would do it.

When I responded, I was thinking within the context of the
existing AutoCAD
.NET APIs only, not making your own wrapper for an
unmanaged C++ function.

Nicely done.  🙂

<Alexander
Rivilis> wrote in message

href="news:5210042@discussion.autodesk.com">
size=2>news:5210042@discussion.autodesk.com

size=2>...
What about this code?
[code]
using System;
using
System.Runtime.InteropServices;
using Autodesk.AutoCAD.Runtime;
using
Autodesk.AutoCAD.Geometry;
using
Autodesk.AutoCAD.ApplicationServices;
using
Autodesk.AutoCAD.DatabaseServices;
using
Autodesk.AutoCAD.EditorInput;

[assembly:
CommandClass(typeof(XrefLib.XrefClass))]

namespace XrefLib
{
 
public class XrefClass
  {
    // For AutoCAD
2006:
   
[System.Security.SuppressUnmanagedCodeSecurity]
   
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl,
CharSet
= CharSet.Ansi,
       EntryPoint="

href="mailto:?acedXrefUnload@@YA?AW4ErrorStatus@Acad@@PBD_NPAVAcDbDatabase@@@Z">
face=Arial
size=2...

face=Arial size=2>")
 ]
      // For
AutoCAD 2007:
      //   
[DllImport("acad.exe", CallingConvention =
CallingConvention.Cdecl, CharSet
= CharSet.Unicode,
      //

EntryPoint="

href="mailto:?acedXrefUnload@@YA?AW4ErrorStatus@Acad@@PB_W_NPAVAcDbDatabase@@@Z">
face=Arial
size=...

face=Arial size=2>")
 ]
    extern static int
acedXrefUnload(string XrefBlockname, bool bQuiet,
IntPtr
db);

    // For AutoCAD 2006:
   
[System.Security.SuppressUnmanagedCodeSecurity]
   
[DllImport("acdb16.dll", CallingConvention = CallingConvention.Cdecl,

CharSet = CharSet.Ansi)]
      // For AutoCAD
2007:
      //   
[System.Security.SuppressUnmanagedCodeSecurity]
     
//    [DllImport("acdb17.dll", CallingConvention =

CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
   
extern static string acadErrorStatusText(int unnamed);

   
static private int XrefUnload(string XrefBlockname, bool bQuite,
Database
db)
    {
      return
acedXrefUnload(XrefBlockname,bQuite,(db ==

null)?IntPtr.Zero:db.UnmanagedObject);
   
}

    [CommandMethod("XUNLOAD")]
   
static public void XUnload()
   
{
      Editor ed = 
Application.DocumentManager.MdiActiveDocument.Editor;
     
PromptStringOptions pr = new PromptStringOptions("\nType
XrefBlockName: ");
pr.AllowSpaces = true;
      PromptResult res =
ed.GetString(pr);
      if (res.Status ==
PromptStatus.OK)
     
{
        if

(XrefUnload(res.StringResult,true,HostApplicationServices.WorkingDatabase)

!=0)
       
{
         
ed.WriteMessage("\nError in unloading xref <{0}>",

res.StringResult);
       
}
      }
    }
 
}
}
[/code]
Message 10 of 20
Anonymous
in reply to: Techno Destructo


Detach and unload are two different things. 
Detach completely removes the xref from the drawing as though it had never been
attached.  Whereas, unload simply unloads the xref - sort of like if the
xref was not found when the drawing was opened.

 

I just checked the source and DetachXref() does
indeed do a detach, not an unload.  DetachXref() is a wrapper for the
ObjectARX function acdbDetachXref().

 

DetachXref() (and acdbDetachXref()) should not be
called on any xref that has any unerased BlockReferences referencing
it.

 

"Paul Richardson" <prichardsonATadelphia.net> wrote in message
href="news:5210102@discussion.autodesk.com">news:5210102@discussion.autodesk.com
...


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">

Hi Guys, Searching 'xref' using
the 'Object Browser' I found

'DetachXref'.

 

Did a test and this seems to work


db.DetachXref(blkDef.ObjectId);


 


gl-Paul


Yes calling acedXrefUnload()
would do it.

When I responded, I was thinking within the context of the
existing AutoCAD
.NET APIs only, not making your own wrapper for an
unmanaged C++ function.

Nicely done.  🙂

<Alexander
Rivilis> wrote in message

href="news:5210042@discussion.autodesk.com">
size=2>news:5210042@discussion.autodesk.com

size=2>...
What about this code?
[code]
using System;
using
System.Runtime.InteropServices;
using Autodesk.AutoCAD.Runtime;
using
Autodesk.AutoCAD.Geometry;
using
Autodesk.AutoCAD.ApplicationServices;
using
Autodesk.AutoCAD.DatabaseServices;
using
Autodesk.AutoCAD.EditorInput;

[assembly:
CommandClass(typeof(XrefLib.XrefClass))]

namespace
XrefLib
{
  public class XrefClass
 
{
    // For AutoCAD 2006:
   
[System.Security.SuppressUnmanagedCodeSecurity]
   
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl,

CharSet = CharSet.Ansi,
      
EntryPoint="

href="mailto:?acedXrefUnload@@YA?AW4ErrorStatus@Acad@@PBD_NPAVAcDbDatabase@@@Z">
face=Arial
...

face=Arial size=2>")
 ]
      // For
AutoCAD 2007:
      //   
[DllImport("acad.exe", CallingConvention =
CallingConvention.Cdecl,
CharSet = CharSet.Unicode,
      //

EntryPoint="

href="mailto:?acedXrefUnload@@YA?AW4ErrorStatus@Acad@@PB_W_NPAVAcDbDatabase@@@Z">
face=Arial
...

face=Arial size=2>")
 ]
    extern static int
acedXrefUnload(string XrefBlockname, bool bQuiet,
IntPtr
db);

    // For AutoCAD 2006:
   
[System.Security.SuppressUnmanagedCodeSecurity]
   
[DllImport("acdb16.dll", CallingConvention = CallingConvention.Cdecl,

CharSet = CharSet.Ansi)]
      // For AutoCAD
2007:
      //   
[System.Security.SuppressUnmanagedCodeSecurity]
     
//    [DllImport("acdb17.dll", CallingConvention =

CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
   
extern static string acadErrorStatusText(int
unnamed);

    static private int XrefUnload(string
XrefBlockname, bool bQuite,
Database db)
   
{
      return
acedXrefUnload(XrefBlockname,bQuite,(db ==

null)?IntPtr.Zero:db.UnmanagedObject);
   
}

    [CommandMethod("XUNLOAD")]
   
static public void XUnload()
   
{
      Editor ed = 
Application.DocumentManager.MdiActiveDocument.Editor;
     
PromptStringOptions pr = new PromptStringOptions("\nType
XrefBlockName:
"); pr.AllowSpaces = true;
      PromptResult res
= ed.GetString(pr);
      if (res.Status ==
PromptStatus.OK)
     
{
        if

(XrefUnload(res.StringResult,true,HostApplicationServices.WorkingDatabase)

!=0)
       
{
         
ed.WriteMessage("\nError in unloading xref <{0}>",

res.StringResult);
       
}
      }
    }
 
}
}
[/code]
Message 11 of 20
Anonymous
in reply to: Techno Destructo


Thanks Art!


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">


Detach and unload are two different things. 
Detach completely removes the xref from the drawing as though it had never
been attached.  Whereas, unload simply unloads the xref - sort of like if
the xref was not found when the drawing was opened.

 

I just checked the source and DetachXref() does
indeed do a detach, not an unload.  DetachXref() is a wrapper for the
ObjectARX function acdbDetachXref().

 

DetachXref() (and acdbDetachXref()) should not be
called on any xref that has any unerased BlockReferences referencing
it.

 

"Paul Richardson" <prichardsonATadelphia.net> wrote in message
href="news:5210102@discussion.autodesk.com">news:5210102@discussion.autodesk.com
...


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">

Hi Guys, Searching 'xref' using
the 'Object Browser' I found

'DetachXref'.

 

Did a test and this seems to work


db.DetachXref(blkDef.ObjectId);


 


gl-Paul


Yes calling
acedXrefUnload() would do it.

When I responded, I was thinking within
the context of the existing AutoCAD
.NET APIs only, not making your own
wrapper for an unmanaged C++ function.

Nicely done. 
🙂

<Alexander Rivilis> wrote in message

href="news:5210042@discussion.autodesk.com">
size=2>news:5210042@discussion.autodesk.com

size=2>...
What about this code?
[code]
using System;
using
System.Runtime.InteropServices;
using Autodesk.AutoCAD.Runtime;
using
Autodesk.AutoCAD.Geometry;
using
Autodesk.AutoCAD.ApplicationServices;
using
Autodesk.AutoCAD.DatabaseServices;
using
Autodesk.AutoCAD.EditorInput;

[assembly:
CommandClass(typeof(XrefLib.XrefClass))]

namespace
XrefLib
{
  public class XrefClass
 
{
    // For AutoCAD 2006:
   
[System.Security.SuppressUnmanagedCodeSecurity]
   
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl,

CharSet = CharSet.Ansi,
      
EntryPoint="

href="mailto:?acedXrefUnload@@YA?AW4ErrorStatus@Acad@@PBD_NPAVAcDbDatabase@@@Z">
face=Arial...

face=Arial size=2>")
 ]
      // For
AutoCAD 2007:
      //   
[DllImport("acad.exe", CallingConvention =
CallingConvention.Cdecl,
CharSet = CharSet.Unicode,
      //

EntryPoint="

href="mailto:?acedXrefUnload@@YA?AW4ErrorStatus@Acad@@PB_W_NPAVAcDbDatabase@@@Z">
face=Aria...

face=Arial size=2>")
 ]
    extern static int
acedXrefUnload(string XrefBlockname, bool bQuiet,
IntPtr
db);

    // For AutoCAD 2006:
   
[System.Security.SuppressUnmanagedCodeSecurity]
   
[DllImport("acdb16.dll", CallingConvention = CallingConvention.Cdecl,

CharSet = CharSet.Ansi)]
      // For
AutoCAD 2007:
      //   
[System.Security.SuppressUnmanagedCodeSecurity]
     
//    [DllImport("acdb17.dll", CallingConvention =

CallingConvention.Cdecl, CharSet =
CharSet.Unicode)]
    extern static string
acadErrorStatusText(int unnamed);

    static private
int XrefUnload(string XrefBlockname, bool bQuite,
Database
db)
    {
      return
acedXrefUnload(XrefBlockname,bQuite,(db ==

null)?IntPtr.Zero:db.UnmanagedObject);
   
}

    [CommandMethod("XUNLOAD")]
   
static public void XUnload()
   
{
      Editor ed = 
Application.DocumentManager.MdiActiveDocument.Editor;
     
PromptStringOptions pr = new PromptStringOptions("\nType
XrefBlockName:
"); pr.AllowSpaces = true;
      PromptResult
res = ed.GetString(pr);
      if (res.Status ==
PromptStatus.OK)
     
{
        if

(XrefUnload(res.StringResult,true,HostApplicationServices.WorkingDatabase)

!=0)
       
{
         
ed.WriteMessage("\nError in unloading xref <{0}>",

res.StringResult);
       
}
      }
    }
 
}
}
[/code]
Message 12 of 20
Anonymous
in reply to: Techno Destructo

It is updated more universal code:
[code]
using System;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;

[assembly: CommandClass(typeof(XrefLib.XrefClass))]

namespace XrefLib
{
class Wrapper
{
static int version = Autodesk.AutoCAD.ApplicationServices.Application.Version.Major;
// For AutoCAD 2006:
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi,
EntryPoint = "?acedXrefUnload@@YA?AW4ErrorStatus@Acad@@PBD_NPAVAcDbDatabase@@@Z")]
extern public static ErrorStatus acedXrefUnload16(string XrefBlockname, bool bQuiet, IntPtr db);
// For AutoCAD 2007:
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode,
EntryPoint = "?acedXrefUnload@@YA?AW4ErrorStatus@Acad@@PB_W_NPAVAcDbDatabase@@@Z")]
extern public static ErrorStatus acedXrefUnload17(string XrefBlockname, bool bQuiet, IntPtr db);

// For AutoCAD 2006:
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi,
EntryPoint = "?acedXrefReload@@YA?AW4ErrorStatus@Acad@@PBD_NPAVAcDbDatabase@@@Z")]
extern public static ErrorStatus acedXrefReload16(string XrefBlockname, bool bQuiet, IntPtr db);
// For AutoCAD 2007:
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode,
EntryPoint = "?acedXrefReload@@YA?AW4ErrorStatus@Acad@@PB_W_NPAVAcDbDatabase@@@Z")]
extern public static ErrorStatus acedXrefReload17(string XrefBlockname, bool bQuiet, IntPtr db);

// For AutoCAD 2006:
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi,
EntryPoint = "?acedXrefBind@@YA?AW4ErrorStatus@Acad@@PBD_N1PAVAcDbDatabase@@@Z")]
extern public static ErrorStatus acedXrefBind16(string XrefBlockname, bool bInsertBind, bool bQuiet, IntPtr db);
// For AutoCAD 2007:
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode,
EntryPoint = "?acedXrefBind@@YA?AW4ErrorStatus@Acad@@PB_W_N1PAVAcDbDatabase@@@Z")]

extern public static ErrorStatus acedXrefBind17(string XrefBlockname, bool bInsertBind, bool bQuiet, IntPtr db);

static public ErrorStatus acedXrefUnload(string XrefBlockname, bool bQuite, Database db)
{
switch (version)
{
case 16: return acedXrefUnload16(XrefBlockname, bQuite, (db == null) ? IntPtr.Zero : db.UnmanagedObject);
case 17: return acedXrefUnload17(XrefBlockname, bQuite, (db == null) ? IntPtr.Zero : db.UnmanagedObject);
}
return ErrorStatus.NotImplementedYet;
}

static public ErrorStatus acedXrefReload(string XrefBlockname, bool bQuite, Database db)
{
switch (version)
{
case 16: return acedXrefReload16(XrefBlockname, bQuite, (db == null) ? IntPtr.Zero : db.UnmanagedObject);
case 17: return acedXrefReload17(XrefBlockname, bQuite, (db == null) ? IntPtr.Zero : db.UnmanagedObject);
}
return ErrorStatus.NotImplementedYet;
}

static public ErrorStatus acedXrefBind(string XrefBlockname, bool bInsertBind, bool bQuite, Database db)
{
switch (version)
{
case 16: return acedXrefBind16(XrefBlockname, bInsertBind, bQuite, (db == null) ? IntPtr.Zero : db.UnmanagedObject);
case 17: return acedXrefBind17(XrefBlockname, bInsertBind, bQuite, (db == null) ? IntPtr.Zero : db.UnmanagedObject);
}
return ErrorStatus.NotImplementedYet;
}
}

public class XrefClass
{
[CommandMethod("X_UNLOAD")]
static public void XUnload()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptStringOptions pr = new PromptStringOptions("\nType XrefBlockName: "); pr.AllowSpaces = true;
PromptResult res = ed.GetString(pr);
if (res.Status == PromptStatus.OK)
{
ErrorStatus es = Wrapper.acedXrefUnload(res.StringResult, true, HostApplicationServices.WorkingDatabase);
if (es != ErrorStatus.OK)
{
ed.WriteMessage("\nError in unloading xref <{0}>: {1}", res.StringResult, es);
}
}
}
[CommandMethod("X_RELOAD")]
static public void XReload()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptStringOptions pr = new PromptStringOptions("\nType XrefBlockName: "); pr.AllowSpaces = true;
PromptResult res = ed.GetString(pr);
if (res.Status == PromptStatus.OK)
{
ErrorStatus es = Wrapper.acedXrefReload(res.StringResult, true, HostApplicationServices.WorkingDatabase);
if (es != ErrorStatus.OK)
{
ed.WriteMessage("\nError in reloading xref <{0}>: {1}", res.StringResult, es);
}
}
}
[CommandMethod("X_BIND")]
static public void XBind()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptStringOptions pr = new PromptStringOptions("\nType XrefBlockName: "); pr.AllowSpaces = true;
PromptResult res = ed.GetString(pr);
if (res.Status == PromptStatus.OK)
{
ErrorStatus es = Wrapper.acedXrefBind(res.StringResult, false, true, HostApplicationServices.WorkingDatabase);
if (es != ErrorStatus.OK)
{
ed.WriteMessage("\nError in binding xref <{0}>: {1}", res.StringResult, es);
}
}
}
}
}
[/code]

It is interesting that sometime ErrorStatus has wrong value. For example, while unloading nonexisting in this drawing xref name. Who can explain me what is wrong? In native ObjectARX equivalent I get eNotImplementedYet for this situation. In .NET I get different values, such as number 156168256.
Message 13 of 20
Anonymous
in reply to: Techno Destructo

Nice, Thanks for posting...

wrote in message news:5210152@discussion.autodesk.com...
It is updated more universal code:
[code]
using System;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;

[assembly: CommandClass(typeof(XrefLib.XrefClass))]

namespace XrefLib
{
class Wrapper
{
static int version =
Autodesk.AutoCAD.ApplicationServices.Application.Version.Major;
// For AutoCAD 2006:
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl,
CharSet = CharSet.Ansi,
EntryPoint =
"?acedXrefUnload@@YA?AW4ErrorStatus@Acad@@PBD_NPAVAcDbDatabase@@@Z")]
extern public static ErrorStatus acedXrefUnload16(string XrefBlockname,
bool bQuiet, IntPtr db);
// For AutoCAD 2007:
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl,
CharSet = CharSet.Unicode,
EntryPoint =
"?acedXrefUnload@@YA?AW4ErrorStatus@Acad@@PB_W_NPAVAcDbDatabase@@@Z")]
extern public static ErrorStatus acedXrefUnload17(string XrefBlockname,
bool bQuiet, IntPtr db);

// For AutoCAD 2006:
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl,
CharSet = CharSet.Ansi,
EntryPoint =
"?acedXrefReload@@YA?AW4ErrorStatus@Acad@@PBD_NPAVAcDbDatabase@@@Z")]
extern public static ErrorStatus acedXrefReload16(string XrefBlockname,
bool bQuiet, IntPtr db);
// For AutoCAD 2007:
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl,
CharSet = CharSet.Unicode,
EntryPoint =
"?acedXrefReload@@YA?AW4ErrorStatus@Acad@@PB_W_NPAVAcDbDatabase@@@Z")]
extern public static ErrorStatus acedXrefReload17(string XrefBlockname,
bool bQuiet, IntPtr db);

// For AutoCAD 2006:
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl,
CharSet = CharSet.Ansi,
EntryPoint =
"?acedXrefBind@@YA?AW4ErrorStatus@Acad@@PBD_N1PAVAcDbDatabase@@@Z")]
extern public static ErrorStatus acedXrefBind16(string XrefBlockname,
bool bInsertBind, bool bQuiet, IntPtr db);
// For AutoCAD 2007:
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl,
CharSet = CharSet.Unicode,
EntryPoint =
"?acedXrefBind@@YA?AW4ErrorStatus@Acad@@PB_W_N1PAVAcDbDatabase@@@Z")]

extern public static ErrorStatus acedXrefBind17(string XrefBlockname,
bool bInsertBind, bool bQuiet, IntPtr db);

static public ErrorStatus acedXrefUnload(string XrefBlockname, bool
bQuite, Database db)
{
switch (version)
{
case 16: return acedXrefUnload16(XrefBlockname, bQuite, (db == null)
? IntPtr.Zero : db.UnmanagedObject);
case 17: return acedXrefUnload17(XrefBlockname, bQuite, (db == null)
? IntPtr.Zero : db.UnmanagedObject);
}
return ErrorStatus.NotImplementedYet;
}

static public ErrorStatus acedXrefReload(string XrefBlockname, bool
bQuite, Database db)
{
switch (version)
{
case 16: return acedXrefReload16(XrefBlockname, bQuite, (db == null)
? IntPtr.Zero : db.UnmanagedObject);
case 17: return acedXrefReload17(XrefBlockname, bQuite, (db == null)
? IntPtr.Zero : db.UnmanagedObject);
}
return ErrorStatus.NotImplementedYet;
}

static public ErrorStatus acedXrefBind(string XrefBlockname, bool
bInsertBind, bool bQuite, Database db)
{
switch (version)
{
case 16: return acedXrefBind16(XrefBlockname, bInsertBind, bQuite,
(db == null) ? IntPtr.Zero : db.UnmanagedObject);
case 17: return acedXrefBind17(XrefBlockname, bInsertBind, bQuite,
(db == null) ? IntPtr.Zero : db.UnmanagedObject);
}
return ErrorStatus.NotImplementedYet;
}
}

public class XrefClass
{
[CommandMethod("X_UNLOAD")]
static public void XUnload()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptStringOptions pr = new PromptStringOptions("\nType
XrefBlockName: "); pr.AllowSpaces = true;
PromptResult res = ed.GetString(pr);
if (res.Status == PromptStatus.OK)
{
ErrorStatus es = Wrapper.acedXrefUnload(res.StringResult, true,
HostApplicationServices.WorkingDatabase);
if (es != ErrorStatus.OK)
{
ed.WriteMessage("\nError in unloading xref <{0}>: {1}",
res.StringResult, es);
}
}
}
[CommandMethod("X_RELOAD")]
static public void XReload()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptStringOptions pr = new PromptStringOptions("\nType
XrefBlockName: "); pr.AllowSpaces = true;
PromptResult res = ed.GetString(pr);
if (res.Status == PromptStatus.OK)
{
ErrorStatus es = Wrapper.acedXrefReload(res.StringResult, true,
HostApplicationServices.WorkingDatabase);
if (es != ErrorStatus.OK)
{
ed.WriteMessage("\nError in reloading xref <{0}>: {1}",
res.StringResult, es);
}
}
}
[CommandMethod("X_BIND")]
static public void XBind()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptStringOptions pr = new PromptStringOptions("\nType
XrefBlockName: "); pr.AllowSpaces = true;
PromptResult res = ed.GetString(pr);
if (res.Status == PromptStatus.OK)
{
ErrorStatus es = Wrapper.acedXrefBind(res.StringResult, false, true,
HostApplicationServices.WorkingDatabase);
if (es != ErrorStatus.OK)
{
ed.WriteMessage("\nError in binding xref <{0}>: {1}",
res.StringResult, es);
}
}
}
}
}
[/code]

It is interesting that sometime ErrorStatus has wrong value. For example,
while unloading nonexisting in this drawing xref name. Who can explain me
what is wrong? In native ObjectARX equivalent I get
eNotImplementedYet for this situation. In .NET I get different
values, such as number 156168256.
Message 14 of 20
Anonymous
in reply to: Techno Destructo

🙂 And what you think about wrong value of ErrorStatus?
Message 15 of 20
smcclure
in reply to: Techno Destructo

I think the problem is in the code below (and the other definitions for the other ACAD versions):

[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi,
EntryPoint = "?acedXrefUnload@@YA?AW4ErrorStatus@Acad@@PBD_NPAVAcDbDatabase@@@Z")]
extern public static ErrorStatus acedXrefUnload16(string XrefBlockname, bool bQuiet, IntPtr db);

I think the function should not return an ErrorStatus object, which I believe is a .NET managed class, but an integer. My suspicion is that the crazy values you are getting are due to some casting issues since they are not even near within the valid range of error code integer values.

Hope that fixes it...
- Scott
Message 16 of 20
Anonymous
in reply to: Techno Destructo

Thanks, Scott!
But before posting that question I try with such return value:
int, uint, short, ushort. But without success. It is very strange, that under debugger (with Unmanaged debugging) I get value ErrorStatus.NullObjectId
In ObjectARX I stable get eNotImplementedYet.
Message 17 of 20

The Wrapper provided has worked great for 2006 and 2007.
Can anyone update it so that it works with 2008?
Wrappers are way above my skill level.
Message 18 of 20
Anonymous
in reply to: Techno Destructo

You can download "Depends.exe" to find the exported name. See pic.

wrote in message news:5566275@discussion.autodesk.com...
The Wrapper provided has worked great for 2006 and 2007.
Can anyone update it so that it works with 2008?
Wrappers are way above my skill level.
Message 19 of 20

Thanks for that tip!
I will give it a try.
I always wondered how to get the name.
Message 20 of 20
Anonymous
in reply to: Techno Destructo

Hi, Techno Destructo!
As I think that my code must work in AutoCAD 2008 without any changes because of binary compatibly between ObjectARX 2007 and 2008

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost