APEX Script: Get component of Vector

   340   2   0
User Avatar
Member
18 posts
Joined: Nov. 2018
Offline
Is there an easy python like way to get a component of a vector in APEX Script without having to add nodes and use the API to connect ins and outs?

For example, the following code gives an error

pos = Vector3(1, 0, 0)
x = Float(pos.x)

The error is:

(Error: Error generated by Python node.
Line 2: :: x = Float(``pos.x)``
Can only fetch attributes from graph or node objects).

It would seem like something as simple as grabbing a component of a vector could be done without getting too verbose.

(fwiw,
pos[0]
nor
pos.x()
work either)
Edited by playBlaster - Aug. 16, 2024 20:20:03
User Avatar
Member
27 posts
Joined: May 2015
Offline
Correct me if I'm wrong... I think apex snippet is not exactly python. Each function has a corresponding apex node. You would need vector3ToFloat node to split a vector, thus you'll need to use vector3ToFloat() in snippet.

pos = Vector3(1,0,0)
x, y, z = vector3ToFloat(pos)
Edited by NMVHS - Aug. 17, 2024 04:42:06
User Avatar
Member
18 posts
Joined: Nov. 2018
Offline
NMVHS
x, y, z = vector3ToFloat(pos)

That's just what i needed NMVHS! And yeah, i know APEX script is not exactly python, that's why i said "python like". What threw me off though was the "x, y, z =" syntax. Mmmm, i see destructuring. I'm rather new to python but I'm familiar with this from javascript, which was only added fairly recently. I'll keep this in mind when faced with similar issues.

Thanks,
Sky
  • Quick Links