Notifications
Clear all

[Closed] dialog spawned by CA cannot reference the owner

tryout to figure out how a CA rollout button can spawn a dialog and effect the object holding the CA. I get tehis error:

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

here is an example of what I am attempting: a button that lets an object switch its parent object via a list box popup. (the exact task is not important, the list box properly referencing the CA owner is what I am after)

ca= attributes parent_switch (
	
	parameters params rollout:_rollout
	(
		'self' type:#maxObject 
	)

	rollout _rollout "switch parent" (
		
		fn getParents=(
			parentList=#()
			for each in $Sphere*  do
			(
				append parentList each.name
			)
			parentList
		)
		
		fn newparent i =(
			parentList=getParents()
			format "		newParent:%
" parentList[i]
			--this is where the error happens
			self.parent=( execute ("$"+parentList[i]) )
		)
		
		fn switch_parent=(
			getParents()
			ro=rollout ro "pick a parent" (
				listbox lb_parents items:(getParents())
				on lb_parents doubleClicked i do (
					
					newparent i
				)
			)
			
			createdialog ro modal:false
		)
		
		button btn_switchParent "switch My Parent"
		on btn_switchParent pressed do (switch_parent())
	)
)

--clear scene
delete objects
obj=box()
parent1=sphere pos:[50,0,0]
parent2=sphere pos:[0,50,0]
parent3=sphere pos:[0,-50,0]
--apply CA to box
AttributeHolder=EmptyModifier()
addModifier obj AttributeHolder
custAttributes.add obj.modifiers[#AttributeHolder] ca
--set the parameter 'self' to be the box
obj.modifiers[#AttributeHolder].parent_switch.self=obj
select obj
6 Replies

before show a dialog you have to pass to this dialog its owner (the actual instance of this plugin). it’s simple (don’t have max around but i will try to wright it blind):

ca = attributes ca
(
  parameters params rollout:params
  (
  )
 rollout rol "" width:160
 (
    local owner = if owner != undefined do owner
    label lb "" align:#center
    on rol open do lb.text = owner as string
  )
  rollout params ""
  (
    button bt "Show"
    on bt pressed do
    (
      rol.owner = this
      createdialog rol
    )
  )
)

the real problem you will meet later. but that will be another story.

Thanks for the hints. I revised my code and got it working.

the real problem you will meet later. but that will be another story.

There were a couple of issues getting the object that has the CA to be referenced correctly.
One was the need to store a weak reference to the CA object in the ‘self’ parameter, which I had anticipated.
Two was a need for a local ref to ‘self’ within the CA rollout, so that any function called form elsewhere (like the popup) would be able to’ see it.

ca= attributes parent_switch (
	
	parameters params rollout:ro
	(
		'self' type:#maxObject 
	)
	
	rollout ro "switch parent" (
		
		local selfNode --holder for an in scope refence to the above param 
		
		fn getParents=(for each in ($Sphere*) collect  each.name) 
		
		fn showSelf=(
			try(format "selfNode:%
" self.node)
			catch(format "selfNode:" (getCurrentException()) )
		)
		
		fn newparent i =(
			selfNode.parent=( execute ("$"+(getParents())[i]) )
			selfNode.transform=selfNode.parent.transform
		)
		
		fn spawn_popup=(
			popup = rollout popup "" 
			(
				local owner = if owner != undefined do owner
				listbox lb_parents items:#()
				on lb_parents doubleClicked i do (
					owner.showSelf()
					owner.newparent i
					destroydialog popup
				)
			)
			createdialog popup modal:false
			popup.owner = ro
			popup.lb_parents.items= getParents()
			
		)
		
		button btn_showSelf "showSelf"
		on btn_showSelf pressed do showSelf() --whey does this button work
		button btn_spawn_popup "new parent"
		on btn_spawn_popup pressed do (spawn_popup())	--but the same showSelf() call in this fn fails?
		on ro open do selfNode = self.Node
	)
)

--createobjects to test the ca
delete objects
obj=box()
parent1=sphere pos:[50,0,0]
parent2=sphere pos:[0,50,0]
parent3=sphere pos:[0,-50,0]

--apply CA to box
AttributeHolder=EmptyModifier()
addModifier obj AttributeHolder
custAttributes.add obj.modifiers[#AttributeHolder] ca
--use a weak reference to hold the box's self reference
refObj=nodeTransformMonitor node:obj forwardTransformChangeMsgs:false
obj.modifiers[#AttributeHolder].parent_switch.self=refObj
select obj

It seems like a CA’s parameters are local to the rollout and cannot be accessed form “child” rollouts…

all local of ca instance and its rollouts are accessible to popup rollout of course.
in your case the access is: owner.ro.<anylocal>

deletedeletedelete

Is there anyway to access the ‘self’ parameter from the popup?
owner.ro.self yields
>> MAXScript Rollout Handler Exception:
– Unknown property: “self” in Rollout:ro <<

within the ‘parent’ rollout ‘self’ will get the parameter value, but
the parameter block seems isolated form ‘children’ dialogs of the rollout.

in your case it’s: owner.self