Author Topic: Cannot get a projected point exactly and send it to Autocad 's Command  (Read 619 times)

0 Members and 1 Guest are viewing this topic.

lethuongtri

  • Mosquito
  • Posts: 14
Goodmorning everyone, I 'm a newbie and i have a question.  I tried to create a simple align command for X /Y direction by finding the projected point and moving entities by this point. The source code is like below . Please see it.

firstly , I tried it with X direction.But the resuilt pt1T 's value seemed that became " the closest endpoint" or "the closet Intersection point"  . I also tried with putting the system variable "OSMODE" to 0 but It 's not Work.

I attached the image . Please see it.

Thanks in advance.
Code - C++: [Select]
  1. void
  2. cmdAXY()
  3. {
  4.     ads_name ss;
  5.     TCHAR Kw[10];
  6.     int rc;
  7.     rc = acedSSGet(NULL, NULL, NULL, NULL, ss);
  8.     if (rc != RTNORM) return;
  9.  
  10.     acedInitGet(1, _T("X Y"));
  11.     acedGetKword(_T("\nAlign Direction:<X/Y>"), Kw);
  12.  
  13.     //Khai báo, &#273;&#7883;nh ngh&#297;a g&#7889;c 0 UCS
  14.     ads_point pt0,pt1,pt2,pt1T;
  15.     pt0[0] = 0;
  16.     pt0[1] = 0;
  17.     pt0[2] = 0;
  18.  
  19.     //&#272;&#7883;nh ngh&#297;a pt1
  20.     acedInitGet(1,NULL);
  21.     rc = acedGetPoint(pt0, _T("\n Select the first point:"), pt1);
  22.     if (rc != RTNORM) return;
  23.  
  24.     //&#272;&#7883;nh ngh&#297;a pt2:
  25.     acedInitGet(1, NULL);
  26.     rc = acedGetPoint(pt1, _T("\n Select the second point:"), pt2);
  27.     if (rc != RTNORM) return;
  28.  
  29.     struct resbuf* cmdlist;
  30.     if (_tcscmp(Kw, _T("X")) == 0)
  31.     {
  32.         pt1T[0] = pt1[0];
  33.         pt1T[1] = pt2[1];
  34.         pt1T[2] = pt1[2];
  35.     }
  36.     else
  37.     {
  38.         pt1T[0] = pt2[0];
  39.         pt1T[1] = pt1[1];
  40.         pt1T[2] = pt1[2];
  41.     }
  42.     cmdlist = acutBuildList(RTSTR, _T(".move"), RTSTR, _T("P"),RTSTR,_T(""),RTPOINT
  43.         , pt1, RTPOINT, pt1T, 0);
  44.  
  45.     acedCmdS(cmdlist);
  46.     acutRelRb(cmdlist);
  47.     acedSSFree(ss);
  48. }


It's Alive!

  • Retired
  • Needs a day job
  • Posts: 7300
  • AKA Daniel
Re: Cannot get a projected point exactly and send it to Autocad 's Command
« Reply #1 on: January 15, 2022, 07:11:23 PM »
RT3DPOINT instead of RTPOINT?
Retired

lethuongtri

  • Mosquito
  • Posts: 14
Re: Cannot get a projected point exactly and send it to Autocad 's Command
« Reply #2 on: January 16, 2022, 02:26:19 AM »
Thank for your reply . I tried it too but it didn't work.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 7300
  • AKA Daniel
Re: Cannot get a projected point exactly and send it to Autocad 's Command
« Reply #3 on: January 16, 2022, 03:46:09 AM »
maybe try not using the move command

Code - C: [Select]
  1.     static void ArxBrxTest_doit()
  2.     {
  3.         ads_name ss{ 0L, 0L };
  4.         TCHAR Kw[10] = { 0 };
  5.         int rc;
  6.         rc = acedSSGet(NULL, NULL, NULL, NULL, ss);
  7.         if (rc != RTNORM) return;
  8.  
  9.         acedInitGet(1, _T("X Y"));
  10.         acedGetKword(_T("\nAlign Direction:<X/Y>"), Kw);
  11.  
  12.         AcGePoint3d pt1, pt2, pt1T;
  13.         acedInitGet(1, NULL);
  14.         rc = acedGetPoint(NULL, _T("\n Select the first point:"), asDblArray(pt1));
  15.         if (rc != RTNORM) return;
  16.  
  17.         acedInitGet(1, NULL);
  18.         rc = acedGetPoint(asDblArray(pt1), _T("\n Select the second point:"), asDblArray(pt2));
  19.         if (rc != RTNORM) return;
  20.  
  21.         AcGePlane plane;
  22.         if (_tcscmp(Kw, _T("X")) == 0)
  23.             plane.set(pt1, AcGeVector3d::kYAxis);
  24.         else
  25.             plane.set(pt1, AcGeVector3d::kXAxis);
  26.  
  27.         pt1T = plane.closestPointTo(pt2);
  28.  
  29.         AcGeMatrix3d xform = AcGeMatrix3d::translation(pt2 - pt1T);
  30.  
  31.         AcDbObjectIdArray ids;
  32.         acedGetCurrentSelectionSet(ids);
  33.         for (auto id : ids)
  34.         {
  35.             if (AcDbEntityPointer pEnt(id, AcDb::kForWrite); pEnt.openStatus() == eOk)
  36.                 pEnt->transformBy(xform);
  37.         }
  38.         acedSSFree(ss);
  39.     }
  40.  
  41.  
Retired

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 7300
  • AKA Daniel
Re: Cannot get a projected point exactly and send it to Autocad 's Command
« Reply #4 on: January 16, 2022, 03:51:21 AM »
though you may need to transform to a UCS
Retired

lethuongtri

  • Mosquito
  • Posts: 14
Re: Cannot get a projected point exactly and send it to Autocad 's Command
« Reply #5 on: January 16, 2022, 09:40:25 AM »
Thank for your reply . Finally, it worked .

I have some question about your code
     "ads_name ss{ 0L, 0L };
     TCHAR Kw[10] = { 0 };"   ->   {0L,0L} and {0} is what ?  and why do we use it ?

I guess it related to "string may not zero terminated" warning but i 'm not sure .

Thanks in advance.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 7300
  • AKA Daniel
Re: Cannot get a projected point exactly and send it to Autocad 's Command
« Reply #6 on: January 16, 2022, 05:10:00 PM »
Glad it works : )

I just try to get in the habit of initializing variables, sometimes I forget, I missed rc

Uninitialized variables make a program non-deterministic. Each time the program runs, it may behave differently.
Probably not an issue in this case
Retired

lethuongtri

  • Mosquito
  • Posts: 14
Re: Cannot get a projected point exactly and send it to Autocad 's Command
« Reply #7 on: January 22, 2022, 07:32:01 AM »
Thanks you alot . I got it .