Maxscript - get position of object

Maxscript - get position of object

Anonymous
Not applicable
15,058 Views
3 Replies
Message 1 of 4

Maxscript - get position of object

Anonymous
Not applicable

Hello

 

I try to get the postion of an object

 

When I ask the MAXScript Listener about my objetc, it return:

 

print $Caisson_042
$Editable_Poly:Caisson_042 @ [0.000000,24384.000000,0.000000]

x = (coordsys local $Caisson_042.pos.x)
-0.00368188

y = (coordsys local $Caisson_042.pos.y)
-0.00397266

z = (coordsys local $Caisson_042.pos.z)
-24384.0

My question is why the position is OK in the print command and isn't the same in the coordsys ?

 

And how i can get the position indicated in the print command ?

 

 

Thanks for your help

0 Likes
Accepted solutions (1)
15,059 Views
3 Replies
Replies (3)
Message 2 of 4

kevinvandecar
Community Manager
Community Manager

hello,

 

The script code is actually obtaining different values. The first print, is using the world coordinates. The 'pos' property in the next section of the code is actually getting the local coordinates (from the keyword 'local' used with the 'coordsys' expression). If you change the second series to be 'world', then the values should be the same. For example:

 

x = (coordsys world $Caisson_042.pos.x)

Also, the values of

-0.003...

are likely just minor tolerance differences, too. Very close to zero.

 

I would review these sections in the help in case you want to know more:

http://help.autodesk.com/view/3DSMAX/2017/ENU/index.html?guid=__files_GUID_6C7219CF_B9B7_4B18_A846_5...

http://help.autodesk.com/view/3DSMAX/2017/ENU/index.html?guid=__files_GUID_3B001F21_8FE9_4663_A972_E...

 

Note that coordinate systems can be nested as well, and there is also a 'parent' keyword that can be used.

 

Hope it helps,

Kevin


Kevin Vandecar
Developer Technical Services
Autodesk Developer Network



0 Likes
Message 3 of 4

Anonymous
Not applicable

Sorry for the delay, I was out of the office last week.

 

I tryed to change my code to "World" coordsys but the result is continued to be different.

 

print $Caisson_042
$Editable_Poly:Caisson_042 @ [2438.399902,0.000000,0.000000]

x = (coordsys world $Caisson_042.pos.x)
0.0

y = (coordsys world $Caisson_042.pos.y)
0.0

z = (coordsys world $Caisson_042.pos.z)
0.0

 

 

I put all my code, if it can help to fix the error

My code take input in excel sheet and make an assembly of barges of 40'x8' and 20'x8' in staggered rows like brick wall

 

resetMaxFile(#noPrompt)

-- Chemins d'acces
oPath20 = "my_path\\Caisson 20.max"
oPath40 = "my_path\\Caisson 40.max"

-- Prendre les infos du fichier Excel
excelFile = "my_path\\BOC - parametre de dessin.xlsx"

-- Start an Excel OLE Object
x = CreateOLEObject "Excel.Application"

-- Create a new workbook in the new excel document
x.application.Workbooks.open(excelFile)

oColCount40 = (x.application.cells 30 2).value
oColSpacing40 = (x.application.cells 27 4).value
oColCount20 =  (x.application.cells 31 2).value
oColSpacing20 =  (x.application.cells 29 4).value
oRowCount = (x.application.cells 32 2).value
oRowSpacing =  (x.application.cells 28 4).value
oNbSpuds =  (x.application.cells 40 2).value

-- Close the spreadsheet
x.application.ActiveWorkbook.Close

-------------------------------------------------------------------------

-- Inserer le premier caisson 40'

myNewObjs = getMAXFileObjectNames oPath40
theXrefBox = xrefs.addNewXrefObject oPath40 myNewObjs

-- Pattern 40' de la premiere ligne

Caisson_40 = for item in myNewObjs collect getNodeByName item

i=0
for i = 1 to oColCount40-1
do
(
maxOps.CloneNodes Caisson_40 \
	offset:[0 ,i*oColSpacing40, 0] \
	expandHierarchy:true \
	cloneType:#instance \
	newNodes:&newnode
)

--------------------------------------------------------------------------

If ((mod oRowCount 2) == 0) do
(
	print "Largeur PAIR"
If (oColCount20 == 1) do
(
	print "Besoin 20 sur long"
	
-- insérer le dernier caisson BOC-20 à la fin de la 1ere rangée
myNewObjs = ""
myNewObjs = getMAXFileObjectNames oPath20
objXRefMgr.dupMtlNameAction = #useXRefed
objXRefMgr.AddXRefItemsFromFile oPath20 objNames: myNewObjs promptObjNames:false
Caisson_20 = for item in myNewObjs collect getNodeByName item
move Caisson_20 [0, oColCount40*oColSpacing40, 0]

-- insérer le premier caisson BOC-20 au début dse la 2eme rangée
maxOps.CloneNodes Caisson_20 \
offset:[oRowSpacing , 0, 0] \
expandHierarchy:true \
cloneType:#instance \
newNodes:&newnode

-- insérer le premier caisson BOC-40 au début dse la 2eme rangée
maxOps.CloneNodes Caisson_40 \
offset:[oRowSpacing ,oColSpacing20, 0] \
expandHierarchy:true \
cloneType:#instance \
newNodes:&newnode

-- Pattern 40' de 2eme ligne
i=0
for i = 1 to oColCount40-1
do
(
maxOps.CloneNodes Caisson_40 \
	offset:[oRowSpacing ,oColSpacing20+i*oColSpacing40, 0] \
	expandHierarchy:true \
	cloneType:#instance \
	newNodes:&newnode
)

XrefBind = ($*)
XrefCount = xrefs.getXRefFileCount() 
  
for i = 1 to XrefCount do   
( 
 CurrXRef = xrefs.getXRefFile i 
  
 for o in XrefBind do 
 ( 
  if o == CurrXRef.parent do 
  ( 
   UpdateXRef CurrXRef 
  ) 
 ) 
)  

aSelection = ( XrefBind as array ) --store the selection in an array

i=0
j=0
for i = 1 to ((oRowCount/2)-1) do
(
for j = 1 to aSelection.count do
(
	obj = aSelection[j] --pull the object from the array at index j
	x = (coordsys world obj.pos.x)
	y = (coordsys world obj.pos.y)
	z = (coordsys world obj.pos.z)
	
print obj
format "X:%, Y:%, Z:%\n" x y z

maxOps.CloneNodes obj \
	offset:[x+(i*oRowSpacing*2) , y, 0] \
	expandHierarchy:true \
	cloneType:#instance \
	newNodes:&newnode
	
)
)

-- Insérer le plan (eau)

Plane length:100000 width:100000 pos:[0, 0, 0] \
isSelected:on lengthsegs:100 widthsegs:100
	
)

)

 

 

thanks for your help

0 Likes
Message 4 of 4

Anonymous
Not applicable
Accepted solution

I found the solution.

 

I used the transform matrix of the object and it return the real world position

 

	x = obj.transform.pos.x
	y = obj.transform.pos.y
	z = obj.transform.pos.z