.NET

Reply
Contributor
Blarran
Posts: 15
Registered: ‎07-30-2012
Message 1 of 2 (119 Views)

ResultBuffer and Application.Invoke

119 Views, 1 Replies
08-13-2014 12:44 PM

I'm trying to understand how to send commands using ResultBuffer and Application.Invoke.

 

I want to be able to jump (or surf) to a component in Autocad Electrical from another application that has a DataGridView. When user clicks on a row, AE jumps to the location of the component in question.

 

I wrote test code to figure out how to use the ResultBuffer and Application.Invoke. I couldn't get it to work. The work around is to send the commands using SendStringToExecute().

 

Can someone tell me what I'm doing wrong with setting up the ResultBuffer?

 

Thanks.

 

[CommandMethod("TestJump", CommandFlags.Session )]
static public void TestJump()
{
	string path = @"C:\WORK\AUTOCAD ELECTRICAL\SAMPLE PROJECT\33729802004.DWG";
	path = path.Replace(@"\",@"/");
	// JumpTo(path, "7366"); <<<< DOESN"T WORK
	JumpTo2(path, "7366");
}


// DOES NOT WORK
public static void JumpTo(string path,string hdl )
{
	try
	{
		// WHAT IS WRONG???
		ResultBuffer pa = new ResultBuffer();
		pa.Add(new TypedValue(LispUtil.RTSTR, "c:ace_surf_zoom_in_no_dlg"));
		pa.Add(new TypedValue(LispUtil.RTSTR, path));
		pa.Add(new TypedValue(LispUtil.RTSTR, hdl));
		pa.Add(new TypedValue(LispUtil.RTNIL));

		ResultBuffer rb = Application.Invoke(pa);
		Debug.Print(rb.ToString());
	}
	catch (System.Exception ex)
	{
		Debug.Print(ex.Message);
	}
}

// THIS WORKS
public static void JumpTo2(string path, string hdl)
{
	string cmd = "(c:ace_surf_zoom_in_no_dlg \"{0}\" \"{1}\" nil) ";
	cmd = string.Format(cmd, path, hdl);
	var doc = Application.DocumentManager.MdiActiveDocument;
	Application.
	doc.SendStringToExecute(cmd, true, false, true);
	doc = null;
}

 

ADN Support Specialist
augusto.goncalves
Posts: 387
Registered: ‎04-30-2009
Message 2 of 2 (74 Views)

Re: ResultBuffer and Application.Invoke

08-27-2014 01:35 PM in reply to: Blarran

I'm not sure about the type numbers you're using, but I replaced them with the number and seems to work fine:

 

public static void JumpTo(string path, string hdl)
{
  try
  {
    ResultBuffer pa = new ResultBuffer();
    pa.Add(new TypedValue(5005, "c:ace_surf_zoom_in_no_dlg"));
    pa.Add(new TypedValue(5005, path));
    pa.Add(new TypedValue(5005, hdl));
    pa.Add(new TypedValue(5019));

    ResultBuffer rb = Application.Invoke(pa);
    Debug.Print(rb.ToString());
  }
  catch (System.Exception ex)
  {
    Debug.Print(ex.Message);
  }
}
Regards,



Augusto Goncalves
Autodesk Developer Network
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!