Notifications
Clear all

[Closed] Pflow changed parameters through MaxScript not reflected in the scene?

Hi,
is there a function that tells Max that the PFlow tree has changed and should be reevaluated?

This problem happens only when the code is in an event of a GUI element (button or spinedit).

Codes in listener and in a script file by itself work as expected.

When the code is in a button – I can create an entire Flow through MaxScript in PView but no particles show in the scene – I have to manualy add and delete a random operator in PView for the scene to refresh.
The same goes for changing parameters in operators – the parameter changes, as reflected in PView but the scene doesn’t aknowledge that!!!

I managed to narrow the problem down:

Code:
$Birth_01.Amount=400

  • in the listener – it works
  • as script by itself – it works
  • as a script inside an on pressed event of a button – it changes only the parameter in PView, the scene doesn’t reflect the change

One workaround is to emediately after, Hold the scene and then Fetch it – the reopened scene shows the change.

So now the question is, what is the difference between code run as a whole script and the same code run in a button?

PS. Anybody know a way to Fetch the scene without the “Are’U’Sure” dialog opening???

7 Replies
 JHN

Have you tried to scrub the time 1 frame forward after a press on the button? Did that reflect the change? I have seen conditions where this was the case, you could code in a viewport update en a timeslider +1 action.

-Johan

The hold/fetch trick is suggested when you construct a completely new PFlow via MAXScript (otherwise no particles will be born). But for just changing a parameter, that should not be necessary. Try the time slider trick and see if it helps.

Otherwise, you can use fetchMaxFile quiet:true

to update PF you only have to activate particle display:


try(destroydialog testRol) catch()
global pcf
global pAmount = if pAmount == undefined then 100 else pAmount 
rollout testRol "PF Update by denisT" 
(
 spinner sp "Amount: " range:[0,1000,pAmount] type:#integer fieldwidth:56
 button create "Create PF" width:180 offset:[0,4]
 
 local pf, op1
 on create pressed do undo "Create" on 
 (
  try (delete objects) catch()
  pcf = PF_Source name:"Test" X_Coord:0 Y_Coord:0 Emitter_Length:10 Emitter_Width:10 \
   Quantity_Viewport:100 Show_Logo:on Show_Emitter:on wirecolor:blue
	
  particleFlow.BeginEdit()
  op1 = Birth name:"_birth" amount:pAmount 
  op2 = Position_Icon()
  op3 = Speed()
  op4 = ShapeStandard shape:2 size:0.8
  op5 = RenderParticles()
  op6 = DisplayParticles name:"_display" color:pcf.wireColor
  ev1 = Event name:"_event"
  ev1.SetPViewLocation (pcf.X_Coord) (pcf.Y_Coord+100)
  particleFlow.EndEdit()
  
  ev1.AppendAction op1
  ev1.AppendAction op2
  ev1.AppendAction op3
  ev1.AppendAction op4
  ev1.AppendAction op5
  pcf.AppendAction op6
  pcf.AppendInitialActionList ev1
  sp.value = pcf._event._birth.amount
 )
 on sp changed val do if iskindof pcf PF_Source do
 (
  pcf._event._birth.amount = pAmount = sp.value
  for i=1 to pcf.numActions() 
   where iskindof (d = pcf.getAction i) DisplayParticles and d.name == "_display" do 
	pcf.activateAction i 1
 )
)
createdialog testRol width:200 height:60

Scrubbing the timeslider doesn’t help

Activating the Display operators seems to be working on a quick test, will have to update the whole script and tell you how it went

OK, got it working

Updating parameters in operators through MaxScript required an update funtion, and the one that denis wrote totally worked.

It didn’t work on creating the Flow though, I still had no particles in the scene after creating and whatever I tried to activate it still didn’t work :((

The funny thing was that denis’s simple test script actually showed the particles right after creating them, so it took me about an hour to decompose it and compare it to mine to finally discover THE SILLYEST thing ever:

If you want to create a Particle Flow using MaxScript you have to INSERT THE FLOW CREATION SCRIPT INSIDE AN UNDO CLAUSE:

undo “Particles created” on (

– your flow creation script

)

This probably is still a bug, but the simple process of temporal storing the scene for Undo operations gets around it beautifully

I found easiest way to update particles in view after changing any parameter of any action using mx script:
<PF_Source>.activateParticles on

Beautiful mate