.NET

Reply
Contributor
osayed3202
Posts: 12
Registered: ‎01-05-2014
Message 1 of 5 (383 Views)
Accepted Solution

DocumentManager.open() not open the file completely

383 Views, 4 Replies
01-07-2014 12:49 AM

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):smileywink:) , 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
Valued Contributor
FRFR1426
Posts: 71
Registered: ‎04-05-2012
Message 2 of 5 (346 Views)

Re : DocumentManager.open() not open the file completely

01-07-2014 12:02 PM 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.
Contributor
osayed3202
Posts: 12
Registered: ‎01-05-2014
Message 3 of 5 (328 Views)

Re: DocumentManager.open() not open the file completely

01-07-2014 07:55 PM 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
Moderator
Alexander.Rivilis
Posts: 1,398
Registered: ‎04-09-2008
Message 4 of 5 (303 Views)

Re: DocumentManager.open() not open the file completely

01-08-2014 08:15 AM in reply to: osayed3202

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


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Contributor
osayed3202
Posts: 12
Registered: ‎01-05-2014
Message 5 of 5 (286 Views)

Re: DocumentManager.open() not open the file completely

01-08-2014 07:15 PM in reply to: Alexander.Rivilis

Thank you all guys,

really appreciate your time and support.

 

bye till another discussion :smileyhappy:

Best Regards
O.Sayed
CAD developer

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community