Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python 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

    Melting Polygons

    Scheduled Pinned Locked Moved SDK Help
    14 Posts 0 Posters 1.2k Views
    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.
    • H Offline
      Helper
      last edited by

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

      On 20/01/2012 at 02:00, xxxxxxxx wrote:

      Thanks for your answer. I have to admit, I do not understand the behavior of COFFEE in this case.
      My code is as follows:

        if (Melt)  
      {  
       doc->SetActiveObject(poly_obj);  
       SendModelingCommand(MCOMMAND_SELECTALL,doc,poly_obj,bc,MODELINGCOMMANDMODE_POLYGONSELECTION);  
       var select = poly_obj->GetPolygonSelection();  
       println("Selected= ",select->GetCount());  
       //SendModelingCommand(  
       println("Melting");  
       SendModelingCommand(MCOMMAND_MELT,doc,poly_obj,bc,MODELINGCOMMANDMODE_POLYGONSELECTION);  
       CallCommand(ID_MODELING_MELT_COMMAND);  
       poly_obj->Message(MSG_UPDATE);  
      }    
      

      As you can see, in my script I check that the comparison is passed with println ("Melting"); and I also check that I have polygons selected.
       
      Nor the SendModelingCommand nor the CallCommand take any actions on the polygon object. If I execute the CallCommand from the console after the script has ended, it does what is expected, but not from inside the code. I think that's kind of weird, isn't it?

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

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

        On 20/01/2012 at 06:22, xxxxxxxx wrote:

        Originally posted by xxxxxxxx

        As you can see, in my script I check that the comparison is passed with println ("Melting"); and I also check that I have polygons selected.
         
        Nor the SendModelingCommand nor the CallCommand take any actions on the polygon object. If I execute the CallCommand from the console after the script has ended, it does what is expected, but not from inside the code. I think that's kind of weird, isn't it?

        If I execute your code, it works as expected. 
         
        Is "Melting" printed in the console ? i.e. do you enter in the 'if' ?
        Does your object is really an editable polygon object ?

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

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

          On 20/01/2012 at 06:54, xxxxxxxx wrote:

          Yes, I see the message "Melting" on the console and the number of selected polygons (the other print statement).
           
          When I execute the Melt command from the GUI the polygons get melted, so I believe the structure of the polygons are sound.
           
          When the script runs AND I am using Poligon Mode I even see the polygons selected on the HUD and on the display view.
           
          The only instance where I have found the GUI's melt command not to work is when on Object or Model modes. Might be COFFEE assuming I am in Model / Object mode and it does not want to melt the polygons? (Tough I have Polygon Mode selected for the GUI)

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

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

            On 20/01/2012 at 14:42, xxxxxxxx wrote:

            Originally posted by xxxxxxxx

            Yes, I see the message "Melting" on the console and the number of selected polygons (the other print statement).
             
            When I execute the Melt command from the GUI the polygons get melted, so I believe the structure of the polygons are sound.
             
            When the script runs AND I am using Poligon Mode I even see the polygons selected on the HUD and on the display view.
             
            The only instance where I have found the GUI's melt command not to work is when on Object or Model modes. Might be COFFEE assuming I am in Model / Object mode and it does not want to melt the polygons? (Tough I have Polygon Mode selected for the GUI)

            You can make sure modeling commands will be evaluated in polygon mode by forcing polygon mode with:

            CallCommand(12187); // Set Polygon mode
            
            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

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

              On 24/01/2012 at 21:04, xxxxxxxx wrote:

              I'm not beeing lucky. To reduce the possible points of error I have created a COFFEE tag with the code I'm using on the xpresso COFFEE node. It is like this:

              main(doc,op)  
              {  
               var bc = new (BaseContainer);   
               doc->SetActiveObject(op);    
               SendModelingCommand(MCOMMAND_SELECTALL,doc,op,bc,MODELINGCOMMANDMODE_POLYGONSELECTION);  
               var select = op->GetPolygonSelection();  
               println("Selected= ",select->GetCount());  
               //SendModelingCommand(  
               println("COFFEE TAG");  
               SendModelingCommand(MCOMMAND_MELT,doc,op,bc,MODELINGCOMMANDMODE_POLYGONSELECTION);  
               op->Message(MSG_UPDATE);  
              }
              

              I create a plane and make it editable. When I apply the COFFEE tag to the plane, its polygons do not get melted, though I can see the message "COFFEE TAG" on the console.
              Curiously when I am on the COFFEE code Editor and press the button execute, the polygons get melt.
              Have you got any idea about what is causing this behaviour?
              If you have any functional sample working code which works from a COFFEE tag, Xpresso COFFEE node, I would appreciate if you could post it.
              When executing the code from the console it seems to work properly but not when executed from a tag/node.
              Thanks
               
              [P.S.] I found that pressing the play animation button, after a while (10 or 12 frames) the polygons get melted when using the COFFEE Tag. Why is necessary for the script to run several times to melt the polygons? My XPresso node cannot work this way, as I am creating a polygon based on a series of user entered points, and I would need to run only once the melt command.

              1 Reply Last reply Reply Quote 0
              • H Offline
                Helper
                last edited by

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

                On 25/01/2012 at 07:18, xxxxxxxx wrote:

                Why do you really need to run the modeling commands from a tag or XPresso node ?
                Scripting tags and nodes are called for each frame.

                1 Reply Last reply Reply Quote 0
                • H Offline
                  Helper
                  last edited by

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

                  On 25/01/2012 at 09:16, xxxxxxxx wrote:

                  I've written an XPresso tag, which from a closed spline creates a polygon object. The easiest way to "untriangulate" its polygons, is to melt them. The XPresso expresion resides on a Null Object (could be anywhere else) and by dragging a spline to a User Defined Parameter of the XPresso tag, and activating a boolean User Defined Parameter, it creates the triangulated polygon.
                  The XPresso expression only runs once, because when it is called again, by checking the boolean Parameter, I know whether the function has already been executed and I exit the function. I don't need the function to run more than once. That's how C4D works. But when it runs once, it does not seem to work. I found accidentally, as the COFFEE tag does not check whether I already executed the expression or not, that if it is executed several times, eventually it works.
                  The last step I need for the expression is to "untriangulate" the created polygon...
                  Is there another way of doing this? I believe my approach is a valid one.

                  1 Reply Last reply Reply Quote 0
                  • H Offline
                    Helper
                    last edited by

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

                    On 26/01/2012 at 01:53, xxxxxxxx wrote:

                    I'm still a bit confused, are you executing the code from a COFFEE tag or an XPresso COFFEE node ?

                    1 Reply Last reply Reply Quote 0
                    • H Offline
                      Helper
                      last edited by

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

                      On 26/01/2012 at 02:32, xxxxxxxx wrote:

                      My original script runs from a XPresso COFFEE node.
                      To check functionality of the part that was not working as I expected (the melting of polygons) I put it in a COFFEE Tag. The code is above, date 24.01.
                      In any case none of both work as I was expecting.
                       
                      Does the code I added on 24.01 work for you? As I think this is the way the melting command should be called, from a COFFEE tag or from an Xpresso COFFEE node.
                      If this is not the way, any help about the sequence of statements to use would be really appreciated.

                      1 Reply Last reply Reply Quote 0
                      • H Offline
                        Helper
                        last edited by

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

                        On 26/01/2012 at 03:20, xxxxxxxx wrote:

                        Originally posted by xxxxxxxx

                        Does the code I added on 24.01 work for you? As I think this is the way the melting command should be called, from a COFFEE tag or from an Xpresso COFFEE node.
                        If this is not the way, any help about the sequence of statements to use would be really appreciated.

                        A COFFEE tag is called every time the editor is redrawn. An XPresso COFFEE node is called for every execution of the XPresso setup where the node is located.

                        Could you send an example scene to [email protected] ? I don't know how to exactly reproduce the problem (Spline user data + XPresso setup etc.).

                        1 Reply Last reply Reply Quote 0
                        • H Offline
                          Helper
                          last edited by

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

                          On 26/01/2012 at 09:10, xxxxxxxx wrote:

                          This may be a limitation/bug while sending modeling commands from a COFFEE XPresso node.
                          I don't see any error in the code. As you already told me I also tried to run it from the script manager and it works.

                          I converted the code to Python and it works from the script manager and from a Python XPresso node.
                          In case you need the code:

                          import c4d
                          from c4d import utils
                            
                          def main() :
                            
                              if Done: return
                            
                              # Create Polygon object to create all edges
                              poly_obj = c4d.BaseObject(c4d.Opolygon)
                              
                              # We need a spline object to get its points
                              if not Object.CheckType(c4d.Ospline) : return # Not a point object
                            
                              # Get number of points of the point object
                              cnt_points = Object.GetPointCount()
                            
                              # Get all point positions
                              pos_point = Object.GetAllPoints()
                            
                              # Add the number of points to the polygon
                              poly_obj.ResizeObject(cnt_points)
                            
                              # Position the points at the same place as they are at the spline
                              for i in range(0,cnt_points) :
                                  #print pos_point[i]
                                  poly_obj.SetPoint(i,pos_point[i])
                            
                              # Create polys
                              for i in range(1,cnt_points) :
                                  cnt_polys=poly_obj.GetPolygonCount()
                                  poly_obj.ResizeObject(cnt_points,cnt_polys+1)
                            
                                  # Create a polygon with the points
                                  poly_obj.SetPolygon(cnt_polys,c4d.CPolygon(0,i-1,i,i))
                              
                              poly_obj.Message(c4d.MSG_UPDATE)
                              doc.InsertObject(poly_obj)
                            
                              if Melt:
                                  bc = c4d.BaseContainer()
                                  doc.SetActiveObject(poly_obj)
                                  utils.SendModelingCommand(c4d.MCOMMAND_SELECTALL,[poly_obj],c4d.MODELINGCOMMANDMODE_POLYGONSELECTION,bc=bc,doc=doc)
                                  select = poly_obj.GetPolygonS()
                                  utils.SendModelingCommand(c4d.MCOMMAND_MELT,[poly_obj],c4d.MODELINGCOMMANDMODE_POLYGONSELECTION,bc=bc,doc=doc)
                                  poly_obj.Message(c4d.MSG_UPDATE)
                              
                              global Output1
                              Output1=True
                          
                          1 Reply Last reply Reply Quote 0
                          • H Offline
                            Helper
                            last edited by

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

                            On 26/01/2012 at 14:14, xxxxxxxx wrote:

                            Thanks a lot for the information and for the Python script.
                            Python was going to be my next step. I suppose this is a good reason to move on to Python.
                             
                            Again thanks for the code. It saves me a good time in research. 👍

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