.NET

Reply
Active Contributor
Posts: 47
Registered: ‎04-05-2006
Message 1 of 20 (335 Views)

Unload Xref?

335 Views, 19 Replies
06-14-2006 06:08 PM
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!
Active Contributor
Posts: 47
Registered: ‎04-05-2006
Message 2 of 20 (335 Views)

Re: Unload Xref?

06-15-2006 02:49 AM in reply to: Techno Destructo
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?
Active Contributor
Posts: 47
Registered: ‎04-05-2006
Message 3 of 20 (335 Views)

Re: Unload Xref?

06-17-2006 01:59 AM in reply to: Techno Destructo
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.
*Art Cooney
Message 4 of 20 (335 Views)

Re: Unload Xref?

06-17-2006 10:23 AM 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.
Distinguished Contributor
Posts: 303
Registered: ‎09-26-2004
Message 5 of 20 (335 Views)

Re: Unload Xref?

06-17-2006 02:11 PM 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]
*Art Cooney
Message 6 of 20 (335 Views)

Re: Unload Xref?

06-17-2006 03:28 PM 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. :smileyhappy:

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

Re: Unload Xref?

06-17-2006 03:37 PM in reply to: Techno Destructo
Thanks, Art! :smileyhappy:
Active Contributor
Posts: 47
Registered: ‎04-05-2006
Message 8 of 20 (335 Views)

Re: Unload Xref?

06-17-2006 04:49 PM in reply to: Techno Destructo
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.
*Paul Richardson
Message 9 of 20 (335 Views)

Re: Unload Xref?

06-17-2006 05:38 PM 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.  :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
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]
*Art Cooney
Message 10 of 20 (335 Views)

Re: Unload Xref?

06-17-2006 09:34 PM 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.  :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=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]

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you interested in helping shape the Autodesk Community?
We’re looking at a few different ways to improve the “All Forums” landing page and need your feedback! If interested, please take a few minutes to fill out the following Usability Study. Thank you for your time!

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community