get selection poligon vertex and perform a scaling



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 26/08/2011 at 03:09, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   12 
    Platform:      
    Language(s) :   C.O.F.F.E.E  ;

    ---------
    I'm using c.o.f.f.e.e. (no pytohon, no c++) i'm in polygon mode i would to do these things:

    1. enable menu plugin if the user is in polygon mode and has selected a poligon
    2. get all the list of polygon selected
    3. then perform a scaling but only for the X axis
       
      very big thanks!


  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 30/08/2011 at 09:42, xxxxxxxx wrote:

    The state of the menu entry is controled via the MenuPlugin::GetState method. Override it for your own plugins. The other points are explained in my example.

      
    class MPPlugin : MenuPlugin  
    {  
      public:  
          MPPlugin();  
      
          GetID();  
          GetName();  
          GetState();  
            
          GetHelp();  
          Execute(doc);  
    }  
      
    MPPlugin::MPPlugin()  
    {  
      super();  
    }  
      
    MPPlugin::GetID()  
    {  
      return 1001150;  
    }  
      
    MPPlugin::GetState()  
    {  
      var doc = GetActiveDocument();  
      if (!doc) return 0;  
        
      // is polygon mode checked  
      if (!IsCommandChecked(12187)) return 0;  
      
      // is there an selected object and is it a polygon object  
      var op = doc->GetActiveObject();  
      if (!op || op->GetType() != Opolygon) return 0;  
        
      // is at least one polyogn selected  
      var sel = op->GetPolygonSelection();  
      if (sel->GetCount() == 0) return 0;  
        
      return CMD_ENABLED;  
    }  
      
    MPPlugin::GetName()  
    {  
      return "Scale Test";  
    }  
      
    MPPlugin::GetHelp()  
    {  
      return "Scale Test";  
    }  
      
      
    MPPlugin::Execute(doc)  
    {  
      var op = doc->GetActiveObject();  
      if (!op || op->GetType() != Opolygon) return 0;  
        
      var sel = op->GetPolygonSelection();  
      if (sel->GetCount() == 0) return;  
      
      var fcnt = op->GetPolygonCount();  
      var vcnt = op->GetPointCount();  
        
      // create a vertex index array to store selection states for vertices of selected polygons  
      var vidx = new(array,vcnt);  
      if (!vidx) return;  
        
      var i = 0;  
        
      // initialize the array  
      for (i=0; i<vcnt; i++)  
      {  
          vidx[i] = FALSE;  
      }  
        
      // converts polygon selection into point selection  
      for (i=0; i<fcnt; i++)  
      {  
          if (sel->IsSelected(i))  
          {  
              var poly = op->GetPolygon(i);  
              vidx[poly->a] = TRUE;  
              vidx[poly->b] = TRUE;  
              vidx[poly->c] = TRUE;  
              vidx[poly->d] = TRUE;        }  
      }  
        
      // go through the vertices and do something (e.g scale)  
      for (i=0; i<vcnt; i++)  
      {  
          if (vidx[i])  
          {  
              var vertex = op->GetPoint(i);  
                
              // do something with vertex  
              vertex.x *= 5.0;  
              //vertex.y *= 2.0;  
              //vertex.z *= 3.0;   
                
              op->SetPoint(i, vertex);  
          }  
      }  
        
      // must be called for object and editor update  
      op->Message(MSG_UPDATE);  
      EventAdd();  
    }  
      
      
    main()  
    {  
      Register(MPPlugin);  
    }  
    

    cheers,
    Matthias


Log in to reply