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.
Solved! Go to Solution.
Solved by Alexander.Rivilis. Go to Solution.
Solved by FRFR1426. Go to Solution.
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.
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
Thank you all guys,
really appreciate your time and support.
bye till another discussion 🙂
To get it to work in vb I used this:
.SendStringToExecute("_-purge _all " & vbCr & "n ", True, False, True)