Skip to content

Instantly share code, notes, and snippets.

@MikeUdin
Last active February 28, 2018 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MikeUdin/57658383c536bb44eacafbffc218d787 to your computer and use it in GitHub Desktop.
Save MikeUdin/57658383c536bb44eacafbffc218d787 to your computer and use it in GitHub Desktop.
Grouping objects in Cinema 4D
import c4d
from c4d import gui
# Welcome to the world of Python
# Author: Mike Udin,
# Tutorial here http://mikeudin.net/2018/02/28/cinema-4d-python-grouping/
# 2018
def main():
obs = doc.GetActiveObjects(0)
if not obs:
gui.MessageDialog('Please select some objects!')
return
if len(obs) == 1:
nullm = obs[0].GetMg()
else:
nullm = c4d.Matrix()
nullm.off = sum([ob.GetMg().off for ob in obs])/ len(obs)
doc.StartUndo()
null = c4d.BaseObject(c4d.Onull)
null.InsertBefore(obs[0])
doc.AddUndo(c4d.UNDOTYPE_NEW, null)
null.SetBit(c4d.BIT_ACTIVE)
null.SetMg(nullm)
for ob in obs:
m = ob.GetMg()
doc.AddUndo(c4d.UNDOTYPE_HIERARCHY_PSR, ob)
ob.InsertUnderLast(null)
ob.DelBit(c4d.BIT_ACTIVE)
ob.SetMg(m)
doc.EndUndo()
c4d.EventAdd()
if __name__=='__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment