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

Fiberless operations

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
thierry_prince
1800 Views, 7 Replies

Fiberless operations

Hi,

 

I wonder about the migration of programs that use the "acedCommand()" API function.

Can someone tell me if the "acedCommandC()" replacement function is synchronous ?

 

For example, if I have a command like :

void MyNewCommand()
{
  // Use of first command
  extern MyClass myData1;
  acedCommand(RTSTR, theFirstCommand, RTNONE);
  for (int i = 0; i < myData1.count; i++)
    acedCommand(RT3DPOINT, myData1.point[i], RTNONE);
  acedCommand(RTSTR, "", RTNONE);

  // Use of second command
  extern MyClass myData2;
  acedCommand(RTSTR, theSecondCommand, RTNONE);
  for (int i = 0; i < myData2.count; i++)
    acedCommand(RT3DPOINT, myData2.point[i], RTNONE);
  acedCommand(RTSTR, "", RTNONE);
 
// Something to process or use the previous results
DoSomethingWithTheResults();
}

 

Can this code be replaced with someting like :

void MyNewCommandWithoutFiber()
{
  // Use of the first command
  extern MyClass myData1;
  acedCommandC(&MyCallBack,
               reinterpret_cast<void*>(&myData1),
               RTSTR, theFirstCommand,
               RTNONE);

  // Use of the second command
  extern MyClass myData2;
  acedCommandC(&MyCallBack,
               reinterpret_cast<void*>(&myData2),
               RTSTR, theSecondCommand,
               RTNONE);

// Something to process or use the previous results
DoSomethingWithTheResults();
}

Thanks for your answers.

Cheers,

Thierry

7 REPLIES 7
Message 2 of 8

Hi,

 

there are some comments and instructions available >>>in the wikihelp<<< .

Do these help?

 

- alfred -

 

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 8

Hi Alfred,

 

Thanks for yor answer.

Of course yes, I read the Wiki before, but all is not clear.

 

In my different tests, it seems that AutoCAD continue the processing of the "main" code and when it is finished, then the callback is called.

But at this time all the data we give (myData1 and myData2) has no more sense.

 

I know that there is some solutions to replace the use of acedCommand() and then to not need to port the code. But because we have lots of commands that use this mechanism (they were written for many many years ago), I would prefer to do the minimal work to not waste too many time.

 

Cheers,

Thierry

Message 4 of 8
Balaji_Ram
in reply to: thierry_prince

Hi Thierry,

 

Your code seems to have all the inputs that are required by the your commands.

In that case, you do not need to use the coroutine version. You can try using the "acedCmdS" as in this code snippet :

 

AcArray<AcGePoint3d> points;
points.append(AcGePoint3d(0.0, 0.0, 0.0));
points.append(AcGePoint3d(10.0, 0.0, 0.0));
points.append(AcGePoint3d(10.0, 10.0, 0.0));
points.append(AcGePoint3d(0.0, 10.0, 0.0));

resbuf* rb = acutBuildList(RTSTR, _T("MyCommand1"), 0);
resbuf* lastNode = rb;
		
for (long i = 0; i < points.length(); i++) 
{
	AcGePoint3d pt = points[i];
	resbuf* tmp =  acutBuildList(RT3DPOINT, pt, 0);
	lastNode->rbnext = tmp;
	lastNode = tmp;
}
acedCmdS(rb);

 After your first command, the second command can be invoked on similar lines. 

 

Regards,

Balaji



Balaji
Developer Technical Services
Autodesk Developer Network

Message 5 of 8
thierry_prince
in reply to: Balaji_Ram

Hi Balaji,

 

Thanks for your answer but I know that solution, and I use it in some cases.

My sample was only to propose something simple.

 

A more concrete sample could be ue use of the INSERT command :

 

do
{
  acedCommand(RTSTR, "_-INSERT", RTSTR, symbolName, 0);
  while (insertCommandIsActive())
  {
    acedCommand(RTSTR, PAUSE, 0); // Get some parameter in an arbitrary order
  }
}
while (newSymbolCreated())

Cheers,

Thierry

Message 6 of 8
Balaji_Ram
in reply to: thierry_prince

Hi Thierry,

 

Yes, I get your point. 

 

acedCommand was only synchronous in earlier versions of AutoCAD if all the parameters required by the command were provided together. But you could wait for the command to complete in a while loop by checking if the command is active.

 

Unfortunately, I do not think that is possible with "acedCommandC". Some restructuring of the code might be needed to know when both the insert commands get completed since this information is available in the callback functions.

 

Here is a sample code that worked ok :

 

static void AdskMyTestCommand(void)
{
	acedCommandC(&myCallbackFn1, NULL, RTSTR, ACRX_T("_-INSERT"), RTSTR, ACRX_T("TestBlk1"), RTNONE); 
}

static void InsertBlock2(void)
{
	acedCommandC(&myCallbackFn2, NULL, RTSTR, ACRX_T("_-INSERT"), RTSTR, ACRX_T("TestBlk2"), RTNONE);
}

static void CallWhenDone()
{
	acutPrintf(ACRX_T("\nAll Done !!"));
}

static int myCallbackFn1(void * pData)
{
	if (isInsertActive())
	{
		acedCommandC(&myCallbackFn1, NULL, RTSTR, PAUSE, RTNONE); 
		return 1;
	}
	
	InsertBlock2();

	return 0;
}

static int myCallbackFn2(void * pData)
{
	if (isInsertActive())
	{
		acedCommandC(&myCallbackFn2, NULL, RTSTR, PAUSE, RTNONE); 
		return 1;
	}

	CallWhenDone();

	return 0;
}

static Adesk::Boolean isInsertActive() 
{ 
	struct resbuf rb; 
	acedGetVar(_T("CMDNAMES"),&rb); 
	if (_tcsstr(rb.resval.rstring, _T("INSERT"))) 
		return Adesk::kTrue; 

	return Adesk::kFalse; 
} 

 

Regards,

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

Message 7 of 8
thierry_prince
in reply to: Balaji_Ram

Hi Balaji,

 

Thanks again for your answer.

 

Finaly, the only important thing to know is if the use of acedCommandC() can be synchronous.

If yes, that allow us to write something from your main function like :

static void AdskMyTestCommand(void)
{
  acedCommandC(&myCallbackFn1, NULL,
               RTSTR, ACRX_T("_-INSERT"),
               RTSTR, ACRX_T("TestBlk1"),
               RTNONE); 

  // Next we process the inserted blocks
  DoSomethingWithTheInserts();
}

and to be sure that the call to DoSomethingWithTheInserts() will be done after the acedCommandC() function and all its callbacks will be processed.

 

If not, then the acedCommandC() function will be "dramaticly useless".

And in this case we should have many work to replace its use.

 

Cheers,

 

Thierry

 

Message 8 of 8
Balaji_Ram
in reply to: thierry_prince

Hi Thierry,

 

Sorry, there is no way to make it synchronous. The acedCommand in earlier versions were also not synchronous when using pause.

Since you could loop to send the pause token, the rest of the code after the while loop did not execute making it look synchronous.

 

In acedCommandC, a callback is provided specifically for letting AutoCAD pass control to our plugin after the input is provided.

It is only in the callback method that you recognise the end of the command.

 

The sample code that I posted in my previous reply can help to execute commands in a sequence. 

 

But I agree this is a lot of migration work.

 

Regards,

Balaji 

 



Balaji
Developer Technical Services
Autodesk Developer Network

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

Post to forums  

Autodesk Design & Make Report

”Boost