.NET

Reply
*Paul Richardson
Message 11 of 20 (152 Views)

Re: Unload Xref?

06-18-2006 04:49 AM 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. 
:smileyhappy:

<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]
Distinguished Contributor
Alexander Rivilis
Posts: 303
Registered: ‎09-26-2004
Message 12 of 20 (152 Views)

Re: Unload Xref?

06-18-2006 06:10 AM 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.
*Paul Richardson
Message 13 of 20 (152 Views)

Re: Unload Xref?

06-18-2006 06:45 AM 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.
Distinguished Contributor
Alexander Rivilis
Posts: 303
Registered: ‎09-26-2004
Message 14 of 20 (152 Views)

Re: Unload Xref?

06-18-2006 06:50 AM in reply to: Techno Destructo
:smileyhappy: And what you think about wrong value of ErrorStatus?
Valued Contributor
smcclure
Posts: 60
Registered: ‎06-08-2006
Message 15 of 20 (152 Views)

Re: Unload Xref?

06-23-2006 07:48 AM 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
Distinguished Contributor
Alexander Rivilis
Posts: 303
Registered: ‎09-26-2004
Message 16 of 20 (152 Views)

Re: Unload Xref?

06-23-2006 09:59 AM 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.
Active Contributor
Techno Destructo
Posts: 47
Registered: ‎04-05-2006
Message 17 of 20 (152 Views)

Re: Unload Xref?

04-26-2007 04:49 PM in reply to: Techno Destructo
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.
*Paul Richardson
Message 18 of 20 (152 Views)

Re: Unload Xref?

04-27-2007 05:51 AM 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.
Active Contributor
Techno Destructo
Posts: 47
Registered: ‎04-05-2006
Message 19 of 20 (152 Views)

Re: Unload Xref?

04-27-2007 08:44 PM in reply to: Techno Destructo
Thanks for that tip!
I will give it a try.
I always wondered how to get the name.
Distinguished Contributor
Alexander Rivilis
Posts: 303
Registered: ‎09-26-2004
Message 20 of 20 (152 Views)

Re: Unload Xref?

04-29-2007 01:54 PM 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
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.