PDA

View Full Version : Accessing Custom Parameter on a PFlow system


blakboks
03-29-2006, 07:42 PM
Hi all,
I'm extremely new to MaxScript, and relatively new to scripting in general.

I have a ScriptTest operator on one of my events in PFlow, and I need to access some custom parameters I have on the PFlow object through the script. I don't need to change the values or anything, I just need to read them and do some calculations based off them. Also, along those lines, how can I access attributes from other events. Specifically, I need to see how many particles exist in total on a couple other events. So, how would I find out the number of particles on each individual event?

If there's already a post somewhere that can help out, by all means point me to it, please. I did a search through the forums, but since I'm not really even entirely sure what I should be looking for, I was pretty unsuccessful. I also checked out the MaxScript docs quite a bit, again, since I didn't really know what I should be looking for, I was pretty unsuccessful.

Much obliged,
Chris

Bobo
03-29-2006, 08:14 PM
Hi all,
I'm extremely new to MaxScript, and relatively new to scripting in general.

I have a ScriptTest operator on one of my events in PFlow, and I need to access some custom parameters I have on the PFlow object through the script. I don't need to change the values or anything, I just need to read them and do some calculations based off them. Also, along those lines, how can I access attributes from other events. Specifically, I need to see how many particles exist in total on a couple other events. So, how would I find out the number of particles on each individual event?

If there's already a post somewhere that can help out, by all means point me to it, please. I did a search through the forums, but since I'm not really even entirely sure what I should be looking for, I was pretty unsuccessful. I also checked out the MaxScript docs quite a bit, again, since I didn't really know what I should be looking for, I was pretty unsuccessful.

Much obliged,
Chris

When you say "Custom Parameters", do you mean properties of the PFlow operators, or USER-DEFINED CUSTOM ATTRIBUTES? An example of what you mean usually helps.

To get the number of particles in a specific event, you have to call the .numParticles() method in the corresponding Particle Group object. For each Event, a ParticleGroup class object is available. It's name is automatically set to the name of the Emitter and the Event.

For example, if you would create a default PFlow with one Event, the ParticleGroup of Event 01 would be called


$'PF Source 01->Event 01'
$Particle_Group:PF Source 01->Event 01 @ [0.000000,0.000000,0.000000]


You can take a look at the available methods for the Particle Group:

showInterfaces $'PF Source 01->Event 01'
Interface: particleObjectExt
Properties:
Methods:
<integer>numParticles()
<integer>numParticlesGenerated()
<index>particleBornIndex particleIndex
Actions:
OK

Scrub the time slider to frame 50 and call

$'PF Source 01->Event 01'.numParticles()
100


You should be able to use this approach from inside Scripted Operators in the flows.


Another method would be to place Script Operators in the Events of interest and let them write the result of pCont.numParticles() into global variables (or in a global array of integers) and read these global values from your code that needs the counts....

blakboks
03-29-2006, 08:24 PM
Wow, thank you very much for that explaination. It was extremely helpful.

In regards to the custom parameters:
Yes, I believe I do mean Custom Attributes. Sorry, coming from an XSI background here. I basically created these parameter (attributes) through the Parameter Editor (ok, it would help with the confusion if even Max was consistent in their naming). I added the parameters/attributes to the base level of the PF Source.
I think I might've figured this one out, though. I just kind of learned about the MaxScript Listener and the MacroRecorder. I enabled the MacroRecorder and adjusted the parameters/attributes and just copied what it gave me into my script. Gotta see if it's going to work now, though.

Ugh...not looking forward to debugging this thing.
-Chris

blakboks
03-29-2006, 09:23 PM
Ok, so what are some suggested methods of debugging Script Test operators on a PFlow object? Nothing seems to be working for me at all. It's strange, the script seems to be working without too many problems. The particles are doing something, anyway. They're moving where they should be, and in a manner that seems to be consistent with how it should react. However, whenever I close the script window a message box pops up saying that the script contains errors.

What I want to do is to see what my values are within the script. A simple print command doesn't seem to be working. At least, it's not printing to the listener.

-Chris

Bobo
03-30-2006, 01:21 AM
Ok, so what are some suggested methods of debugging Script Test operators on a PFlow object? Nothing seems to be working for me at all. It's strange, the script seems to be working without too many problems. The particles are doing something, anyway. They're moving where they should be, and in a manner that seems to be consistent with how it should react. However, whenever I close the script window a message box pops up saying that the script contains errors.

What I want to do is to see what my values are within the script. A simple print command doesn't seem to be working. At least, it's not printing to the listener.

-Chris

I use PRINT all the time from inside the Script Operators (and I use Script Operators all the time ;)) If you are getting a MESSAGE BOX about an error, this means there was a syntax error when parsing the code, so the code is disabled and not evaluated at all. This is why the print is doing nothing...

For example, if you are missing a closing bracket somewhere in the code and press Ctrl+E to evaluate, a message box will tell you there is an error in the code, and an error message will be printed to the Listener. If it is a bracket problem, the error message would be pretty meaningless because your code structure has no meaning anyway... (You can press Ctrl+B to use the Bracket Balancer).
Look for typos of all kinds - it must be a typo if you are getting the message box.


As for custom attributes, they are completely MAXScript-based and were originally called Custom Attribures in both MXS and the UI. Then somebody decided that it would be easier for Maya users if they were called Parameters (as if Maya users would use Max...) so they changed the UI to "Parameter Editor", but of course you cannot change the programming language without breaking compatibility, so Custom Attributes are still called Custom Attriibutes...

