3ds Max – Creating City Blocks – Part 20 – Using the Macro Recorder

3ds Max – Creating City Blocks – Part 20 – Using the Macro Recorder

September 24, 2019 0 By Kailee Schamberger


In the last movie, you created your first building’s street level mainly by extruding a 2D shape. There were a few steps involved, none too difficult but quite a few that become repetitive when dealing with additional floors. In this movie, you take a look at optimizing your workflow by scripting repetitive tasks. Let’s revisit the scene from the last movie: use your own file or the file named: CityBlocks_Bldgs-macros.max that’s been provided to you. Select the street level extrusion and go to the Modify panel to take a look at how it was created. Initially, it was created by duplicating an existing 2D spline as a reference. Then an Extrude Modifier was applied, using a preliminary height value. Ultimately, you have also settled on disabling capping options, that’s two additional tasks that can be scripted. Furthermore, you added a UVW Map modifier which you set to Box mode and ensured it’s working in Real-World mode. Let’s see how you can automate these tasks so you don’t have to manually repeat them every time you add a new level. Most 3D artists are not programmers by trade, but you’d be surprised how much you can achieve with the help of the Macro Recorder. Select the original 2D shape, here named Angle001 and isolate it. Deselect the spline when done. Right-click in the bottom-left corner and open the Listener Window. Depending whether or not you’ve used it before, the macro-recorder section may be hidden from view. If that’s the case, make sure you set the dialog so that you can see both the white and pink sections. From the MacroRecorder menu, make sure the recorder is enabled. From this point on, most actions you do will be shown in code. For example, if you select the 2D shape, you will see a record of that. If you make a reference out of it using Ctrl+V, additional lines of code appear. In this case, the first line relates to the Clone Options dialog and can ultimately be discarded. You won’t need to see the dialog to automate the tasks. The second line of code is the actual creation of the duplicate in reference mode, and the third line of code selects the new object. Add an Extrude modifier and give it a preliminary height, say about 6m. Watch the code as it unfolds. Note that the extrude amount is different from what you set a moment ago. In this case, this is because the Display Units are in meters but the System Units are in Feet. 6m equal 19.685 feet. Adjust the caps to make sure they’re disabled. The code updates accordingly. Delete lines of code that are redundant or not needed. In fact, remove the second line that relates to the display of the clone dialog. As mentioned earlier, you won’t need it. Make sure the cursor is at the bottom of the paragraph and add a UVW Map modifier. Set it to Box mode and to use Real-World mapping. Again the code is updated. The code is almost ready to be tested but you can do one or two things to improve it further. Look at the first line, where an object is selected by its specific name. This can prove troublesome, as the shape and its name can change, so you need a better solution. Also, it would be good to work in a hierarchy mode where all levels are children of the main base 2D shape. This will simplify repositioning the building if you need to. With that in mind, you will define a variable name for the base spline, which the script will assume is already selected. Remove the first line and replace it by papa=$ Here, the variable named “papa” is being assigned to the current selection, represented by a $ sign. If you find the term papa too corny, you can replace it by something else, although I find the term papa appropriate for a parent object. Add a line right before the Extrude modifier action and write: nnl.parent=papa Let’s take a look at what it means: The second line of code as mentioned earlier created a reference clone and assigned it to a variable named nnl. The third line, select nnl selects the new object. So by that time, the duplicate is selected and ready to be parented. The new line that you added, nnl.parent=papa is basically saying that the parent for the newly created clone, (which is now selected), is now in fact the original spline also known in code as papa. Disable the recorder when done. You can always enable it again later if you need to. For now, let’s see how you can test and use the script you created. Co to Customize>Customize User Interface and choose the Toolbars tab. Click the New button and give your new toolbar a name, such as MyBuildingTools and click OK. A new toolbar is created but has no icons or functionality just yet. Select the script that you ended up with in the macro recorder and drag it to your newly created toolbar. A new button is created and you can control its appearance with a right-click. Use the Text Button option and give it a label such as: Create Floor, and then click OK. Dismiss the dialogs and delete or hide the extruded wall you created previously. Select the original 2D shape and test your script by pressing the Create Floor button. Voila! Magiců verify the modifiers and you’ll find them to be set exactly as designed. What’s more, the extruded floor is now a child of the base spline and that simplifies relocation. To create another floor, make sure the original shape is selected and hit Create Floor again. This creates a second extruded floor in exactly the same spot as the first one. You can move it up in Z so that one floor sits on top of the other. You can also automate that task with yet another script. Open the Listener Window again and delete the previous script. Instead, type the following line: selected=$ As before, this is simply assigning a variable named “selected” to the currently selected object. In this case, the currently selected object is the upper floor that you need to move up. As a second line type in: temp=(pickobject prompt:”Pick Level…”) This is assigning a variable named temp to an existing level you need to specify in the viewport, using the ‘pickobject” command. Finally, add the line: selected.position.z=temp.position.z+(temp.modifiers[#Extrude].amount) This is saying that the “selected” (upper floor) z-position, is the same as the “temp” (lower floor) z-position, added to the extrusion height of the floor below. Select those three lines and add them to your new toolbar. Name the tool: Align Level, and then dismiss the listener window. Test it out: with the upper floor selected, click the Align Tool button and then click the lower floor. The upper floor is correctly relocated. Keep in mind the script is still based on a manual operation and contains no “intelligence”. This means that if you decide to change the extrusion height of the lower floor, you’d need to run the Align Level script again. Still, it’s much faster than having to manually adjust the level using transform type-ins, align tool or snap modes. With the scripts in place, remove any floors you may have created and exit Isolate mode. Use the link tool to link the first level to the main base shape, since that level was built entirely manually. It may be easier to use the Select from Scene dialog to prevent any errors. This linking task will be automated for future floors as the process is now built into the script you created. Save your file, in the next movie, you finalize your first low-poly building.