.NET

Reply
*T.Willey
Message 1 of 1 (62 Views)

Open drawing with a time limit

62 Views, 0 Replies
09-15-2006 08:55 AM
I have gotten all the help I can on the code side of things. It is running
now, but I need help on the Acad side of things now. The object is to open
a list of drawings (user selected) one at a time, issue the 3dorbit command,
let run for a certain amout of time (10 seconds right now), then close that
one, and open the next. I can get to the point of issueing the command, and
canceling it, but when it goes to close the current drawing, Acad crashes
out without any notice.

Any/all help is appreciated. I will attach a text file of the code also, as
this may not look good.

using System;
using System.Diagnostics;
using System.Timers;
using System.Windows.Forms;
using System.Runtime.InteropServices;

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;

using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

[assembly: CommandClass(typeof(Test.TimeLimitOpenv04))]

namespace Test
{
///
/// Description of TimeLimitOpen.
///
public class TimeLimitOpenv04
{

[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl,
EntryPoint = "?acedPostCommand@@YAHPBD@Z")]
extern static public int acedPostCommand(string cmd);
private static string[] DwgList;//<---Modification
private static DocumentCollection DocMan = AcadApp.DocumentManager;
private static Document NewDoc;
private static int cnt = 1; //<---Modification
System.Timers.Timer CountDownTimer;
//- Constructor: sets up var's etc for this class before use.
public TimeLimitOpenv04()
{
CountDownTimer = new System.Timers.Timer();
CountDownTimer.Elapsed += new
ElapsedEventHandler(CancelCommand);
CountDownTimer.Interval = 10000;
}

~TimeLimitOpenv04() // <-- Destructor, do clean up here.
{
CountDownTimer.Elapsed -= new
ElapsedEventHandler(CancelCommand);
}
public void CancelCommand(object sender, ElapsedEventArgs e)
{
acedPostCommand ("CancelCmd");
acedPostCommand ("CancelCmd");
CountDownTimer.Enabled = false;
TimeLimitOpenv04.NewDoc.CloseAndDiscard();
TimeLimitOpenv04.NewDoc = TimeLimitOpenv04.DocMan.Open
(DwgList[cnt], true);
if (TimeLimitOpenv04.NewDoc !=
TimeLimitOpenv04.DocMan.MdiActiveDocument) {
TimeLimitOpenv04.DocMan.MdiActiveDocument =
TimeLimitOpenv04.NewDoc;
}
++TimeLimitOpenv04.cnt;//You access it by the class name
if (TimeLimitOpenv04.cnt > TimeLimitOpenv04.DwgList.Length) {
CountDownTimer.Enabled = false;
CountDownTimer.Dispose();
}
CountDownTimer.Enabled = true;
TimeLimitOpenv04.NewDoc.SendStringToExecute ("_.3dorbit", false,
false, true);
}

[CommandMethod("TestTimer4", CommandFlags.Session)]
public void Main()
{
Autodesk.AutoCAD.Windows.OpenFileDialog Dia =
new Autodesk.AutoCAD.Windows.OpenFileDialog(
"Select drawings to update Cloud layer", "", "dwg", "",

Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.AllowMultiple);
Dia.ShowDialog();
TimeLimitOpenv04.DwgList = Dia.GetFilenames();
if (TimeLimitOpenv04.DwgList.Length > 1)
{
CountDownTimer.Enabled = true;
TimeLimitOpenv04.NewDoc = TimeLimitOpenv04.DocMan.Open
(DwgList[0], true);
if (TimeLimitOpenv04.NewDoc !=
TimeLimitOpenv04.DocMan.MdiActiveDocument) {
TimeLimitOpenv04.DocMan.MdiActiveDocument =
TimeLimitOpenv04.NewDoc;
}
TimeLimitOpenv04.NewDoc.SendStringToExecute ("_.3dorbit\n",
false, false, true);
}
}
}
}


--

Tim
"A blind man lets nothing block his vision."
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 or visit the Installation and Licensing Forum to get help installing your software.