Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Get Point selection tag center

    Cinema 4D SDK
    c++ r21
    2
    7
    863
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • N
      Neekoe
      last edited by

      Hi Guys:
      I don't see the point position data that can be returned in "gettagdata",I hope I can get the center position of the selected point or point group. At present, I have set a link window in the dialog box. I hope I can drag my point group label to reach the link, and then calculate a center according to the linked point group (similar to forming a new bound and then getting the center). Plz
      Thank you```
      .....

      case IDC_LINKBOX2 :
      {
      GePrint("aaa"_s);
      // Test can get response
      break;
      }

      1 Reply Last reply Reply Quote 0
      • ManuelM
        Manuel
        last edited by

        Hi,

        you must retrieve the BaseSelect from the tag with GetBaseSelect and check every point if they are selected or not and calculate the mean.
        You also must retrieve the object the tag is attached to and the point positions. This can be done with GetObject and GetPointR. In that case, I am using GetPointR because i do not want to modify the values.

        // get point selection tag
        LinkBoxGui* linkGui = static_cast<LinkBoxGui*>(FindCustomGui(IDC_LINKBOX2, CUSTOMGUI_LINKBOX));
        if (linkGui == nullptr)
        	return false;
        BaseDocument* doc = GetActiveDocument();
        if (doc == nullptr)
        	return false;
        SelectionTag* selectionTag = (SelectionTag*)linkGui->GetLink(doc);
        if (selectionTag == nullptr)
        {
        	ApplicationOutput("the field is empty");
        	return true;
        }
        // stop if the selection tag is not a point selection but we still return true
        if (!selectionTag->IsInstanceOf(Tpointselection))
        	return true;
        
        PointObject* op = ToPoly(selectionTag->GetObject());
        if (op == nullptr)
        	return false;
        const Vector* padr = op->GetPointR();
        const Int32 pointCount = op->GetPointCount();
        BaseSelect* selection = selectionTag->GetBaseSelect();
        // use the LminMax class to retrieve selection information
        
        
        // calculate the mean of all points
        Vector mean;
        for (Int32 pointIndex = 0; pointIndex < pointCount; pointIndex++)
        {
        	if (selection->IsSelected(pointIndex))
        		mean += padr[pointIndex];
        }
        mean /= selection->GetCount();
        
        ApplicationOutput(" mean is @", mean);
        
        return true;
        break;
        

        Cheers,
        Manuel

        MAXON SDK Specialist

        MAXON Registered Developer

        N 1 Reply Last reply Reply Quote 0
        • N
          Neekoe @Manuel
          last edited by

          @m_magalhaes Hi,m_magalhaes, I want to call your name again, because the last question is also your answer and has perfectly solved my problem. You are my God. Thank you very much.

          Can I ask another question? Last night, I found that my tag name may be unclear. I want to use my own name. But gettagdata is not a member of baselist2d. I tried to browse the API, but I couldn't find the answer. For example, findcustomgui, which can be clearly known in the SDK, belongs to getdialog 😥

          ManuelM 1 Reply Last reply Reply Quote 0
          • ManuelM
            Manuel @Neekoe
            last edited by

            You mean GetTagDataR or GetTagDataW?? They are part of BaseObject.

            I am not sure to follow you.

            Cheers,
            Manuel

            MAXON SDK Specialist

            MAXON Registered Developer

            N 3 Replies Last reply Reply Quote 0
            • N
              Neekoe @Manuel
              last edited by

              This post is deleted!
              1 Reply Last reply Reply Quote 0
              • N
                Neekoe @Manuel
                last edited by

                This post is deleted!
                1 Reply Last reply Reply Quote 0
                • N
                  Neekoe @Manuel
                  last edited by

                  @m_magalhaes Thank you, I think I understand

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post