Skip to content

Commit

Permalink
Replace materials upon upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
celentes committed Jun 14, 2020
1 parent 10de2c7 commit 7d1fb17
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
15 changes: 14 additions & 1 deletion UI.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ def get_directory_hints_c4d():
[tf_list.extend(get_material_texture_paths_c4d(m)) for m in mats]
return get_directory_hints(tf_list)

def replace_material(doc, oldmat, newmat):
ID_MATERIAL_TAG = 5616
objects = [x for x in doc.GetObjects() if x.GetTag(ID_MATERIAL_TAG)[c4d.TEXTURETAG_MATERIAL] == oldmat]
for x in objects:
x.GetTag(ID_MATERIAL_TAG)[c4d.TEXTURETAG_MATERIAL] = newmat
oldmat.Remove()

SCROLLGRP_MAIN=500
BTN_SCAN_MATERIALS=1000
GRP_CONTROL=1001
GRP_CHANGE_DIR=2000
Expand Down Expand Up @@ -116,8 +124,10 @@ def CreateLayout(self):
self.SetTitle("Photobash Material Converter")
self.AddButton(BTN_SCAN_MATERIALS, c4d.BFH_SCALEFIT, name="Scan materials")

#self.ScrollGroupBegin(id=SCROLLGRP_MAIN, flags=c4d.BFH_SCALEFIT, inith=120, scrollflags=c4d.SCROLLGROUP_VERT)
self.GroupBegin(id=GRP_CONTROL,flags=c4d.BFH_SCALEFIT,cols=1)
self.GroupEnd()
#self.GroupEnd()

return True

Expand Down Expand Up @@ -234,9 +244,12 @@ def Command(self, id, msg):
if id == BTN_UPGRADE:
ids = self.selected_material_ids()
mats = [self.materials[i] for i in ids]
doc = c4d.documents.GetActiveDocument()
for m in mats:
self.rnd.upgrade_material(m, [self.directory])
newmat = self.rnd.upgrade_material(m, [self.directory])
replace_material(doc, m, newmat)
c4d.EventAdd(c4d.EVENT_FORCEREDRAW)
self.AskClose()

if id == SG_TEXTURE_DIR:
self.texture_dir_hide = not self.texture_dir_hide
Expand Down
9 changes: 1 addition & 8 deletions photobash_material_converter.pyp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,7 @@ class PBMC_CommandData(c4d.plugins.CommandData):
if self.dialog is None:
self.dialog = UI.PBMC_Dialog()

return self.dialog.Open(c4d.DLG_TYPE_ASYNC, pluginid=PLUGIN_ID, defaultw=300, defaulth=500, xpos=-2, ypos=-2)

def RestoreLayout(self, sec_ref):
if self.dialog is None:
self.dialog = UI.PBMC_Dialog()

return self.dialog.Restore(pluginid=PLUGIN_ID, secret=sec_ref)

return self.dialog.Open(c4d.DLG_TYPE_MODAL_RESIZEABLE, pluginid=PLUGIN_ID, defaultw=300, defaulth=500, xpos=-2, ypos=-2)

# Execute main()
if __name__=='__main__':
Expand Down

0 comments on commit 7d1fb17

Please sign in to comment.