Hello Scriptspot community,
I would like to have a script to align an object, by just picking an source object and it would align my selection min, to max positon of the source Object.
just for one Button, to fasten the Workflow.
Regards.
Forum topic · Scripts Wanted
By Dragan_ilic · 2019-01-30
Hello Scriptspot community,
I would like to have a script to align an object, by just picking an source object and it would align my selection min, to max positon of the source Object.
just for one Button, to fasten the Workflow.
Regards.
Hi MiauuI modify your code
titane357 · 2019-02-14
Hi Miauu
I modify your code to make use more faster (no ui)
Is there a way to make a rubberband from each selected object ? Now just first one have a rubberband...
obj1 = selection
obj = pickObject rubberBand:obj1[1].pos
if obj != undefined and selection.count != 0 do
(
for o in selection do
(
o.pos.z = obj.max.z + (o.pos.z - o.min.z)
)
)
.
miauu · 2019-02-14
Hi!
Rubberband accept only one point3 value. Instead of it you can use custon rubberband:
(
global DrawCustomRubberband
unRegisterRedrawViewsCallback DrawCustomRubberband
local selObjsArr = selection as array
local selObjsPosArr = for o in selObjsArr collect o.pos
function DrawCustomRubberband =
(
if selObjsArr.count != 0 do
(
local pointsArr = for p in selObjsPosArr collect (gw.transPoint p)
local p3ViewCameraWorldPos = (inverse(getViewTM())).row4
local p3ViewCameraWorldDir = -(inverse(getViewTM())).row3
local fViewAngle = acos(dot (normalize(selObjsPosArr[1] - p3ViewCameraWorldPos)) p3ViewCameraWorldDir)
local fViewDepth = (distance selObjsPosArr[1] p3ViewCameraWorldPos) * (cos fViewAngle)
local p2MouseScreenPos = mouse.pos
local p3MouseViewPos = mapScreenToView p2MouseScreenPos (-fViewDepth)
local p3MouseWorldPos = p3MouseViewPos * inverse(getViewTM())
gw.setTransform(Matrix3 1)
local firstPointEnd = (gw.TransPoint p3MouseWorldPos)
try(firstPointEnd.z = 0)catch()
gw.setcolor #line (color 56 156 256)
for k = 1 to pointsArr.count do gw.wPolyline #(firstPointEnd, pointsArr[k]) off
gw.enlargeUpdateRect #whole
gw.updateScreen()
)
)
registerRedrawViewsCallback DrawCustomRubberband
obj = pickObject()
if obj != undefined and selection.count != 0 then
(
for o in selection do
(
o.pos.z = obj.max.z + (o.pos.z - o.min.z)
)
unRegisterRedrawViewsCallback DrawCustomRubberband
)
else
(
unRegisterRedrawViewsCallback DrawCustomRubberband
)
)
titane357 · 2019-02-15
Hi, thanks !!! and we can change color of lines !! :-)
but in 2019, I need to remove first "unRegisterRedrawViewsCallback DrawCustomRubberband"
or an error pop up...
.
jahman · 2019-02-15
Then you may end up registering redraw callbacks multiple times without any possibility to unregister it in future.
.
miauu · 2019-02-15
In max 2019 is... funny. :)
Just put the first "unRegisterRedrawViewsCallback DrawCustomRubberband" in try()catch() statement. It is not the best option but it works. Or you will face what jahman wrote.
Dragan_ilic · 2019-02-01
Wow thank you very much
.
miauu · 2019-01-31
Select the objcets that you want to align. Run the script, press the [Pick source object] button and pick the object to which you want to align.
(
global rol_alignTo
try(destroyDialog rol_alignTo)catch()
rollout rol_alignTo "miauu"
(
pickbutton pbtn_getObj "Pick source object" width:140
on pbtn_getObj picked obj do
(
if obj != undefined and selection.count != 0 do
(
for o in selection do
(
o.pos.z = obj.max.z + (o.pos.z - o.min.z)
)
)
)
)
createdialog rol_alignTo
)