On 23/03/2013 at 16:16, xxxxxxxx wrote:
Hello everybody,
i think its a bit difficulte to explain what I want, but Ill try to do my best. I wrote a tagdata to be able to work with large data tables. The result of the the tagdata is the variable list_.
import os
import sys
import c4d
from c4d import plugins, utils, bitmaps, gui
import datetime
# be sure to use a unique ID obtained from www.plugincafe.com
PLUGIN_ID = 10000045 #TEST ID
def ValInType(o_val) :
val = o_val
if "," in o_val: o_val = o_val.replace(",", ".")
try: return float(o_val)
except ValueError: return str(val)
class PlgTAG(plugins.TagData) :
list_ = []
def Init(self, node) :
return True
def Message(self, node, type, data) :
if type==c4d.MSG_DESCRIPTION_COMMAND:
if data['id'][0].id==10002:
self.LoadList(node)
self.GetVal(node)
self.FillPorts(node)
return True
def LoadList(self, op) :
try: txt = open(op[10001], 'r')
except IOError:
gui.MessageDialog("File is not readable.")
return
lns = txt.readlines()
txt.close()
self.list_ = []
self.lncnt = len(lns)
ccnt = 0
for ln in lns:
cols = ln.split(";")
if ccnt < len(cols) : ccnt = len(cols) #Just to get the largest columne count
for ii in range(len(lns)) :
new_ln = []
cols = lns[ii][0:len(lns[ii])-1].split(";")
for i in range(ccnt) :
if i < len(cols) : new_ln.append(ValInType(cols[i]))
else: new_ln.append("None")
self.list_.append(new_ln)
self.colcnt = ccnt
return
if __name__ == "__main__":
dir, file = os.path.split(__file__)
bmp = bitmaps.BaseBitmap()
bmp.InitWith(os.path.join(dir, "res", "icon.tif"))
plugins.RegisterTagPlugin(id=PLUGIN_ID,
str="PlgTAG",
g=PlgTAG,
description="PlgTAG",
icon=bmp,
info=c4d.TAG_MULTIPLE|c4d.TAG_EXPRESSION|c4d.TAG_VISIBLE)
Now Id like to visible list_ in a commanddata. I can get list_ from somewhere else with:
class GetValues(object) :
def __init__(self, list_=None, lncnt = 0, colcnt = 0) :
super(GetValues, self).__init__()
self.list_ = list_
self.lncnt = lncnt
self.colcnt = colcnt
# tag is the tagdata
list_obj = GetValues()
tag.Message(10000045, list_obj)
list_ = list_obj.list_
lncnt = list_obj.lncnt
colcnt = list_obj.colcnt
(https://plugincafe.maxon.net/topic/7036/7946_how-to-get-a-variable-from-plugintag -> Thanks to littledevil and niklas)
The commanddata:
import c4d
from c4d import bitmaps, gui, plugins, utils
import collections, os
PLUGIN_ID = 10000055 #TestID only!!!!!!!!!!!!
class GetValues(object) :
def __init__(self, list_=None, lncnt = 0, colcnt = 0) :
super(GetValues, self).__init__()
self.list_ = list_
self.lncnt = lncnt
self.colcnt = colcnt
class MyDialog(gui.GeDialog) :
tag = None
list_ = []
lncnt = 10
colcnt = 10
def CreateLayout(self) :
ln = 0
col = 0
element = 0
cntr = 0
hole = (self.lncnt+1)*(self.colcnt+1)
self.ScrollGroupBegin(
id=0,
flags=c4d.BFH_SCALEFIT|c4d.BFV_SCALEFIT,
scrollflags=c4d.SCROLLGROUP_VERT | c4d.SCROLLGROUP_HORIZ,
initw=300,
inith=50
)
self.GroupBegin(id=1, flags=c4d.BFV_TOP|c4d.BFH_LEFT, title="", cols=self.colcnt+1)
for i in range(self.lncnt+1) :
for ii in range(self.colcnt+1) :
cntr += 1
if i == 0:
if ii == 0: self.AddStaticText(id=i+2, flags=c4d.BFH_LEFT, name="", borderstyle=c4d.BORDER_NONE)
else:
self.AddStaticText(id=i+2, flags=c4d.BFH_LEFT, initw=100, name=str(col), borderstyle=c4d.BORDER_THIN_OUT)
col += 1
else:
if ii == 0:
self.AddStaticText(id=i+2, flags=c4d.BFH_LEFT, initw=100, name=str(ln), borderstyle=c4d.BORDER_THIN_OUT)
ln += 1
else:
a = int(float(element)/self.colcnt)
b = element - (a*self.colcnt)
self.AddStaticText(id=i+2, flags=c4d.BFH_LEFT, initw=100, name=str(self.list_[a][b]), borderstyle=c4d.BORDER_THIN_IN)
element += 1
self.GroupEnd()
self.GroupEnd()
return True
def Command(self, id, msg) :
return True
def CoreMessage(self,id,msg) :
if id == c4d.EVMSG_CHANGE or id == 1970300003:
activeTag = c4d.documents.GetActiveDocument().GetActiveTag()
if self.tag != activeTag:
if activeTag == None:
self.list_ = []
self.lncnt = 0
self.colcnt = 0
elif activeTag.GetType() != 10000045:
self.list_ = []
self.lncnt = 0
self.colcnt = 0
else:
self.tag = activeTag
list_obj = GetValues()
self.tag.Message(10000045, list_obj)
self.list_ = list_obj.list_
self.lncnt = list_obj.lncnt
self.colcnt = list_obj.colcnt
self.tag = activeTag
self.LayoutFlushGroup(0)
self.CreateLayout()
self.InitValues()
self.LayoutChanged(0)
return True
class Test(plugins.CommandData) :
dialog = None
def Execute(self, doc) :
if self.dialog is None: self.dialog = MyDialog()
return self.dialog.Open(dlgtype=c4d.DLG_TYPE_ASYNC, pluginid=PLUGIN_ID, defaultw=1, defaulth=1)
def RestoreLayout(self, sec_ref) :
if self.dialog is None: self.dialog = MyDialog()
return self.dialog.Restore(pluginid=PLUGIN_ID, secret=sec_ref)
if __name__ == "__main__":
bmp = bitmaps.BaseBitmap()
dir, f = os.path.split(__file__)
fn = os.path.join(dir, "res", "icon.tif")
bmp.InitWith(fn)
plugins.RegisterCommandPlugin(id=PLUGIN_ID,
str="Test",
info=0,
help="Test",
dat=Test(),
icon=bmp)
If the active tag of the document is a TableTag, the commanddata shows the table. If not, the commendata is empty. If the active tag is changed from one TableTag to an other the commanddata is refreshing its one and the table of the new active TableTag is shown. So far, so good.
It works well, but this way simply takes to long for refreshing. I tested with 12.000 element (1000 line, 12 columnes, 1.8sec.) and 120.000 elements (10000 lines, 12columnes, more than 4min.).
So my question is: How is the structure manager working? I think it is a commanddata, too. And it gets the information from the pointtag of the active object.
I hope I explained comprehensibly.
Thanks for help
Greetings
rown