Notifications
Clear all

[Closed] Accessing parameters from another parameter block in scripted plugins

Hi,
I’m trying to use class parameters for default creation values for my simple geometry object plugin.
I defined two parameters blocks, the ‘defaults’ being the class type of parameters.
But it seems that I cannot access them from my other parameter block. What am I doing wrong?

Here are the parameter blocks definitions:

parameters defaults type:#class
   	(
   		defWidth type:#float default:1
   		defLength type:#float default:1
   		defHeight type:#float default:1
   		defPivot type:#integer default:1
   	)
   	
   	parameters main rollout:params
   	(
   		width type:#float ui:width default:defWidth
   		length type:#float ui:length default:defLength
   		height type:#float ui:height default:defHeight
   		pivotPoint type:#integer ui:pivot default:defPivot
   	)

Here’s the error message:

– Runtime error: Plug-in not active, unable to access plug-in local or parameter: defWidth

11 Replies

you’ve missed the part how you call these parameters. you can’t ask pblock parameters of a plugin. you can ask only an its instance.

Hey,
I don’t exactly understand what you mean.
Should I call them using ‘this.defWidth?’. That didn’t work.
Or do you mean I can’t refer from one parameter to another?

Where should I apply my defaults then? I tried inside the create tool, in the ‘on mouse click’ event, but that hanged up Max…

hmm… how can i explain it clearer? well
when you use ‘this’ it can be a different thing at the stage you asking it.

it might be a plugin stage (and the system tells you that is not an object yet) or an object stage (instance of the plugin)

because you don’t show your code at the moment when you call ‘this’ it’s hard to get what you do wrong

Sorry, I wasn’t clear enough in my explanation.
The only time (so far) my code calls for class parameters is in the above parameters blocks. So for instance in this line:

width type:#float ui:width default:defWidth
  which is the first line of the second block called 'params', [b]default [/b]attribute calls [b]defWidth[/b] parameter defined in the first block, called 'defaults'.

defWidth type:#float default:1

 The error is thrown at that line coming from the 'params' block. Instead of calling simply 'defWidth' I also tried a hit-and-miss approach - unsuccessfully:

this.defWidth
defaults.defWidth
this.defaults.defWidth
CSGcube.defWidth
CSGcube.defaults.defWidth

[i] (CSGcube being my class name)

[/i]Anyway, the concept of class parameters is only briefly mentioned in Max documentation. I couldn’t find any example of its usage.
The bahaviour I’m looking for is the same as with standard primitives – if you set segments of box width and length to let’s say 10, your next box you create will have the same settings, not the default 1. So my intention is to remember the last used settings.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

ok. now the problem is clear enough. you are trying to define the default value of a parameter as a variable(parameter) which is not created yet. you can’t do it. the system doesn’t work this way

the best solution is to use ‘on create’ handle:

on create do
(
    width = defwidth
) 

or if ‘defwith’ a static value try to define it as a local variable above definition of ‘width’ parameter

Hey,
Thanks for clarifying why my parameter assignment did not work.
Your solution does work, as in it doesn’t produce any errors, but I am not getting desired results.
Local variables seem to live on the instance of a class only.

 When I update them using [b]on <parameter> set[/b] handler, they do not get carried over to next instances.

     	local defPivotPoint = 2
     	local defMedium = 1
     	
     	parameters main rollout:params
     	(		
     		width type:#float ui:width default:4
     		length type:#float ui:length default:4
     		height type:#float ui:height default:4
     		pivotPoint type:#integer ui:pivot default:2
     		medium type:#integer ui:medium default:1
     		
     		on pivotPoint set val do
     		(			
     			defPivotPoint = val
     		)
     		
     		on medium set val do
     		(
     			defMedium = val
     		)
     	)
     
     --rollout definition here
     --(...)
     
     	on create do
     	(
     		pivotPoint = defPivotPoint		
     		medium = defMedium
     	)
     
     
 Is there any way to have variables for the class? Is this what you call 'static' variables? If so, how do you make variables static?

parameters <name> [type:#class] [rollout:<name>] (
{ <param_defs> }+
{ <event_handler> }
)

The optional type:<#class> specifies that the parameters in the parameter block are “class” parameters. This means that there is one copy of each parameter for the all the objects of this plug-in class; they all share the parameter. Examples of existing class parameters are the creation type and type-in parameters in a typical geometry primitive.

this is what mxs help says. but it has never worked for

Yep, that’s the fragment of documentation that made me experiment with the class parameters. Sad to hear it doesn’t work…
I’ll try referring to some global variable holding default values for my custom geo plugins.

Hmm… this is becoming harder than I thought. For some reason I can’t access global variable properly. I have declared a global, which is a struct holding certain default settings for my custom geo plugins. But when I try to access them in my plugin, I get that errror:

It seems to see the global variable itself, but has problem with seeing the struct members.
Are there any restrictions for accessing global variables from inside the scripted plugin?

So here’s my struct and global instance of it:

struct DromaxGlobalsStruct (
  	CSGcube = 1,
  	CSGcylinder = 2,
  	mediaTypes = #("Solid", "Air", "Water", "Solid -> Air", "Solid -> Water", "Air -> Solid", "Flood", "Water -> Solid", "Evaporate", "Blockable")
  )
  
  global DromaxGlobals = DromaxGlobalsStruct

and this is an ‘on open’ event of my scripted plug-in rollout:

on params open do
  		(
  			medium.items = DromaxGlobals.mediaTypes 
  		)

The global variable is defined before the plugin definition, of course.
Is it me or MXS doing something wrong?

 MZ1

global DromaxGlobals = DromaxGlobalsStruct()
You need to create instance of your structure

Page 1 / 2