In short, the UI-based "Parameters" create a new Parameter Block which appears under the name "custom_attributes" in the Curve Editor and can be accessed through that name.
Using hand-coded MAXScript CAs, you can add attributes with arbitrary names, but the shipping editor always creates a uniformly named "custom_attributes" track to avoid confusion.

For example, if you added a float parameter called Param1 to the PF_Source_01, you could access it using

$PF_Source_01.custom_attributes.param1

or

$'PF Source 01'.custom_attributes.param1

(you can either enclose a name containing spaces in single quotes, or replace the spaces with underscores).

blakboks
03-30-2006, 04:51 PM
First of all, thank you very much for all the help you've been, Bobo. Your contributions to the CG community have been extrordinary.

Unfortunately, I still seem to be having problems with the script. Aparently I'm getting errors on the part of the code that I didn't even touch. I'm getting errors on the part that Max has as the starting point (the default test script).


on ChannelsUsed pCont do
(
pCont.useTime = true
)

on Init pCont do
(

)

on Proceed pCont do
(
count = pCont.NumParticles()
for i in 1 to count do
(
pCont.particleIndex = i
DB_Temp = $'PF Source 01'.baseObject.Custom_Attributes.DB_Temp
RHPerc = $'PF Source 01'.baseObject.Custom_Attributes.RHPercent

-- calculate maximum amt. of vapor particles (a function of temperature)
MaxVaporParts = DB_Temp^(1.0/3.0)
-- calculate the number of particles that should be in the vapor (a function of RH%)
RHVaporParts = MaxVaporParts * RHPerc / 100
-- check on how many there are (including Evaporate event)
TotalVaporParts = ($'PF Source 01->Evaporate'.numParticles() + $'PF Source 01->Water Vapor'.numParticles())
-- if there are fewer particles than possible
if TotalVaporParts > RHVaporParts then
(
-- calculate the probability number (based on the difference number), multiply it by a random number(0-1)
Probability = (TotalVaporParts-RHVaporParts)/TotalVaporParts*100
-- if the number is 1
if (random 0 (Probability)) == 1
(
-- pick a random particle from the particles in this event and pass it on to evaporate
pCont.ParticleTestStatus = true
pCont.particleTestTime = pCont.particleTime
)
)
)
)
)

on Release pCont do
(

)


I don't know if this has anything to do with it, but it seems as though the script window is having problems coloring the keywords and everything properly. If I start off the code with a comment, the whole script is green (until I make a change to the line). With the code as it is above, the first line is ok, but then the rest is all blue (as if the 'do' is bleeding through the rest of the script).

I'll try reinstalling Max...something seems seriously wrong with it...
-Chris

Bobo
03-30-2006, 07:14 PM
I don't know if this has anything to do with it, but it seems as though the script window is having problems coloring the keywords and everything properly.

I'll try reinstalling Max...something seems seriously wrong with it...
-Chris

Don't try reinstalling - that color coding problem is normal. Just press Ctrl+D whenever you want to recolor. The auto-color coding was introduced around the time PFlow was introduced, so it does not behave exactly as expected...

Any chance to strip down a very simple scene that has the problem, zip it and send it to bo_petrov@yahoo.de so I can take a look?

Bobo
04-01-2006, 06:30 PM
First of all, thank you very much for all the help you've been, Bobo. Your contributions to the CG community have been extrordinary.

Unfortunately, I still seem to be having problems with the script. Aparently I'm getting errors on the part of the code that I didn't even touch. I'm getting errors on the part that Max has as the starting point (the default test script).


on ChannelsUsed pCont do
(
pCont.useTime = true
)

on Init pCont do
(

)

on Proceed pCont do
(
count = pCont.NumParticles()
for i in 1 to count do
(
pCont.particleIndex = i
DB_Temp = $'PF Source 01'.baseObject.Custom_Attributes.DB_Temp
RHPerc = $'PF Source 01'.baseObject.Custom_Attributes.RHPercent

-- calculate maximum amt. of vapor particles (a function of temperature)
MaxVaporParts = DB_Temp^(1.0/3.0)
-- calculate the number of particles that should be in the vapor (a function of RH%)
RHVaporParts = MaxVaporParts * RHPerc / 100
-- check on how many there are (including Evaporate event)
TotalVaporParts = ($'PF Source 01->Evaporate'.numParticles() + $'PF Source 01->Water Vapor'.numParticles())
-- if there are fewer particles than possible
if TotalVaporParts > RHVaporParts then
(
-- calculate the probability number (based on the difference number), multiply it by a random number(0-1)
Probability = (TotalVaporParts-RHVaporParts)/TotalVaporParts*100
-- if the number is 1
if (random 0 (Probability)) == 1
(
-- pick a random particle from the particles in this event and pass it on to evaporate
pCont.ParticleTestStatus = true
pCont.particleTestTime = pCont.particleTime
)
)
)
)
)

on Release pCont do
(

)


I don't know if this has anything to do with it, but it seems as though the script window is having problems coloring the keywords and everything properly. If I start off the code with a comment, the whole script is green (until I make a change to the line). With the code as it is above, the first line is ok, but then the rest is all blue (as if the 'do' is bleeding through the rest of the script).

I'll try reinstalling Max...something seems seriously wrong with it...
-Chris


See your mailbox...

Btw, the above piece of code has a missing DO after the ' if (random 0 (Probability)) == 1'
and one closing bracket too many after 'pCont.particleTestTime = pCont.particleTime'

CGTalk Moderation
04-01-2006, 06:30 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.