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

Purgeall

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
franciscocsilva
1106 Views, 7 Replies

Purgeall

Hello,

 

Needed help in the following solution.

 

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

 

Thanks

Francisco Silva
www.lojadosdesenhadores.blogspot.com
7 REPLIES 7
Message 2 of 8

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

Thanks Alexander

 

i have this message:

 

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

Francisco Silva
www.lojadosdesenhadores.blogspot.com
Message 4 of 8
e.g.
in reply to: franciscocsilva

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.

Message 5 of 8


@franciscocsilva 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.

 

 


@e.g. 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

Message 6 of 8

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.
Message 7 of 8

Resolved
Thanks Alexander

Francisco Silva
www.lojadosdesenhadores.blogspot.com
Message 8 of 8

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

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