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

    Python Generator - How to assign a field object to a deformer

    Cinema 4D SDK
    python
    2
    6
    963
    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.
    • M
      moGRR
      last edited by moGRR

      Hi all.

      I am new to python and I'm looking for help with assigning a field object to a deformer's falloff within a Python Generator.

      So for example I set up the objects like this:

      myParentNull = c4d.BaseObject(c4d.Onull)
      myFieldObj = c4d.BaseObject(c4d.Flinear)
      myModObj = c4d.BaseObject(1021280) #1021280 = Squash And Stretch Deform Object
      myFieldObj.InsertUnder(myParentNull)

      ... I then hoped that this would achieve what I was after, but it looks like this isn't the way to assign the field object (it doesn't work)

      myModObj[c4d.FIELDS] = myFieldObj

      Can anyone help?

      Many thanks,
      Jamie
      www.moGRR.co.uk

      1 Reply Last reply Reply Quote 0
      • P
        PluginStudent
        last edited by PluginStudent

        The FIELDS parameter stores a FieldList object. You have to add your field to that field list.

        fieldList = op[c4d.FIELDS]
        
        layer = c4d.modules.mograph.FieldLayer(c4d.FLfield)
        layer.SetLinkedObject(field)
        fieldList.InsertLayer(layer)
        
        op[c4d.FIELDS] = fieldList
        c4d.EventAdd()
        

        See FieldList Manual, c4d.FieldList, c4d.modules.mograph.FieldLayer

        1 Reply Last reply Reply Quote 1
        • M
          moGRR
          last edited by Manuel

          Thanks for the reply Plugin Student.

          Having a FieldList makes sense. I was kind of looking for something along those lines.

          I've tried incorporating your code into my python generator and I'm getting this error with the .InsertLayer line:
          AttributeError: 'NoneType' object has no attribute 'InsertLayer'

          Maybe I'm misunderstanding how the fieldlist and layers work? Here is the Python Generator code I am getting that error with:

          import c4d
          #Welcome to the world of Python
          
          
          def main():
              myParentNull = c4d.BaseObject(c4d.Onull)
          
              myDefObj = c4d.BaseObject(1021280) #1021280 = Squash And Stretch Deform Object
              myDefObj.InsertUnder(myParentNull)
          
              myFieldNull = c4d.BaseObject(c4d.Onull)
              myFieldNull.InsertUnder(myParentNull)
          
              myFieldObj = c4d.BaseObject(c4d.Flinear)
              myFieldObj.InsertUnder(myFieldNull)
          
              myFieldList = myDefObj[c4d.FIELDS]
              
              myFieldLayer = c4d.modules.mograph.FieldLayer(c4d.FLfield)
              myFieldLayer.SetLinkedObject(myFieldObj)
              myFieldList.InsertLayer(myFieldLayer)
          
              c4d.EventAdd()
              return(myParentNull)
          
          1 Reply Last reply Reply Quote 0
          • P
            PluginStudent
            last edited by

            Well,

            myFieldList = myDefObj[c4d.FIELDS]
            

            seems to return None.

            I guess you can create a field list and use that list:

            myFieldList = c4d.FieldList()
            

            Also, do not call c4d.EventAdd() in a Python Generator.

            1 Reply Last reply Reply Quote 0
            • M
              moGRR
              last edited by Manuel

              Thanks again Plugin Student.

              I wasn't too sure if I should have an EventAdd in a Python Generator or not, so thanks for clearing that up.

              So this is the code I now have, but it still isn't successfully adding the FieldList to the Deformer object:

              import c4d
              #Welcome to the world of Python
              
              
              def main():
                  myParentNull = c4d.BaseObject(c4d.Onull)
              
                  myDefObj = c4d.BaseObject(1021280) #1021280 = Squash And Stretch Deform Object
                  myDefObj.InsertUnder(myParentNull)
              
                  myFieldNull = c4d.BaseObject(c4d.Onull)
                  myFieldNull.InsertUnder(myParentNull)
              
                  myFieldObj = c4d.BaseObject(c4d.Flinear)
                  myFieldObj.InsertUnder(myFieldNull)
              
                  myFieldLayer = c4d.modules.mograph.FieldLayer(c4d.FLfield)
                  myFieldLayer.SetLinkedObject(myFieldObj)
              
                  myFieldList = c4d.FieldList()
                  myFieldList.InsertLayer(myFieldLayer)
              
                  return(myParentNull)
              
              1 Reply Last reply Reply Quote 0
              • M
                moGRR
                last edited by

                Oops - I forgot to have the following line:

                myDefObj[c4d.FIELDS] = myFieldList
                

                It all works perfectly now. Thanks again for your help @PluginStudent

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