I want to get the coordinates of the points I have selected "en"



  • User Information:
    Cinema 4D Version: 21.115
    Platform: Windows ;
    Language(s) : C++ ;
    I've converted objects to polygons,
    And selected a point

    And print out the serial number of these points

    How can I get the coordinates of these points

    Here's my code

    BaseDocument*doc = GetActiveDocument();
    
    BaseObject * obj1 = doc->GetActiveObject();
    
    if (obj1->GetType()!= Opolygon)
    		{
    			break;
    		}
    PointObject *slpoint = ToPoint(obj1);
    BaseSelect *pointsel = slpoint->GetPointS();
    		
    			
    
    Int32 seg = 0, i, a, b;
    while (pointsel->GetRange(seg++, LIMIT <Int32> ::MAX,&a,&b))
    		{
    			for ( i = a; i < b; i++)
    			{
    				
    				ApplicationOutput("aa: @"_s, i);
    
    			}
    
    			
    		}
    


  • hello,

    For your next threads, please help us keeping things organised and clean.

    I've added the tags and marked this thread as a question so when you considered it as solved, please change the state :)

    you can use GetPointR to retrieve the points array pointer.

    You will retrieve the point in object position so you have to multiply by the matrix of the object to retrieve the world coordinate of the point.

    Watch out that your range could have only one point so be careful with the condition of the for loop and use inforior or equal to b

    for (i=a; i<=b; ++i)
    

    Something like this will work

            PointObject *slpoint = ToPoint(obj1);
    	BaseSelect *pointsel = slpoint->GetPointS();
    	const maxon::Vector* padr = slpoint->GetPointR();
    	const maxon::Matrix opmg = slpoint->GetMg();
    
    	Int32 seg = 0, i, a, b;
    	while (pointsel->GetRange(seg++, LIMIT<Int32>::MAX, &a, &b))
    	{
    		for (i = a; i <= b; i++)
    		{
    			const maxon::Vector pointPosition = padr[i];
    			const maxon::Vector worldPointPosition = opmg * pointPosition ;
    
    			ApplicationOutput("aa index : @, object position @, wordl position @", i, pointPosition, worldPointPosition);
    
    		}
    
    
    	}
    
    
    

    Cheers
    Manuel



  • @m_magalhaes
    非常感谢
    我用另外一个办法解决了不用求矩阵
    代码如下

    PointObject *slpoint = ToPoint(obj1); //转换为点对象
    		BaseSelect *pointsel = slpoint->GetPointS();//获取选择的点
    
    		Int32 pointConst = slpoint->GetPointCount();//获取所有的点
    		Vector *points = slpoint->GetPointW();//获取所有点的坐标
    		Vector pt;
    		Int32 i;
    		for (i = 0; i < pointConst; i++)//利用for循环来不断读取所有点的数据
    		{
    			if (pointsel->IsSelected(i))//来判断当前的点是否选择住
    			{
    				pt += points[i];//若果选择 所有向量相加
    			}
    		}
    


  • @m_magalhaes
    I'll write it in your way

    Thank you very much.

    Cheers!