Is there an equivalent to ThisDrawing.PurgeAll in VB.NET?

Is there an equivalent to ThisDrawing.PurgeAll in VB.NET?

Anonymous
Not applicable
4,085 Views
6 Replies
Message 1 of 7

Is there an equivalent to ThisDrawing.PurgeAll in VB.NET?

Anonymous
Not applicable

Hi,

 

I'm making some progress in my transition from VBA to VB.NET.  Is there a VB.NET equivalent to VBA's ThisDrawing.PurgeAll?  Or do I need to follow what they are doing here:

http://forums.autodesk.com/t5/NET/Purge-Linetypes/m-p/2899312/highlight/true#M22478

 

And look for each type of named object (blocks, dim styles, layers, etc...) separately?  I understand that I will also have to iterate until I purge all nested objects.

 

Thanks,

Constantine

0 Likes
4,086 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable

You can use PurgeAll from Autodesk.Autocad.Interop the same as in VBA.

How to find Autodesk.Autocad.Interop? Look at: http://through-the-interface.typepad.com/through_the_interface/2007/02/using_the_com_i.html and http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer%27s%20Guide/files/WS73099cc142f4875...

Other solution (without Interop) you can find here: http://www.theswamp.org/index.php?topic=25880.0

0 Likes
Message 3 of 7

Anonymous
Not applicable

Hi Alexander,

 

Thanks for the links.  I had tried using the COM version (Autodesk.Autocad.Interop) but it did nothing. I got no error, the statement appeared to run (I placed msgbox statements before and after to make sure that part of the code ran), but nothing was purged.

 

I will take a closer at "theswamp" link.  I think that is what I was looking for.

 

Thanks,

Constantine

0 Likes
Message 4 of 7

Anonymous
Not applicable

 

using System;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using AcRx = Autodesk.AutoCAD.Runtime;
using AcEd = Autodesk.AutoCAD.EditorInput;
using AcDb = Autodesk.AutoCAD.DatabaseServices;
using AcAp = Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;

[assembly: CommandClass(typeof(Rivilis.TestMyPurge))]

namespace Rivilis
{
  class TestMyPurge {
    [CommandMethod("MyPurgeAll")]
    static public void MyPurgeAll()
    {
      AcadDocument doc = AcAp.Application.DocumentManager.MdiActiveDocument.AcadDocument as AcadDocument;
      if (doc != null) {
        doc.PurgeAll();
      }
    }
  }
}

 Try this sample. Quick testing in AutoCAD 2008 show that this method working as expected.

 

0 Likes
Message 5 of 7

Anonymous
Not applicable

Hi Alexander,

 

I copied and pasted into a new C# project and have some difficulties.  I've never used C# before and don't know how to add references to the AutoCAD dll files and to compile to .NET 3.5.

 

I took a first pass at converting your code to VB.NET, but I'm not very experienced with that version either.  It does not like the line:

If doc <> vbNull Then

 

Here is my converted code:

 

Imports System
Imports System.Runtime.InteropServices
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common

Public Class Class1

    <Autodesk.AutoCAD.Runtime.CommandMethod("runMyPurge", CommandFlags.Session)> _
    Public Sub MyPurge()
        Dim doc As acaddocument

        doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.AcadDocument
        If doc <> vbNull Then
            doc.PurgeAll()
        End If


    End Sub
End Class

 Any help is greatly appreciated.

 

Thanks,

Constantine

 

0 Likes
Message 6 of 7

Anonymous
Not applicable

I think the equivalent is

 

If doc IsNot Nothing

 

-drg

0 Likes
Message 7 of 7

Anonymous
Not applicable

Dan,

 

Thanks, that works!

 

Constantine

0 Likes