Jump to content

Fatal reading error...


btraemoore
 Share

Recommended Posts

I'm accessing autocad via COM and netloading a custom dll, but when i call my start function inside of my dll, intermittently i get a fatal error.. I do not get it when i call the method from in process, but only when i call it from COM. Here is the code from when get a list of paths.

 

 


private void Btn_ContClick(object sender, System.EventArgs e)
{
List<string> DwgList = getDWGStofix();
sendToExecute(DwgList,"faud");
}

bool SC = true;
private void sendToExecute(List<string> DwgList,string cmd){
PreloadCmds();
if (DwgList != null)
{
	foreach (string pth in DwgList)
	{
		if(SC)
			FixDwg(pth,cmd);
		else
			break;
	}
	if(AcApp != null)
		AcApp.Quit();
	if(SC)
		MessageBox.Show("Successful completion!!","ALERT");
	Application.Exit();
}
}

AcadDocument activeDWG;
private void PreloadCmds(){
string NewDWGPth = "C:/Documents and Settings/moorerb/application data/autodesk/autocad 2012 - english/r18.2/enu/template/acad.dwt";
try {
	activeDWG = AcApp.ActiveDocument;
} catch (Exception) {
	AcApp.Documents.Open(NewDWGPth,false);
	activeDWG = AcApp.ActiveDocument;
}
activeDWG.SendCommand(
	string.Format(
		"(command \"netload\" \"{0}InProcAudit.dll\")\n",dllPath.Replace('\\','/'))
);
}

string prevDWG;
private void FixDwg(string pth, string cmd)
{
activeDWG = AcApp.Documents.Open(pth,false);
activeDWG.SetVariable("USERI1",1);
if(prevDWG != null)
	activeDWG.SetVariable("USERS1",prevDWG);

// try to send the the activation command to the active drawing command line.
try {
	var*appState*=*AcApp.GetAcadState();
	while*(!appState.IsQuiescent){}
	activeDWG.SendCommand(string.Format("{0}\n",cmd));
} catch (System.Exception ex) {
	if(ex.Message.Contains("The remote procedure call failed.")){
		MessageBox.Show(
			string.Format(
				"We have encountered an error with drawing \"{0}\".",pth)
			,"Error"
			,MessageBoxButtons.OK
			,MessageBoxIcon.Exclamation
		);
		AcApp = null;
		SC = false;
	}
}
activeDWG.BeginClose += new _DAcadDocumentEvents_BeginCloseEventHandler(activeDWG_BeginClose);
while (activeDWG.GetVariable("USERI1") == 1)
{
	try {
		// hold for .5 seconds before checking for variable change
		Thread.Sleep(500);
	} catch (COMException CE) {
		if(CE.ErrorCode.ToString() == "-2147417848"){
			activeDWG.BeginClose -= new _DAcadDocumentEvents_BeginCloseEventHandler(activeDWG_BeginClose);
			activeDWG = null;
			break;
		}

	}
}
prevDWG = pth;
activeDWG.Save();
if(activeDWG != null)
	activeDWG.Close();
}      

 

I've been trying to figure it out for a few days now and cant seem to fix the problem.. My analysis is that im interupting autocad, to counter that i put an AcadState.isQuiescent() check in there.. any ideas?

Edited by btraemoore
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...