Tell us what you think of the site.
I’m in the middle of writing a script that duplicates an object based on the number of points on a given piece of geometry and which also translates each duplicate to the given points. Its working, but at the moment im only able to access the local point component positions but i need the global component positions. Any one know how I can get to it? right now I’m using ActivePrimitive.Geometry.Points.PositionArray
Falun Dafa
A meditative practice for the mind and body
You can convert to global with XSIMath.MapObjectPositionToWorldSpace
Thanks! I’m sure thats what I need to do. I’m trying it out, but I keep getting com errors, its telling me that the position I’m providing to convert is not a com object, I looked over my code in all the ways I know how, so I’m a bit confused at the moment ^_^
Show us your code.
Forgot to mention I’m using python...........
The code as requested:
import win32com
XSIMath = win32com.client.Dispatch( “XSI.Math” )
#Define Application
xsi=Application
#Define selected object
rtn=xsi.PickElement("","Pick An Object”, “Pick An Object")
oDob=rtn[2]
#Define Object to duplicate onto
rtn=xsi.PickElement("","Pick Destination Object”, “Pick Destination Object")
oCob=rtn[2]
oTrans = oCob.name+".Kinematics.Local.Transform"
oPoint = oCob.name+".ActivePrimitive.Geometry.Points.Position"
Application.LogMessage (oPoint)
XSIMath.MapObjectPositionToWorldSpace (oTrans,oPoint)
Thanks!!
oTrans = oCob.name+".Kinematics.Local.Transform" oPoint = oCob.name+".ActivePrimitive.Geometry.Points.Positi on"
oTrans and oPoint are strings.
Points is a collection; you need to do something like Points(0).Position
Hello,
I tried that already as well as using the commands directly instead of the variables, but the xsimath still returns the same error. Could someone run it and give a go and trying to debug the problem, I figure it is because I’m accessing a collection, but putting (0) there didnt change anything. Also if I only put one number there, I would not be able to access each points position right?
Thanks!!!
Basically, the XSIMath method accepts an siVector3 object as input, so you need to construct one of those from each point position. The positionArray is handy to get the ordered point positions.
This is an example run on a simple cube. It uses mapped lambda functions, which pretty much allow you to encapsulate an whole ‘for...in’ statement in a single line. Regular loops would work just as well.
import win32com
XSIMath = win32com.client.Dispatch( "XSI.Math" )
#Define Applicationxsi=Application
oCob = xsi.Selection(0)
oTrans = oCob.Kinematics.Local.Transform
#Get a 2D array of point positions i.e x,y or z value per pointposArr = oCob.ActivePrimitive.Geometry.Points.PositionArray
#build an array of siVectors from the positionArray components, using a mapped lambda function
#XSIMath.CreatVector3() is the function
#the posArr indices are the x, y, z arguements in that ordervecArr = map(lambda x,y,z: XSIMath.CreateVector3(x,y,z), posArr[0], posArr[1], posArr[2])
xsi.logmessage('Local space')map(lambda a, b: xsi.logmessage(str(b) + ': ' + str(a.X) + ' ' + str(a.Y) + ' ' + str(a.Z)), vecArr, range(len(vecArr)))xsi.logmessage('######################')
#Again, use a mapped lambda function to pass the entire array through the XSIMath method at oncemappedVecArr = map(lambda x: XSIMath.MapObjectPositionToWorldSpace(oTrans, x), vecArr)
xsi.logmessage('World space')map(lambda a, b: xsi.logmessage(str(b) + ': ' + str(a.X) + ' ' + str(a.Y) + ' ' + str(a.Z)), mappedVecArr, range(len(mappedVecArr)))xsi.logmessage('######################')
Thanks!!! I will try this out asap!!
Now that the points position values are mapped to world space, will reusing
ActivePrimitive.Geometry.Points.PositionArray
get me the new position values? Reason I asked is because I tried that lol and I still get a local value. I’m trying to make a copy script where I can copy a geo object onto the points of another object, and it works without have to convert the spaces except that it only works based on local position so I ran into some issues with some meshes, so thats why I needed to convert the positions to a world space ^_^ so, I know reusing ActivePrimitive.Geometry.Points.PositionArray is not giving me those new values, any suggestions?
or do I now need to get the length of the mappedVecArr? right now I using
for p in range(len(pa[0])):
null = xsi.SIDuplicate(oDob)
xsi.Logmessage(null)
tmp=null[0]
t = tmp.Kinematics.Global.Transform
t.SetTranslationFromValues(pa[0][p], pa[1][p], pa[2][p])
tmp.Kinematics.Global.Transform = t