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

    How to set project scale

    General Talk
    r20 python
    2
    6
    2.1k
    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.
    • R
      Rage
      last edited by

      Hi All,

      I'm trying to figure out how to change the Project scale and type (centimeters, meters etc etc) through python.

      I think I've to use the UnitScale class, but the documentation is a bit unclear about this class
      Reference:
      https://developers.maxon.net/docs/py/2023_2/modules/c4d/CustomDataType/UnitScaleData/index.html#c4d.UnitScaleData

      Any help?

      1 Reply Last reply Reply Quote 0
      • r_giganteR
        r_gigante
        last edited by r_gigante

        Hi Rage thanks for reaching us.

        With regard to your question, please consider that it was already discussed in the past in this thread.

        Long story short you can set the scene scale simply using

        def main():
            # check the current values for the currently active scene
            # for default scene it returns (1.0, 3) where scale is "1.0" and unit is "cm"
            print "current scale:", doc[c4d.DOCUMENT_DOCUNIT].GetUnitScale()
        
            # instantiate an UnitScaleData()
            sclData = c4d.UnitScaleData()
            # set the data accordingly to your needs
            # e.g. scale by 10x and set to mm units 
            sclData.SetUnitScale(10, c4d.DOCUMENT_UNIT_MM)
            # set the proper parameter in the active doc
            doc[c4d.DOCUMENT_DOCUNIT] = sclData
            # fire an EventAdd() 
            c4d.EventAdd()
        
            # check the new value
            print "new scale:", doc[c4d.DOCUMENT_DOCUNIT].GetUnitScale()
        

        Finally, to speed up your issues' resolution, I warmly encourage making use of the search function.

        Best, Riccardo

        1 Reply Last reply Reply Quote 3
        • R
          Rage
          last edited by

          Thanks @r_gigante for your reply

          What if I want to scale the project using the "Scale Project" button?
          I know that I can use the CallButton() function, but I don't know how to properly set the settings

          c4d.CallButton(op, c4d.DOCUMENT_SCALEDOCUMENT)

          op is a baselist containing the options for the button, right? How can I set the options (current and target scale)? I searched in the c++ documentation but all I could find is the ddoc.h with a reference to it, with no description.

          1 Reply Last reply Reply Quote 0
          • r_giganteR
            r_gigante
            last edited by

            Hi Rage, with regard to your follow up you can use the c4d.CallButton() passing, as first argument, the document you intend to change the scale of.

            Beware that using this approach, you'll be provided with a modal dialog which requires the user interaction in the end.

            Cheers, Riccardo

            1 Reply Last reply Reply Quote 0
            • R
              Rage
              last edited by

              So, to be clear, in the end I need an user to interact and I can't do it in scripting? Can I access the dialog, somehow?

              r_giganteR 1 Reply Last reply Reply Quote 0
              • r_giganteR
                r_gigante @Rage
                last edited by

                @Rage if you're looking for a solution where the user is not involved, stick to the first answer where no CallButton() was considered.
                On the contrary using it will request the user to interact since there are no means to programmatically interact with the UI or scripting users' actions on the UI.

                Best, Riccardo

                1 Reply Last reply Reply Quote 1
                • ferdinandF ferdinand forked this topic on
                • First post
                  Last post