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

    Auto fill selection tag to link

    Cinema 4D SDK
    c++ r21
    2
    4
    676
    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

      Sorry, my English is not very good. Maybe I can't describe my problem very well. I am currently learning to make a simple plug-in. I hope to select a point, click a button, and create a selection tag. This step has been completed, but I hope to automatically link to my linkbox when creating a tag (I have an "addcustomgui_linkbox").
      thank!
      1111.png

      Bool MatrixAlignDialog::CreateLayout()
      {
      	SetTitle("Matrix Align"_s);
      
      	GroupBegin(0, BFV_SCALEFIT | BFH_SCALEFIT, 2, 0, "Select Object"_s, 0);
      	{
      		GroupBorderSpace(5, 5, 5, 5);
      		GroupBorder(BORDER_GROUP_IN);
      		AddStaticText(IDC_LINKBOX1_TEXT, BFH_RIGHT | BFH_FIT, 100, 20, "Object"_s, 0);
      		AddCustomGui(IDC_LINKBOX1, CUSTOMGUI_LINKBOX, String(), BFH_SCALEFIT, 250, 10, BaseContainer());
      	}
      	GroupEnd();
      
      	GroupBegin(0, BFV_SCALEFIT | BFH_SCALEFIT, 3, 0, "Set Start Group"_s, 0);
      	{
      		GroupBorderSpace(5, 5, 5, 5);
      		GroupBorder(BORDER_GROUP_IN);
      		AddButton(IDC_BUTTON1, BFH_SCALEFIT, 150, 20, "Set Point"_s);
      		AddStaticText(IDC_LINKBOX2_TEXT, BFH_RIGHT | BFH_FIT, 100, 20, "Start Group"_s, 0);
      		AddCustomGui(IDC_LINKBOX2, CUSTOMGUI_LINKBOX, String(), BFH_SCALEFIT, 250,10, BaseContainer());
      	}
      	GroupEnd();
      
      	 GroupBegin(0, BFV_SCALEFIT | BFH_SCALEFIT, 3, 0, "Set End Group"_s, 0);
      	{
      		GroupBorderSpace(5, 5, 5, 5);
      		GroupBorder(BORDER_GROUP_IN);
      		AddButton(IDC_BUTTON2, BFH_SCALEFIT, 150, 20, "Set Point"_s);
      		AddStaticText(IDC_LINKBOX3_TEXT, BFH_RIGHT | BFH_FIT, 100, 20, "End Group"_s, 0);
      		AddCustomGui(IDC_LINKBOX3, CUSTOMGUI_LINKBOX, String(), BFH_SCALEFIT, 250, 10, BaseContainer());
      	}
      	GroupEnd();
      
      	GroupBegin(0, BFV_SCALEFIT | BFH_SCALEFIT, 3, 0, ""_s, 0);
      	{
      		GroupBorderSpace(5, 5, 5, 5);
      		GroupBorder(BORDER_GROUP_IN);
      		AddButton(IDC_BUTTON3, BFH_SCALEFIT, 150, 20, "Reset Pivot"_s);
      	}
      	GroupEnd();
      
      	return true;
      }
      Bool MatrixAlignDialog::Command(Int32 id, const BaseContainer& msg)
      {
      	switch (id)
      	{
      	case IDC_BUTTON1:
      	{
      		// run the code for IDC_BUTTON1
      		const Int32 commandID = 12552;
      			if(IsCommandEnabled(commandID))
      			{
      			CallCommand(commandID);
      			}
      		break;
      	}
      	case IDC_BUTTON2:
      	{
      		// run the code for IDC_BUTTON2
      		const Int32 commandID = 12552;
      		if (IsCommandEnabled(commandID))
      		{
      			CallCommand(commandID);
      		}
      		break;
      	}
      	case IDC_LINKBOX2:
      	{
      		// get point selection tag
      		break;
      	}
      	default:
      	{
      		break;
      	}
      	}
      	return true;
      
      1 Reply Last reply Reply Quote 0
      • ManuelM
        Manuel
        last edited by Manuel

        Hi,

        perfectly clear 🙂

        you need to retrieve the gadget itself to update it:

        • You could store a pointer in your dialog class, pointing to your gadget. That pointer would be defined to the right value when you use AddCustomGui to add your LinkBox because that function returns the gadget.
        • Or you can use FindCustomGui to retrieve the gadget of a GeDialog.

        You need to create the selection tag:

        • you can create the tag with a call command, but you need to find the active tag and add it to your LinkBox
        • you create the tag yourself and you just need to update the link box.

        I tried both methods but i would create the selection tag myself.

        witch (id)
        {
        	case IDC_BUTTON1:
        	{
        		// run the code for IDC_BUTTON1
        		/*
        		// First solution
        		const Int32 commandID = 12552;
        		if (IsCommandEnabled(commandID))
        		{
        			CallCommand(commandID);
        			LinkBoxGui* linkGui = static_cast<LinkBoxGui*>(FindCustomGui(IDC_LINKBOX2, CUSTOMGUI_LINKBOX));
        			if (linkGui == nullptr)
        				return false;
        			BaseDocument* doc = GetActiveDocument();
        			if (doc == nullptr)
        				return false;
        			BaseList2D* selectionTag = (BaseList2D*)doc->GetActiveTag();
        			if (selectionTag == nullptr)
        				return false;
        			return linkGui->SetLink(selectionTag);
        		}
        		*/
        		BaseDocument* doc = GetActiveDocument();
        		if (doc == nullptr)
        			return false;
        		BaseObject* op = doc->GetActiveObject();
        		if (op == nullptr)
        			return false;
        		BaseSelect* bs = ToPoly(op)->GetPointS();
        		if (bs == nullptr)
        			return false;
        	  SelectionTag* selectionTag = (SelectionTag*)op->MakeTag(Tpointselection);
        		BaseSelect* selectionFromTag = selectionTag->GetBaseSelect();
        		bs->CopyTo(selectionFromTag);
        		// Instead of searching for the custom gadget, a pointer could be stored in the dialog class
        		// and defined when the gadget is added in the CreateLayout function.
        		LinkBoxGui* linkGui = static_cast<LinkBoxGui*>(FindCustomGui(IDC_LINKBOX2, CUSTOMGUI_LINKBOX));
        		if (linkGui == nullptr)
        			return false;
        		EventAdd();
        
        		// Instead of returning the result of the SetLink function, one should test if it did not failed
        		// and reverse the tag creation if it did.
        		return linkGui->SetLink(selectionTag);
        
        		break;
        	}
        
        	case IDC_LINKBOX2:
        	{
        		// 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;
        		break;
        	}
        }
        

        Cheers,
        Manuel

        MAXON SDK Specialist

        MAXON Registered Developer

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

          @m_magalhaes
          Oh, no, I'm really excited. Thank you very much. I'm looking at my code in your way now
          😁

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

            @m_magalhaes
            thank you so much,you and your code is perfact
            😁

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