On 07/08/2017 at 08:35, xxxxxxxx wrote:
I have a pretty basic question:
I have a plugin that uses a dialog to get some values and then creates a bunch of objects in the current scene from data it loads externally. You might call it an import plugin.
This sounds like it should probably be a "Tool" plugin?
I coded it as a Tool plugin (RegisterToolPlugin) and it kind of works, but there is the kind of weird question on how to indicate back to Cinema when the plugin has done it's work and should give control back to Cinema. Right now, after it imports everything and the import is done, the cursor remains stuck with the icon of the plugin and I can't interact with the objects just imported.
I'm clearly missing something...
Here's the code if anybody has the nerves to have a quick look:
import c4d
import os
import time
import array
import csv
import string
from c4d import gui, plugins, bitmaps, utils
from math import radians, atan2, asin, degrees, pi
PLUGIN_ID = 1039683
UI_LABEL = 10000
UI_FILENAME = 10001
UI_FILEDIALOG = 10002
UI_CHECKDEBUG = 10003
UI_CHECKLIMIT = 10004
UI_GO = 10005
UI_PROGRESS = 10006
UI_PROGRESSSUB = 10007
#The actual routine to import an ADT
def file_len(fname) :
with open(fname) as f:
for i, l in enumerate(f) :
pass
return i + 1
def objfile_has_geometry(fname) :
with open(fname) as f:
for l in iter(f) :
if(l.startswith("v")) :
return True
return False
def escape_pressed() :
bc = c4d.BaseContainer()
rs = gui.GetInputState(c4d.BFM_INPUT_KEYBOARD, c4d.KEY_ESC, bc)
if rs and bc[c4d.BFM_INPUT_VALUE]:
if(gui.QuestionDialog("Stop Script and Abort Import?")) :
return True
else:
return False
return False
def ADTImport(filepath, debug, limit, dialog) :
... (long routine to parse the file supplied)
return True
class SettingsDialog(gui.SubDialog) :
#Dialog Stuff
def CreateLayout(self) :
self.AddStaticText(id=UI_LABEL, flags=c4d.BFH_LEFT, initw=200, name="ADT File to Import")
self.AddEditText(id=UI_FILENAME, flags=c4d.BFH_SCALEFIT, initw=400, inith=10)
self.AddButton(id=UI_FILEDIALOG, flags=c4d.BFH_CENTER|c4d.BFH_SCALEFIT, name="Open File Browser")
self.AddCheckbox(id=UI_CHECKDEBUG, flags=c4d.BFH_LEFT, initw=200, inith=10, name="Debug Mode")
self.AddCheckbox(id=UI_CHECKLIMIT, flags=c4d.BFH_LEFT, initw=200, inith=10, name="Limit Parsing to first few objects")
self.AddButton(id=UI_GO, flags=c4d.BFH_CENTER|c4d.BFH_SCALEFIT, name="Start")
self.AddCustomGui(id=UI_PROGRESS, pluginid=c4d.CUSTOMGUI_PROGRESSBAR, name="Progress Bar", flags=c4d.BFH_SCALEFIT, minw=200, minh=10)
self.AddCustomGui(id=UI_PROGRESSSUB, pluginid=c4d.CUSTOMGUI_PROGRESSBAR, name="Progress Sub Bar", flags=c4d.BFH_SCALEFIT, minw=200, minh=10)
return True
def InitValues(self) :
self.SetBool(UI_CHECKDEBUG, False)
self.SetBool(UI_CHECKLIMIT, True)
return True
def Command(self, id, msg) :
if(id == UI_FILEDIALOG) :
self.SetString(UI_FILENAME, c4d.storage.LoadDialog(c4d.FILESELECTTYPE_SCENES, "Select ADT to import", c4d.FILESELECT_LOAD, "obj", "E:\Temp\Location\world\maps\ruinsoftheramore", "ruinsoftheramore_40_39.obj"))
if(id == UI_GO) :
if(self.GetString(UI_FILENAME)) :
ADTImport(self.GetString(UI_FILENAME), self.GetBool(UI_CHECKDEBUG), self.GetBool(UI_CHECKLIMIT), self)
return True
class AIP(plugins.ToolData) :
#Plugin Stuff
def __init__(self) :
self.data = dict() #container
def AllocSubDialog(self, bc) :
return SettingsDialog(self.data) #always return new instance(self.data)
if __name__ == "__main__":
bmp = bitmaps.BaseBitmap()
dir, file = os.path.split(__file__)
fn = os.path.join(dir, "res", "Icon.tif")
bmp.InitWith(fn)
if(plugins.RegisterToolPlugin(id=PLUGIN_ID, str="ADT Import",info=0, icon=bmp, help="ADT Import",dat=AIP())) :
print "ADT Import v0.1 initialized."