Get Position for an Object?

Discussion about scripting with Python
Forester
Posts: 87
Joined: Mon Mar 15, 2010 4:36 am
Contact:

Get Position for an Object?

Postby Forester » Fri May 13, 2016 5:36 pm

I'm having a little syntax problem - I hope it is "little." :oops:

Like many situations, I need to convert water to foam, and I have more than one object in a scene, so I can't use the simple "onCollision" function. Since my problem is a waterfall that is emitting from within a shaped Object (a stainless steel blade to create a sheet flow), and I only need foam at the foot of the waterfall, I am trying to borrow Brandon Young's idea of using distance from one object to another to control where the foam particles get created.

Here's my initial simple code setup, without any of Brandon's randomization functions.

Code: Select all

<def onSimulationStep():

# Original idea of using distance by Brandon Young

#Variables
   liquid = scene.get_PB_Emitter("WaterfallSheet_Type")
   foam = scene.get_PB_Emitter("Container02")

   waterfalltop = scene.getObject("SSBlade")
   waterfallimpactpt = scene.getObject("tempBasin")

   waterfalltopY=Null01.getParameter("Position.Y")
   waterfallimpactptY=Null01.getParameter("Position.Y")
 
   length = waterfallimpactptY-waterfalltopY   # should always result in negative value
   
   velMult = .01 # this adjusts the inherited velocity of the particles  example  .1 = 10% 1 = 100%

# Conversion Water To Foam based on length/distance from stainless steel blade containing
# waterfall sheet emitter

   p = liquid.getFirstParticle()
   while p:
      nextp = p.getNextParticle()
      if (p.getPosition().getY()<= length +0.5):   
         pos = p.getPosition()
         vel = p.getVelocity()
         velx = vel.x * velMult
         vely = vel.y * velMult
         velz = vel.z * velMult
         newvel = Vector.new(velx,vely,velz)
         foam.addParticle(pos, newvel)
         liquid.removeParticle(p.getId())   
      p = nextp  >


My problem is finding the correct syntax for the "GetParameter("Position.Y") statements for an object, and/or for creation of a new variable that would hold that value.

If I place Null Objects in the scene, as Brandon does, and position them at the locations of each of my two objects, the above statement

" waterfalltopY=Null01.getParameter("Position.Y") "

works just fine. But I would prefer to not be forced to place Null Objects in the scene just to make this happen. The locations of these have to be positioned by hand. It seems simpler to just use the Y location of the objects themselves, and create a variable for this location value.

Isn't there a way to write a statement like this for my "waterfalltop" variable (or for the "SSBlade" object) that would return the value of "Y" - so as to create a variable called something like "waterfalltopY" ??????

I haven't been able to find any clues in the Realflow 2015 Scripting Reference doc, or come up with anything through brute-force experimentation. What is the proper command syntax. Sorry about this - I'm still in the early stages of learning Realflow2015 Python. :oops:
Windows 7 Pro 64 - Realflow 10.1.2.0162 (Nov 2017 patched) Standard Version


SantiF
Posts: 2
Joined: Mon Apr 18, 2016 5:12 am

Re: Get Position for an Object?

Postby SantiF » Thu Jun 09, 2016 8:22 am

Hi Forester, If you want to get the position of an object here is the syntax.

testobj = scene.getObject("Sphere01")
posy = testobj.getParameter("Position").getY()
scene.message(str(posy))


You can test with that, should print the position in the messages.

Sorry for late reply,

Cheers,

Santi

Forester
Posts: 87
Joined: Mon Mar 15, 2010 4:36 am
Contact:

Re: Get Position for an Object?

Postby Forester » Mon Jun 13, 2016 9:29 pm

Thank you very much, Santi!

Wonderful!!!!!! That does it!

Thank you again for the favor of a reply - I had almost given up on this project. You've saved me!
Windows 7 Pro 64 - Realflow 10.1.2.0162 (Nov 2017 patched) Standard Version


Return to “Python-Scripting”

Who is online

Users browsing this forum: No registered users and 1 guest