Basics – Part 5

Estimated reading: 5 minutes 186 views

Constructing an Inset / Outline Spinner Action

Now let’s put together what we have learnt in the previous 5 lessons.

  • ModPanel.GetCurrentObject()
  • ClassOf
  • For Loop
  • If Statement

Now we will reconstruct the “Inset” Button that you can find in the Modeling Octopus Menu. That action uses all of these and that represents all of the above. So what is happening is also relatively simple. I’ll guide you through on all of the things that are happening here.

max modify mode
currentMod = ModPanel.GetCurrentObject()

segs = abs {2}
amount = (({0} as float) / segs)

if segs < 1 then -- Outline
(
	if ClassOf(currentMod) == Edit_Poly then
	(
		currentMod.outlineAmount = ( {0} as float )
		currentMod.ButtonOp #Outline
	)
	else
	(
		currentMod.outlineAmount = ( {0} as float )
		currentMod.EditablePoly.Outline()
	)
)
else -- Inset
(
	for i = 1 to segs do
	(
		if ClassOf(currentMod) == Edit_Poly then
		(
			currentMod.insetAmount = amount 
			currentMod.ButtonOp #Inset
		)
		else
		(
			currentMod.insetAmount= amount 
			currentMod.buttonOp #Inset
		)
	)
)

So let’s break down the code to make more sense. Probably you will understand it better. The first part is just a few declarations, so we can use these later.

max modify mode

This line turns on the Modify mode and bring on top the Modifier Panel if it’s not already there. (Who knows, we are maybe at the Create panel.

currentMod = ModPanel.GetCurrentObject()

We know this. This is our object.

segs = abs {2}
amount = (({0} as float) / segs)

Here we are altering the dynamic variables a bit and preparing it for later use.

if segs < 1 then -- Outline
(
	if ClassOf(currentMod) == Edit_Poly then
	(
		currentMod.outlineAmount = ( {0} as float )
		currentMod.ButtonOp #Outline
	)
	else
	(
		currentMod.outlineAmount = ( {0} as float )
		currentMod.EditablePoly.Outline()
	)
)
else -- Inset
(
	for i = 1 to segs do
	(
		if ClassOf(currentMod) == Edit_Poly then
		(
			currentMod.insetAmount = amount 
			currentMod.ButtonOp #Inset
		)
		else
		(
			currentMod.insetAmount= amount 
			currentMod.buttonOp #Inset
		)
	)
)

The selected line are splitting up our code into two different branches. If we set the segs or other words the {2} dynamic variable to 0 (which is smaller than 1), our function will behave as an outline. If it’s greater than 0, then it will behave as an Inset.

Now let’s go one scope deeper in our code and let’s examine the outline part.

if segs < 1 then -- Outline
(
	if ClassOf(currentMod) == Edit_Poly then
	(
		currentMod.outlineAmount = ( {0} as float )
		currentMod.ButtonOp #Outline
	)
	else
	(
		currentMod.outlineAmount = ( {0} as float )
		currentMod.EditablePoly.Outline()
	)
)
else -- Inset
(
	for i = 1 to segs do
	(
		if ClassOf(currentMod) == Edit_Poly then
		(
			currentMod.insetAmount = amount 
			currentMod.ButtonOp #Inset
		)
		else
		(
			currentMod.insetAmount= amount 
			currentMod.buttonOp #Inset
		)
	)
)

Here we are splitting up the code again. The first branch handles the Edit_Poly modifier case, then the second one the ordinary Editable_Poly object case. We just simply set the {0} dynamic value as a float and then we assign that value to the outlineAmount of our object.

As I mentioned before the Edit_Poly is normally using the ButtonOp() function and the name of the button, to execute the command, while the Editable_Poly has it’s own Outline function for this purpose.

Ok now let’s just jump to the Inset part.

if segs < 1 then -- Outline
(
	if ClassOf(currentMod) == Edit_Poly then
	(
		currentMod.outlineAmount = ( {0} as float )
		currentMod.ButtonOp #Outline
	)
	else
	(
		currentMod.outlineAmount = ( {0} as float )
		currentMod.EditablePoly.Outline()
	)
)
else -- Inset
(
	for i = 1 to segs do
	(
		if ClassOf(currentMod) == Edit_Poly then
		(
			currentMod.insetAmount = amount 
			currentMod.ButtonOp #Inset
		)
		else
		(
			currentMod.insetAmount = amount 
			currentMod.buttonOp #Inset
		)
	)
)

Here we are using a for loop and a segs value. Since 3dsmax does not support segment insertion while you are performing a simple Inset, you have to do that several times if you decide to do that. But here comes maxscript in handy, because we can create multiple insets with the for loop. Remember! Ony by one at once!

So what we are doing here is pretty simple. Previously we have created two variables

segs = abs {2}
amount = (({0} as float) / segs)

In this case we have divided the {0} dynamic variable (which is the amount of the Inset) with the number of segments that we would like to insert. This means that if we need 5 segments and we set the overall amount to 10, then each segment will have a distance of 2 from each other, so our new amount is 2.

Now moving back to our original code we just simple repeat the Inset operation 5 times, using the new amount value which is 2, ending up in an overall length of 10, that contains 5 segments.

(
	for i = 1 to segs do
	(
		if ClassOf(currentMod) == Edit_Poly then
		(
			currentMod.insetAmount = amount 
			currentMod.ButtonOp #Inset
		)
		else
		(
			currentMod.insetAmount = amount 
			currentMod.buttonOp #Inset
		)
	)
)

Now let’s paste entire code we have created into the Command Editor.

Now we have created our beautiful and powerful Inset/Outline combo, segment supported maxscript, inside Octopus. Let’s see what we can do with it shall we?

Now this was quite cool. With just a few lines we have extended the overall functionality of the built-in Inset tool with a cool segments feature and on top of that we have also embedded the Outline functionality into the same tool, while we have handled the Edit_Poly and Editable_Poly cases as well. :) And we have not even written thousands of lines of code. :)

If you understood this lesson, then it’s time to jump into the deep water. ;)

Share this Doc

Basics – Part 5

Or copy link

CONTENTS
Shopping Cart
×