How to set project scale
-
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.UnitScaleDataAny help?
-
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
-
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 settingsc4d.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.
-
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
-
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?
-
@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
-