Document CloseAndDiscard In 2013

Document CloseAndDiscard In 2013

Hugh_Compton
Advisor Advisor
4,189 Views
18 Replies
Message 1 of 19

Document CloseAndDiscard In 2013

Hugh_Compton
Advisor
Advisor

 

The Doc.CloseAndDiscard() method on documents returns message of ' not a member of 'Autodesk.AutoCAD.ApplicationServices.Document'. 

 

How do we close a dwg file in AutoCAD 2013?

 

Thanks

0 Likes
Accepted solutions (3)
4,190 Views
18 Replies
Replies (18)
Message 2 of 19

Alexander.Rivilis
Mentor
Mentor
Accepted solution
DocumentExtension.CloseAndDiscard
P.S.: Also read ObjectARX for AutoCAD 2013 Docs: Managed Class Reference -> Migration Guide->.NET Migration Guide

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | 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 19

Hugh_Compton
Advisor
Advisor

 

Works great, thanks.

0 Likes
Message 4 of 19

Anonymous
Not applicable

more clearly, it's DocumentExtension.CloseAndDiscard(doc)

 


just in case anyone would expect it to be an extension method, like i did

0 Likes
Message 5 of 19

jeff
Collaborator
Collaborator

It is a extension method

 

public static void CloseAndDiscard(this Document doc)
{
    CloseInternal(doc, true, null);
}

 

You can also find your answers @ TheSwamp
Message 6 of 19

Anonymous
Not applicable

I checked it and you're right, but I am using VB.net. And there it isn't an extension method.

 

Taken from MSDN:

 

Notice that the extension method definition is marked with the extension attribute <Extension()>. Marking the module in which the method is defined is optional, but each extension method must be marked. System.Runtime.CompilerServices must be imported in order to access the extension attribute.

Extension methods can be declared only within modules.

 

 

0 Likes
Message 7 of 19

jeff
Collaborator
Collaborator

With C# you import the namespace and VB you import the module, but it still is a extension method.

You can also find your answers @ TheSwamp
0 Likes
Message 8 of 19

Anonymous
Not applicable

I am importing 

 

Imports Autodesk.AutoCAD.ApplicationServices.DocumentExtension

which is a class. I couldn't find the module I am supposed to import in VB. Do you know where I can find it?

0 Likes
Message 9 of 19

Alexander.Rivilis
Mentor
Mentor

In AutoCAD 2013 class Autodesk.AutoCAD.ApplicationServices.DocumentExtension is in acmgd.dll

 

08-03-2013 11-08-47.png

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | 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 10 of 19

Anonymous
Not applicable

I know that, Alexander. I was asking about the module for VB.

0 Likes
Message 11 of 19

jeff
Collaborator
Collaborator
Accepted solution

Not sure what your asking

 

Imports System
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.ApplicationServices.DocumentExtension

<Assembly: CommandClass(GetType(AutoCAD_VB_plug_in1.MyCommands))> 
Namespace AutoCAD_VB_plug_in1

    Public Class MyCommands


        <CommandMethod("MyCommand")> _
        Public Sub MyCommand()
            Dim doc As Document = Application.DocumentManager.MdiActiveDocument
            doc.CloseAndDiscard()

        End Sub


    End Class

End Namespace

 

You can also find your answers @ TheSwamp
0 Likes
Message 12 of 19

DiningPhilosopher
Collaborator
Collaborator

The doc you quote relate to defining/implementing extension methods in VB, not consumign them from VB.

 

There does seem to be a problem with consumig those methods as extension methods in VB.NET, and it may have something to do with the fact that both containing type and the methods themselves require the ExtensionAttribute.

 

0 Likes
Message 13 of 19

DiningPhilosopher
Collaborator
Collaborator

@Anonymous wrote:

I know that, Alexander. I was asking about the module for VB.


 

There is no module to import.

 

You are looking at docs that relate to defining extension methods in VB.NET, not consuming extension methods from an assembly.

 

You should only have to import the namespace containing the type that exposes the extension methods, but as I mentioned in my other reply, there seems to be a problem there, as when I tried with the required assembly reference and namespace import, the VB code compiler couldn't find the extension method.

 

 

0 Likes
Message 14 of 19

Anonymous
Not applicable

@DiningPhilosopher: Exactly, that's what I am trying to say. It doesn't work as extension method for VB. I quoted the docs for defining the extension method, because I wanted to point out, that there might be a problem. If you reference the same class from VB and C# it's not compatible.

 

@Jeff: This is what I would expect, but it doesn't work for me.

0 Likes
Message 15 of 19

jeff
Collaborator
Collaborator
Accepted solution

In the last example,

CloseAndDiscard does not show up in intellisense but it does build for me.

You can also find your answers @ TheSwamp
Message 16 of 19

Anonymous
Not applicable

@Jeff: Thanks, it's really just missing intellisense that confused me.

0 Likes
Message 17 of 19

jeff
Collaborator
Collaborator

In a VB project if I reference a fully managed assembly written in C# with extension methods all I have to do is import the namespace and shows up in intellisense and what not.

Don't know?

You can also find your answers @ TheSwamp
0 Likes
Message 18 of 19

Anonymous
Not applicable

Do you mean, that it usually works? Or that it works for you with this particular case too?

0 Likes
Message 19 of 19

jeff
Collaborator
Collaborator

Sorry,

I just was referring to a library of extension methods written in C# that I referenced into new VB project to test quickly.

You can also find your answers @ TheSwamp
0 Likes