ScriptSpot

Forum topic · Scripts Wanted

Scale to the parent object

By ibm · 2019-03-22

Description

Guys help.
Find the script that will scale to the parent object.

Example attached.

Thanks

Attachments
Comments (3)

.

jahman · 2019-03-22


child  = pickObject()
parent = pickObject()

if isValidNode child and isValidNode parent do
(
	
  about child.center
  (
		local target_scale = (parent.max - parent.min) / (child.max - child.min)

		if (abs target_scale[1]) < 0.0001 or bit.isNAN target_scale[1] do target_scale[1] = 0
		if (abs target_scale[2]) < 0.0001 or bit.isNAN target_scale[2] do target_scale[2] = 0
		if (abs target_scale[3]) < 0.0001 or bit.isNAN target_scale[3] do target_scale[3] = 0

		child.scale *= target_scale
  )

  
-- comment this line if you don't need to move child to parent center
  child.center = parent.center

)

Thanks for the reply

ibm · 2019-03-22

It is possible that the parent can be not only a square, but also a rectangle.
It is desirable that the child was not tied to the parent.

and what would the properties of the child was loose, now they are blocked

sorry for my English, it's all mechanical translation :)

.

jahman · 2019-03-22

maybe this thread could help you


  scale child ((parent.max - parent.min) / (child.max - child.min))
  child.center = parent.center