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

DocumentManager.open() not open the file completely

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
osayed3202
1095 Views, 5 Replies

DocumentManager.open() not open the file completely

Hi guys,

I am trying to open document according to the paths in the listview, the open() function when it opens the file the file doesnot open completely so it ignore the subsequent commands like ((acdMgr.MdiActiveDocument.SendStringToExecute("-purge all * n", false, false, true);)) , here is the code

 

            DocumentCollection acdMgr = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager;
            string strFullPath;
      

            //string strTextFileName = SaveDialog.FileName;
            foreach (ListViewItem itemRow in this.lstView.Items)
            {
                Transaction tm = acdMgr.MdiActiveDocument.Database.TransactionManager.StartTransaction();
                using (tm)
                {
                    ListViewItem item = lstView.Items[itemRow.Index];

                    string lines = item.SubItems[0].Text;
                    string col = item.SubItems[1].Text;
                    strFullPath = col + "\\" + lines;

                    //acdMgr.Open(strFullPath, false);
                    acdMgr.Open(strFullPath,false);
                    
                    acdMgr.MdiActiveDocument.SendStringToExecute("-purge all * n", false, false, true);

                    acdMgr.MdiActiveDocument.CloseAndSave(strFullPath);

                    tm.Commit();

                }
                //tm.Commit();

  

            }

 The image attached is for the cad screen after executing the open() function.

 

 

 

 

 

Best Regards
O.Sayed
CAD developer
5 REPLIES 5
Message 2 of 6
FRFR1426
in reply to: osayed3202

It is not the open command which not open the drawing completely it is because the SendStringToExecute which is executed at the end of your command. You have to use SendCommand instead (assuming you have the CommandFlags.Session enabled).

You can also purge without sending a command.
Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr
Message 3 of 6
osayed3202
in reply to: osayed3202

thanks guys for your time and support 

the sendcommand() works but i am struggling using it. 

 

 

 private void btnPurge_Click(object sender, EventArgs e)
        {
            DocumentCollection acdMgr = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager;
            string strFullPath;
      

            //string strTextFileName = SaveDialog.FileName;
            foreach (ListViewItem itemRow in this.lstView.Items)
            {
                Transaction tm = acdMgr.MdiActiveDocument.Database.TransactionManager.StartTransaction();
                using (tm)
                {
                    ListViewItem item = lstView.Items[itemRow.Index];

                    string lines = item.SubItems[0].Text;
                    string col = item.SubItems[1].Text;
                    strFullPath = col + "\\" + lines;

                    //acdMgr.Open(strFullPath, false);
                    acdMgr.Open(strFullPath,false);

                    //Thread.Sleep(3000);

                    AcadApplication app = (AcadApplication) Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;

                    app.ActiveDocument.SendCommand("(command " + (char)34 +
                                                    "-Purge" + (char)34 +
                                                    " " + (char)34 +
                                                    "all" + (char)34 +
                                                    " " + (char)34 +
                                                    "*" + (char)34 +
                                                    " " + (char)34 +
                                                    "n" + (char)34 +
                                                    " " + (char)34 +
                                                     ")");
                    // this is the output in the autocad command line : (command "-Purge" "all" "*" "n" ")

                    app.ActiveDocument.SendCommand("regen ");


                    //(command "-Purge" "all" "*" "n" ")
                    
                    //acdMgr.MdiActiveDocument.SendStringToExecute("-purge all * n", false, false, true);

                    //acdMgr.MdiActiveDocument.CloseAndDiscard();
                    tm.Commit();

                }
                //tm.Commit();

  

            }
        }

 the output in the autocad command line like this   (command "-Purge" "all" "*" "n" ") but did not work and stick in the command line and did not execute.

 

 

 

 

 

Best Regards
O.Sayed
CAD developer
Message 4 of 6

If you use SendCommand or SendStringToExecute then you have to add " " or "\n" to command string, e.g. "_-purge _all * _n\n"

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

Thank you all guys,

really appreciate your time and support.

 

bye till another discussion 🙂

Best Regards
O.Sayed
CAD developer
Message 6 of 6
MrShepherd
in reply to: osayed3202

To get it to work in vb I used this:

.SendStringToExecute("_-purge _all " & vbCr & "n ", True, False, True)

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