Purgeall

Purgeall

Anonymous
Not applicable
2,214 Views
7 Replies
Message 1 of 8

Purgeall

Anonymous
Not applicable

Hello,

 

Needed help in the following solution.

 

doc.SendStringToExecute("_-Purge _A _* _N ", True, False, False)

 

Thanks

0 Likes
Accepted solutions (2)
2,215 Views
7 Replies
Replies (7)
Message 2 of 8

Alexander.Rivilis
Mentor
Mentor
Accepted solution

What help do you need?

 

Maybe simplest sample:

 

using System;
using System.Reflection;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;

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

namespace Rivilis
{
  public class Purge
  {
    [CommandMethod("MyPurgeAll")]
    static public void MyPurgeAll()
    {
      // For AutoCAD 2013+
      object adoc = Application.DocumentManager.MdiActiveDocument.GetAcadDocument();
      // For AutoCAD 2012-
      // object adoc = Application.DocumentManager.MdiActiveDocument.AcadDocument;
      if (adoc != null) {
        adoc.GetType().InvokeMember("PurgeAll",BindingFlags.InvokeMethod, null, adoc, null);
      }
    }
  }
}

 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 3 of 8

Anonymous
Not applicable

Thanks Alexander

 

i have this message:

 

Error 1 'GetAcadDocument' is not a member of 'Autodesk.AutoCAD.ApplicationServices.Document'. 

0 Likes
Message 4 of 8

Anonymous
Not applicable

Hi Alexander,

 

the code works ok, but I have though a question: I have a drawing that was last saved in paper space (paper space being active space).

 

When I open up the drawing and try to run the code (just as the first command in the drawing), it doesn't run. Although if I enter model space through viewport or switch back and forth between model space and paper space, the code will run as supposed to.

 

I don't know what is missing.

 

Thanks,

 

e.g.

0 Likes
Message 5 of 8

Alexander.Rivilis
Mentor
Mentor

@Anonymous wrote:

Thanks Alexander

 

i have this message:

 

Error 1 'GetAcadDocument' is not a member of 'Autodesk.AutoCAD.ApplicationServices.Document'. 


This is because you did not read the comments in the program. Read them carefully.

 

 


@Anonymous wrote:
...When I open up the drawing and try to run the code (just as the first command in the drawing), it doesn't run. Although if I enter model space through viewport or switch back and forth between model space and paper space, the code will run as supposed to...

Sorry but I can not reproduce this behavior. 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

0 Likes
Message 6 of 8

brianchapmandesign
Collaborator
Collaborator

I was just telling myself, as an uneducated programming hobbyiest writing addins for myself only, that modifying geometry in CAD so far has been fairly straight forward, but there was no way I could figure out how to "purge all".... VUALA! Magic appears at Autodesk 🙂

 

Thanks Alexander (or is it Alex?)

 

One more question... I couldn't help but notice the difference in the adoc dealio... everything I've written for myself has been for 2012... are you showing me that I'll have to update every flippin acdoc in my code when I update to 2013?  sad face lol

 

Thanks!

 

 


"Very funny, Scotty. Now beam down my clothes.
0 Likes
Message 7 of 8

Anonymous
Not applicable

Resolved
Thanks Alexander

0 Likes
Message 8 of 8

Alexander.Rivilis
Mentor
Mentor
Accepted solution

This code have to work in both AutoCAD 2012 (and 2011, 2010...) and AutoCAD 2013:

using System;
using System.Reflection;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;

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

namespace Rivilis
{
  public class Purge
  {
    [CommandMethod("MyPurgeAll")]
    static public void MyPurgeAll()
    {
      Document doc = Application.DocumentManager.MdiActiveDocument;
      object adoc = null;
      if (Application.Version.Major < 19) { 
        // For AutoCAD 2012- (i.e. 2012, 2011, 2010, ...)
        adoc = doc.GetType().InvokeMember("AcadDocument", 
          BindingFlags.GetProperty, null, doc, null);
      } else { 
        // For AutoCAD 2013+ (i.e. 2013, 2014 (???), ...)
        Type ext = typeof(Autodesk.AutoCAD.Windows.Menu).Assembly
.GetType("Autodesk.AutoCAD.ApplicationServices.DocumentExtension", true); MethodInfo GetAcadDocumentMethod = ext.GetMethod("GetAcadDocument", BindingFlags.Public | BindingFlags.Static); adoc = GetAcadDocumentMethod.Invoke(doc, new object[1] { doc }); } if (adoc != null) { adoc.GetType().InvokeMember("PurgeAll", BindingFlags.InvokeMethod, null, adoc, null); } } } }

 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

0 Likes