Jump to content
Developer Wiki and Function Reference Links ×

Generating Popup Control dynamic content


BillW

Recommended Posts

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.NodeDefinition
class 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

Link to comment
  • Marionette Maven

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.

Link to comment

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

 

Link to comment
  • Marionette Maven

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.

Link to comment

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.

Link to comment
  • Marionette Maven

@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

 

Link to comment

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...