Placement & Spinner

Hello, I'd love to have some help with the following script. It is an important way we place objects in a scene at our office.

The majority of the code is actually there (already because of many of you) but i like to tie it together with this script and there are some issues that still need to be resolved. De script contains:

1. a button for placing one or multiple objects through my mouse position (this works well already).
2. a spinner which should adjust the z=value when placing objects (default value should be 0).
3. a button to take the z-value of a selected object that is already in the scene and use that value to replace the default 0 value of the spinner (so it can be used to place something on that specific height again).

One of the issues that i also ran into before was that when i had an object which was already on a certain z-value, is that the mouse position is still at z=0, while x and y are based on my mouse position. So what i would like is when i place an object at z=300 through the spinner, that my cursor actually uses the right z=value, instead of staying at z=0.

I hope it makes sense :) and hopefully some of you could help me out.
Thank you!

-- SCRIPT

rollout rollout3 "Placement"
(
button placeObjects "Place" tooltip:"Place the selected objects" width:90 across:3
spinner amount "" type:#integer range:[-10000,10000,0] width:80 align:#center
button useHeight "Use Height" tooltip:"Use the height of a selected object" width:90

on placeObjects pressed do (
tool selectionMover numPoints:1
(
local lastoffset
local prevCenter = selection.center
on freeMove do
(
if lastoffset != undefined do selection.center -= lastoffset
offset = (gridPoint - prevCenter) * [1,1,0]
selection.center += offset
lastoffset = offset
)
)
if selection.count != 0 do startTool selectionMover
)

on useHeight pressed do (
if selection.count == 1 do amount.value = selection[1].pos.z
)
)

RolloutFloaterTemplate = newrolloutfloater "Workflow" 319 58
addrollout rollout3 RolloutFloaterTemplate

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
remykonings's picture

*

It doesn't seem to work well in our scenes. We have huge scenes with 30 xrefs sometimes (all buildings).

Thanks for showing me that alternative, i appreciate the insight a lot. Though I still think that the script as i initially posted it - with those improvements - would work best for us to be honest.

jahman's picture

.

Sounds like you're trying to recreate max native Select and Place tool.
If your max doesn't support it, there's an alternative

remykonings's picture

*

Thank you, It has some similar functions yes but it would not work well for us since we use xRefs a lot, so a surface will not be recognized. Therefor i need to control the z-value myself.

I also like to do it in this way since we have a network toolbar where this script would be part if.

jahman's picture

.


it would not work well for us since we use xRefs a lot, so a surface will not be recognized

It is a shame if max tool doesn't recognize xref surfaces.

I've just checked it with xref scene and it works pretty well.
Here's an example how you can make it.

delete helpers
pt = point centermarker:on cross:off wirecolor:yellow
 
fn callback_fn msg ir obj faceNum shift ctrl alt =
(
 
	if ir != undefined do ::pt.pos = ir.pos
 
	if msg == #mouseAbort do return #end
 
	#continue 
)
 
xref  = xrefs.getXRefFile 1
nodes = xref.tree.children
mouseTrack on:nodes trackCallback:callback_fn
remykonings's picture

*

It doesn't seem to work well in our scenes. We have huge scenes with 30 xrefs sometimes (all buildings).

Thanks for showing me that alternative, i appreciate the insight a lot. Though I still think that the script as i initially posted it - with those improvements - would work best for us to be honest.

jahman's picture

.

But why do you get desired Height offset from .pos property?

try (destroydialog rollout3 ) catch ()
 
rollout rollout3 "Placement" width:300
(
	button placeObjects "Place" tooltip:"Place the selected objects" width:90 across:3
	spinner amount "" type:#worldunits range:[-1e9,1e9,0] offset:[0,3]width:80 align:#center
	button useHeight "Use Height" tooltip:"Use the height of a selected object" width:90
 
	tool selectionMover numPoints:1
	(
		local lastoffset
		local prevCenter = selection.center	
 
		on freeMove do
		(			
			if lastoffset != undefined do selection.center -= lastoffset
			offset = (gridPoint - prevCenter) * [1,1,0] + [ 0, 0, amount.value ]
			selection.center += offset
			lastoffset = offset
		)
	)
 
	on placeObjects pressed do
	(	
		if selection.count != 0 do startTool selectionMover
	)
 
	on useHeight pressed do if selection[1] != undefined do
	(
		amount.value = selection[1].max.z
	)
)
 
createDialog rollout3 pos:[100,100]
remykonings's picture

.

The z-value has to do with colleagues making interior scenes at a certain height other then 0. If they place an object in a camera view (this is how they prefer to work, instead of two viewports) in the way the script now works, then the mouse position goes off the viewport because the z-value stays at 0. It is because they work in the camera view which is static and perspective. Therefor it would work better if the mouse position really follows the object, so when they have the mouse position at a certain place that the proxy is actually there instead of above with the height that is being given through the spinner.

I also noticed that the spinner is like a move function instead of an actually height. Do you think that is possible to change? And i think that the use Height function also check for the middle point of the proxy/object yes? instead of the pivot?

Thanks for you help so far :)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.