.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to send commands using ResultBuffer, Application.Invoke, etc.

1 REPLY 1
Reply
Message 1 of 2
Anonymous
704 Views, 1 Reply

How to send commands using ResultBuffer, Application.Invoke, etc.

I'm trying to understand how to send commands to Autocad Electrical 2013 using ResultBuffer, Application.Invoke, etc.

 

When I copy/paste the following function into the AE command line, it will refresh the scratch database.

(c:wd_mdb_update_wfrm2all_netlst_tabs options)

 

How do I translate the above function into something that can be passed into AE via ResultBuffer. I've tried several different approaches and all have been rejected. In the code below are the iterations I tried at sending the c:wd_mdb_update_wfrm2all_netlst_tabs command.

 

 

[CommandMethod("TestRefreshNetList", CommandFlags.Session)]
public static void TestRefreshNetList()
{
	/* 
	  
	 Lisp function that can be pasted into command line to
	 refresh netlist
	 
	   (c:wd_mdb_update_wfrm2all_netlst_tabs options)
	 
	 */

	ResultBuffer bufIn = null;
	ResultBuffer bufOut = null;
	try
	{

		// Attempt #1
		//; error: AutoCAD command rejected: "_.UNDO"
		bufIn = new ResultBuffer();
		bufIn.Add(new TypedValue(LispUtil.RTSTR, "c:wd_mdb_update_wfrm2all_netlst_tabs"));
		bufIn.Add(new TypedValue(LispUtil.RTNIL));
		bufOut = Application.Invoke(bufIn);
		Debug.Print(bufOut.ToString());

		// Attempt #2
		//; error: AutoCAD command rejected: "_.UNDO"
		bufIn = new ResultBuffer();
		bufIn.Add(new TypedValue(LispUtil.RTSTR, "c:wd_mdb_update_wfrm2all_netlst_tabs"));
		bufIn.Add(new TypedValue(LispUtil.RTSTR, ""));
		bufOut = Application.Invoke(bufIn);
		Debug.Print(bufOut.ToString());

		// Attempt #3				
		bufIn = new ResultBuffer();
		bufIn.Add(new TypedValue(LispUtil.RTSTR, "c:wd_mdb_update_wfrm2all_netlst_tabs"));
		bufIn.Add(new TypedValue(LispUtil.RTNONE));
		bufOut = Application.Invoke(bufIn);
		Debug.Print(bufOut.ToString());

		// Attempt #4
		//; error: AutoCAD command rejected: "_.UNDO"
		bufIn = new ResultBuffer();
		bufIn.Add(new TypedValue(LispUtil.RTSTR, "c:wd_mdb_update_wfrm2all_netlst_tabs"));
		bufIn.Add(new TypedValue(LispUtil.RTLB));
		bufIn.Add(new TypedValue(LispUtil.RTSTR, ""));
		bufIn.Add(new TypedValue(LispUtil.RTLE));
		bufOut = Application.Invoke(bufIn);
		Debug.Print(bufOut.ToString());

		// Attempt #5
		//; error: AutoCAD command rejected: "_.UNDO"
		bufIn = new ResultBuffer();
		bufIn.Add(new TypedValue(LispUtil.RTSTR, "c:wd_mdb_update_wfrm2all_netlst_tabs"));
		bufIn.Add(new TypedValue(LispUtil.RTLB));
		bufIn.Add(new TypedValue(LispUtil.RTNIL));
		bufIn.Add(new TypedValue(LispUtil.RTLE));
		bufOut = Application.Invoke(bufIn);
		Debug.Print(bufOut.ToString());

		// Attempt #6
		//; error: AutoCAD command rejected: "_.UNDO"
		bufIn = new ResultBuffer();
		bufIn.Add(new TypedValue(LispUtil.RTSTR, "c:wd_mdb_update_wfrm2all_netlst_tabs"));
		bufIn.Add(new TypedValue(LispUtil.RTLB));
		bufIn.Add(new TypedValue(LispUtil.RTLE));
		bufOut = Application.Invoke(bufIn);
		Debug.Print(bufOut.ToString());

	}
	catch (System.Exception ex)
	{
		Debug.Print(ex.Message);
	}
}

 

 Thanks.

 

1 REPLY 1
Message 2 of 2
Anonymous
in reply to: Anonymous

I've given up.  

 

I've found a posting on the swamp that clued me in as to how to set up the ResultBuffer. Unfortunately it doesn't work. 

http://www.theswamp.org/index.php?topic=40540.0  

 

I translated the poster's code to C# and it errors out like just as the poster in the previous link found.

 

This code will start the rebuild of the scratch database but will eventually error.

 

[CommandMethod("TestRebuild", CommandFlags.Session )]
public static void TestRebuild()
{
	ResultBuffer rbi = null;
	ResultBuffer rbo = null;
	try
	{
		rbi = new ResultBuffer();
		rbi.Add(new TypedValue(LispUtil.RTSTR, "c:ace_update_WFRM2ALL"));
		rbi.Add(new TypedValue(LispUtil.RTSHORT, 1));
	   
		rbo = Application.Invoke(rbi);
		Debug.Print(rbo.ToString());

	}
	catch (System.Exception ex)
	{
		Debug.Print(ex.Message);
	}
}

 

The odd thing is if I copy and paste the function directly into the command window, it works fine. I get this in the command window

 

 Command: (c:ace_update_WFRM2ALL 1)
 reading project database file . . .
 Data written out to project database table "WFRM2ALL" and "WNETLST"

 

 I can use SendStringToExecute from document and it works.  

 

[CommandMethod("TestRebuild2", CommandFlags.Session)]
public static void TestRebuild2()
{
	var doc = Application.DocumentManager.MdiActiveDocument;
	string command = "(c:ace_update_WFRM2ALL 1) ";
	doc.SendStringToExecute(command, true, false, true);
	doc = null;
}

 

 

  How does a programmer know when to use the SendStringToExecute vs ResultBuffer?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost