View Full Version : PFlow adding Script operator through external script.
kaczorefx 12-08-2009, 09:35 PM Ok this is my script:
particleFlow.BeginEdit()
ms_op = Script_Operator()
ms_op.Proceed_Script="on ChannelsUsed pCont do \n ( \n \n) \n\n\n on Proceed pCont do \n ( \n for i in 1 to pCont.NumParticles() do \n ( \n pCont.particleIndex = i \n print 2 \n ) \n)"
pf.appendAction ms_op
particleFlow.EndEdit()
pf.activateParticles on
This part works.
The operator gets created, the script gets inserted.
Unfortunately the script doesn't work.
I have to manually move the operator in the GUI (drag and drop even on the same place)
Then it starts working.
Thought it was something with scene refresh, hence pf.activateParticles on but no luck.
Saving the scene and reopening doesn't help - and it does when you have a scene refresh issue.
The script will not work until I manually move it around in the GUI (moving by script doesn't work either :( )
Am I missing something?
|
|
denisT
12-08-2009, 11:47 PM
in my code everything updates right. i can't see any problem in your code.
(check highlighted and ignore anything else)
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]
button scr1 "Script 1" across:2 width:89 align:#left offset:[-3,4]
button scr2 "Script 2" width:89 align:#right offset:[3,4]
fn script1 =
(
source = ""
source += "on ChannelsUsed pCont do () \n"
source += "on Proceed pCont do for i in 1 to pCont.NumParticles() do \n"
source += "( \n"
source += "\tpCont.particleIndex = i \n"
source += "\tformat \"script 1: %\\n\" i \n"
source += ") \n"
)
fn script2 =
(
source = ""
source += "on ChannelsUsed pCont do () \n"
source += "on Proceed pCont do for i in 1 to pCont.NumParticles() do \n"
source += "( \n"
source += "\tpCont.particleIndex = i \n"
source += "\tformat \"script 2: %\\n\" i \n"
source += ") \n"
)
local op1
on create pressed do --undo "Create" on
(
try (delete objects) catch() -- be careful!!! i'm deleting all objects before creating a new particle flow
theHold.Begin()
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 = DisplayParticles name:"_display" color:pcf.wireColor
op6 = RenderParticles()
ev1 = Event name:"_event"
ev1.SetPViewLocation (pcf.X_Coord) (pcf.Y_Coord+100)
op7 = Script_Operator name:"_operator"
op7.Proceed_Script = script1()
-- particleFlow.EndEdit()
ev1.AppendAction op1
ev1.AppendAction op2
ev1.AppendAction op3
ev1.AppendAction op4
ev1.AppendAction op5
pcf.AppendAction op6
pcf.AppendAction op7
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
pcf.activateParticles on
)
on scr1 pressed do
(
pcf._operator.Proceed_Script = s = script1()
format "%\n" s
)
on scr2 pressed do
(
pcf._operator.Proceed_Script = s = script2()
format "%\n" s
)
)
createdialog testRol width:200 height:90
kaczorefx
12-09-2009, 05:19 PM
Thanks for help.
Once again the answer was simple: put the whole thing in an Undo clause :)
I can't seem to remmeber that :(
On another note:
does your script work for you.
Here, it creates a load of Display operators not connected to anything, can't find it in the code, and screws up Max's UI so selecting any of the options in the top Menu doesn't do anything. That also includes trying to close Max :)) The red cross doesn't work!!!
I've noticed you had commented out the BeginEdit() and EndEdit() for PFlow and it still works without it!! So why again should we be using it??
Any way forgive me my next post, it's for me and future generations :)
kaczorefx
12-09-2009, 05:24 PM
If you want to do anything with PFlow:
- creating flows
- editing flows
with Maxscript run from a UI element, remember to ALWAYS put the procedure in an undo clause:
undo "pf edit" on (
particleFlow.BeginEdit()
.....
particleFlow.EndEdit()
)
This should solve most of the problems with the scene not refreshing.
keywords:
particle, flow, PF, PFlow, not refreshing, doesn't show, don't, MaxScript,script, MS, external, outside, from, UI, element
denisT
12-09-2009, 05:46 PM
Thanks for help.
I've noticed you had commented out the BeginEdit() and EndEdit() for PFlow and it still works without it!! So why again should we be using it??
<void>particleFlow.beginEdit()
<void>particleFlow.endEdit()
Block the Event encapsulation of Particle Flow Actions created via MAXScript.
When a Particle Flow Action (Operator or Test) is created, it is automatically encapsulated into a Particle Flow Event. This is done since all Particle Flow Actions should belong to an Event.
Sometimes this behavior can be undesired and become an obstacle when creating Actions via MAXScript. To avoid this, the pair beginEdit / endEdit can be used.
i do all appendices from the script and I don't need beginEdit / endEdit
kaczorefx
12-09-2009, 09:53 PM
Thanks again :)
CGTalk Moderation
12-09-2009, 09:54 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.