public has an error message under public static void for the following code

public has an error message under public static void for the following code

irahmanJS6UB
Participant Participant
368 Views
3 Replies
Message 1 of 4

public has an error message under public static void for the following code

irahmanJS6UB
Participant
Participant

Hello, for the following code I get a red line under public and I am not sure as to why, can someone help me?

 

[CommandMethod("OpenDrawing", CommandFlags.Session)]
public static void OpenDrawing()
{
string strFileName = "C:\\campus.dwg";
DocumentCollection acDocMgr = Application.DocumentManager;

if (File.Exists(strFileName))
{
acDocMgr.Open(strFileName, false);
}
else
{
acDocMgr.MdiActiveDocument.Editor.WriteMessage("File " + strFileName +
" does not exist.");
}
}

 

Thank you!

0 Likes
369 Views
3 Replies
Replies (3)
Message 2 of 4

AVCPlugins
Advisor
Advisor

Look in the error message box. You probably didn't declare a namespace and a public class. It feels like you should read the VS tutorial first and compile "Hello world".


Plugins for AutoCAD
A>V>C>
AppStore | Facebook | Twitter | YouTube | Blog
0 Likes
Message 3 of 4

kpblc2000
Advisor
Advisor

 

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;
using System.IO;

namespace Aspecific.AcadCommands
{
    public static class TestCommand
    {

        [CommandMethod("OpenDrawing", CommandFlags.Session)]
        public static void OpenDrawing()
        {
            string strFileName = "C:\\campus.dwg";
            DocumentCollection acDocMgr = Application.DocumentManager;

            if (File.Exists(strFileName))
            {
                acDocMgr.Open(strFileName, false);
            }
            else
            {
                acDocMgr.MdiActiveDocument.Editor.WriteMessage("File " + strFileName +
                " does not exist.");
            }
        }
    }
}

Perhaps this?

 

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


Алексей Кулик aka kpblc | Aleksei Kulik aka kpblc Facebook | LinkedIn
autolisp.ru
Техническая поддержка программистов Autodesk в СНГ
Библиотека пользовательских lisp-функций | Custom Lisp-function library

0 Likes
Message 4 of 4

_gile
Consultant
Consultant

Hi,

 

I suspect you didn't start your project from a "class library" one.

You can start from this topic to see how to create an AutoCAD .NET project.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes