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 March 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

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 March 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 March 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 March 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 March 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).

-- 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).

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 April 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).

-- 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).

Follow Us On:

The CGSociety

The CGSociety is the most respected and accessible global organization for creative digital artists. The CGS supports artists at every level by offering a range of services to connect, inform, educate and promote digital artists worldwide. More about us on TheArtSociety.com