BillW Posted November 17, 2017 Share Posted November 17, 2017 Trying to tie some of my tools into Marionette. Before diving in further, is it possible to dynamically fill a popup controls choice content from say a text file? Can I add a function to class Params and reference in the OIPControl definition (ie this.getcontent('options.txt')) - see below (example from Marionette website) TIA Bill Wood @Marionette.NodeDefinitionclass Params(metaclass = Marionette.OrderedClass): this = Marionette.Node( 'Add' ) a = Marionette.PortIn( 0 ) b = Marionette.PortIn( 0 ) out = Marionette.PortOut() k = Marionette.OIPControl( 'Multiplier', Marionette.WidgetType.Real, 1) p10 = Marionette.OIPControl( 'Popup', Marionette.WidgetType.Popup, 0, ['choice 1', 'choice 2'])def RunNode(self): sum = self.Params.a.value + self.Params.b.value self.Params.out.value = sum * self.Params.k.value Quote Link to comment
Marionette Maven Marissa Farrell Posted November 17, 2017 Marionette Maven Share Posted November 17, 2017 I don't want to say no definitively, but it really depends on how often that external list will change. Marionette Node parameters are only updated when the script is updated (opening then closing the script), which makes dynamically populated OIP controls really fussy. If this text file will always hold the same parameters, then it can probably be done, but if the file is going to be updated, you'll have to remember to update the script every time that happens. (It may also update itself once you run it once, we've seen that before in testing, but I'm not certain it's reliable) Even then, I haven't tried this myself, so it may not work how I anticipate. Quote Link to comment
BillW Posted November 17, 2017 Author Share Posted November 17, 2017 Thanks Marissa. I managed to get the popup filled with content from a standard plugin data file - see below. For some reason I cannot get any output from the node ie self.Params.sectionsize.value = sectionType Tried passing the output to an alertdialog node - nothing. Is it the definition of class content before @Marionette.NodeDefinition causing the problem. import os class content: nodename = "Angle-Metric" nodedesc = 'Select an Angle-Metric section size' def getcontent(): fref = os.path.join(vs.GetFolderPath(20) , 'Angle-Metric.txt' ) content = [] if os.path.exists(fref): f = open(fref) line = f.readline() # First line not used line = f.readline() while line: sline = line.split('\t',1) content.append(sline[0]) line = f.readline() f.close() else: content = ['Undefined'] return content @Marionette.NodeDefinition class Params(metaclass = Marionette.OrderedClass): #APPEARANCE #Name this = Marionette.Node( content.nodename ) this.SetDescription( content.nodedesc ) #OIP Controls sectionType = Marionette.OIPControl('Section Type', Marionette.WidgetType.Popup, 0, content.getcontent() ) sectionType.SetDescription( "List of valid section types" ) #Output Ports sectionsize = Marionette.PortOut('Type') sectionsize.SetDescription( "The resultant section definition" ) #BEHAVIOR def RunNode(self): #inputs sectionType = self.Params.sectionType.value #outputs self.Params.sectionsize.value = sectionType Quote Link to comment
Marionette Maven Marissa Farrell Posted November 17, 2017 Marionette Maven Share Posted November 17, 2017 Yep! You'll want to do this a little differently. #OIP Controls types = content.getcontent() sectionType = Marionette.OIPControl('Section Type', Marionette.WidgetType.Popup, 0, types ) sectionType.SetDescription( "List of valid section types" ) and def RunNode(self): #inputs sectionType = self.Params.types[self.Params.sectionType.value] should do the trick. Let me know if that's still not working and I'll open up VW to figure it out, this is just from memory. Quote Link to comment
BillW Posted November 19, 2017 Author Share Posted November 19, 2017 Marissa, I tried your suggestions but still cannot get any output ie from Marionette.PortOut('Type') even with debug set. I tried various things including merging the content and params classes, replacing the .nodename and .nodedesc with fixed strings and even externally building the getcontent() full string and embedding as a fixed string. I even upgraded Vectorworks 2018 to SP 1 and set Marionette preferences>Cache Last Run in Debug On and Off. I have the feeling that Marionette.WidgetType.Popup does not like long lists. I also understand that by default the popup widget returns a number relating to the selected item from the list. Can you try at your end to see if you can get it to work - it might be my VW installation. Quote Link to comment
Marionette Maven Marissa Farrell Posted November 20, 2017 Marionette Maven Share Posted November 20, 2017 @BillW The script below works for me. It just took some reorganization, let me know if you're still having an issue with it. @Marionette.NodeDefinition class Params(metaclass = Marionette.OrderedClass): def getcontent(): import os fref = os.path.join(vs.GetFolderPath(20) , 'Angle-Metric.txt' ) content = [] if os.path.exists(fref): f = open(fref) line = f.readline() # First line not used line = f.readline() while line: sline = line.split('\t',1) content.append(sline[0]) line = f.readline() f.close() else: content = ['Undefined'] return content #APPEARANCE #Name this = Marionette.Node( 'Angle_Metric' ) this.SetDescription( 'Select an Angle-Metric section size' ) #OIP Controls types = getcontent() sectionType = Marionette.OIPControl('Section Type', Marionette.WidgetType.Popup, 0, types ) sectionType.SetDescription( "List of valid section types" ) #Output Ports sectionsize = Marionette.PortOut('Type') sectionsize.SetDescription( "The resultant section definition" ) #BEHAVIOR def RunNode(self): #inputs sectionType = self.Params.types[self.Params.sectionType.value] #outputs self.Params.sectionsize.value = sectionType Quote Link to comment
BillW Posted November 20, 2017 Author Share Posted November 20, 2017 Marissa, I loaded your script into my VW file - see attached. Weird, I still cannot get it to run. The VW file has popups which do run. I am on Windows 7 Professional SP1 and VW 2018 SP1. Previously, I pretty much made the same sort of edits as your version. angle test.vwx Quote Link to comment
Marionette Maven Marissa Farrell Posted November 20, 2017 Marionette Maven Share Posted November 20, 2017 So, Marionette doesn't like special characters in node names. I think if you change your Angle-Metric to Angle_Metric for the line defining the node name, you may be all set. That's the only change I made when opening the file you have attached. this = Marionette.Node( 'Angle_Metric' ) Quote Link to comment
BillW Posted November 20, 2017 Author Share Posted November 20, 2017 That's the problem solved. Thanks vey much. Bill Wood Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.