Invoke a function after object rotation

Invoke a function after object rotation

Anonymous
Not applicable
11,780 Views
46 Replies
Message 1 of 47

Invoke a function after object rotation

Anonymous
Not applicable

Hi to all,

I'd like to have a block that when The user rotate the block I can call automatically a custom function and print of how much degrees is rotated. Could you give me some examples or idea ? 

 

Best Regards,

Marco

0 Likes
Accepted solutions (2)
11,781 Views
46 Replies
Replies (46)
Message 41 of 47

Alexander.Rivilis
Mentor
Mentor

@Anonymous wrote:

Hi @Alexander.Rivilis,

could you show me an online sample of if statement using acedGetCommandForDocument ?

 

Than you,

Marco


What about to read ObjectARX Documents?

2020-09-28_17-14-34.png

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

0 Likes
Message 42 of 47

Anonymous
Not applicable

Thank you @Alexander.Rivilis , I appreciated very much your help. Sorry I'm not an Autocad developer, I'm Studing for my thesis ObjectArx. I didn't know that this guide was in the autocad folder. 

 

You have been very kind and I thank you for helping me.

 

Marco

0 Likes
Message 43 of 47

Alexander.Rivilis
Mentor
Mentor

@Anonymous wrote:

Thank you @Alexander.Rivilis , I appreciated very much your help. Sorry I'm not an Autocad developer, I'm Studing for my thesis ObjectArx. I didn't know that this guide was in the autocad folder. 

 

You have been very kind and I thank you for helping me.

 

Marco


This guide is a part of ObjectARX SDK (docs folder):

 

2020-09-28_17-28-25.png

 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 44 of 47

Anonymous
Not applicable

Hi @Alexander.Rivilis ,

 

I've downloaded your code but the transformBy() function is not called anytime by AutoCAD. I tried a breakpoint on the function but the code execution never stop on this bp. I think that the code has no effect on my AutoCAD.

I'm attaching my code if you can help me.

 

P.S. thank you to @moogalm for the .bat script

 

Best Regards,

Marco

0 Likes
Message 45 of 47

Alexander.Rivilis
Mentor
Mentor

@Anonymous 

Test attached code and see this video.

 

 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

0 Likes
Message 46 of 47

Anonymous
Not applicable

Hi @Alexander.Rivilis now it's working, thank you.

 

I'm trying to set an Xdata with the theta calculated by the matrix as you mentioned before.

 

static void setLayoutAttribute(AcDbEntity* pSubject,double theta) // brefCar must be open for write
  {
	  AcDbObjectId objId = pSubject->objectId();
	  AcDbObjectPointer<AcDbBlockReference>  brefWheel(objId, AcDb::kForWrite);

	  if (brefWheel.openStatus() == Acad::eOk)
	  {
		  LPCWSTR myAppName = L"LAYOUT";
		  acdbRegApp(myAppName); // Make sure your XData appname is registered

		  resbuf *rb = acutBuildList(
			  AcDb::kDxfRegAppName, myAppName,
			  AcDb::kDxfXdReal, theta,
			  0
		  );

		  brefWheel->setXData(rb);

		  acutRelRb(rb); // release the list.
	  }

	  
  }

 

 

But calling this function from transorfmBy()  the blockreference is nevere in openStatus() == eOk.

 

 ACDBCORE2D_PORT virtual Acad::ErrorStatus transformBy(AcDbEntity* pSubject, const AcGeMatrix3d& xform)
  {
    AcString pGlobalCmdName;
    acedGetCommandForDocument(curDoc(), pGlobalCmdName);
    acutPrintf(L"\nTransformBy Command name: %s", pGlobalCmdName.kTCharPtr());
	

	if (pGlobalCmdName.compareNoCase(L"ROTATE") == 0) {
		double theta;
		AcGeVector3d vectors;
		getAngleAndAxis(theta, vectors,xform);

		acutPrintf(L"Rotazione di : %f radianti", theta);
		setLayoutAttribute(pSubject, theta);


	}

 

I'm missing something ? 

 

 

B.R.

 

Marco

0 Likes
Message 47 of 47

Alexander.Rivilis
Mentor
Mentor

pSubject is opened before calling setLayoutAttribute(...) So you not need to open it again:

 

static void setLayoutAttribute(AcDbEntity* pSubject, double theta)
{
  bool wasWriteEnabled = pSubject->isWriteEnabled();
  if (wasWriteEnabled || pSubject->upgradeOpen() == Acad::eOk)
  {
    LPCWSTR myAppName = L"LAYOUT";
    acdbRegApp(myAppName); // Make sure your XData appname is registered

    resbuf* rb = acutBuildList(
      AcDb::kDxfRegAppName, myAppName,
      AcDb::kDxfXdReal, theta,
      0
    );
    pSubject->setXData(rb);
    acutRelRb(rb); // release the list.
    if (!wasWriteEnabled) pSubject->downgradeOpen();
  }
}

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

0 Likes