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

By
-
Login to Follow
-
Industry
  • Design Visualization
Subject
  • Animation
  • Modeling
  • Scripting
  • 2014
  • Environment
  • Workflow
Products
  • 3ds Max
Skill Level
  • Intermediate
Duration
10 min

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

In this tutorial, you use the Macro Recorder to record and reuse the repetitive tasks you needed to create a floor volume. You then create a new 3ds Max toolbar in which you add a button that invokes your custom scripts.

Notes

Transcript

1
00:00:06,504 --> 00:00:12,803
In the last movie, you created your first building's street level mainly by extruding a 2D shape.

2
00:00:13,178 --> 00:00:19,356
There were a few steps involved, none too difficult but quite a few that become repetitive when dealing with additional floors.

3
00:00:19,761 --> 00:00:25,938
In this movie, you take a look at optimizing your workflow by scripting repetitive tasks.

4
00:00:26,236 --> 00:00:35,689
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.

5
00:00:36,640 --> 00:00:42,640
Select the street level extrusion and go to the Modify panel to take a look at how it was created.

6
00:00:43,140 --> 00:00:48,430
Initially, it was created by duplicating an existing 2D spline as a reference.

7
00:00:48,820 --> 00:00:54,350
Then an Extrude Modifier was applied, using a preliminary height value.

8
00:00:54,940 --> 00:01:01,920
Ultimately, you have also settled on disabling capping options, that's two additional tasks that can be scripted.

9
00:01:02,813 --> 00:01:10,659
Furthermore, you added a UVW Map modifier which you set to Box mode and ensured it's working in Real-World mode.

10
00:01:11,285 --> 00:01:16,618
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.

11
00:01:17,201 --> 00:01:24,622
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.

12
00:01:25,324 --> 00:01:34,018
Select the original 2D shape, here named Angle001 and isolate it. Deselect the spline when done.

13
00:01:35,153 --> 00:01:38,979
Right-click in the bottom-left corner and open the Listener Window.

14
00:01:39,425 --> 00:01:44,497
Depending whether or not you've used it before, the macro-recorder section may be hidden from view.

15
00:01:44,850 --> 00:01:51,010
If that's the case, make sure you set the dialog so that you can see both the white and pink sections.

16
00:01:51,600 --> 00:01:59,170
From the MacroRecorder menu, make sure the recorder is enabled. From this point on, most actions you do will be shown in code.

17
00:01:59,830 --> 00:02:05,291
For example, if you select the 2D shape, you will see a record of that.

18
00:02:06,009 --> 00:02:11,722
If you make a reference out of it using Ctrl+V, additional lines of code appear.

19
00:02:12,280 --> 00:02:17,776
In this case, the first line relates to the Clone Options dialog and can ultimately be discarded.

20
00:02:18,030 --> 00:02:21,060
You won't need to see the dialog to automate the tasks.

21
00:02:21,480 --> 00:02:30,910
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.

22
00:02:31,640 --> 00:02:36,835
Add an Extrude modifier and give it a preliminary height, say about 6m.

23
00:02:37,462 --> 00:02:43,713
Watch the code as it unfolds. Note that the extrude amount is different from what you set a moment ago.

24
00:02:44,041 --> 00:02:53,637
In this case, this is because the Display Units are in meters but the System Units are in Feet. 6m equal 19.685 feet.

25
00:02:54,700 --> 00:02:59,750
Adjust the caps to make sure they're disabled. The code updates accordingly.

26
00:03:00,611 --> 00:03:03,948
Delete lines of code that are redundant or not needed.

27
00:03:04,310 --> 00:03:11,900
In fact, remove the second line that relates to the display of the clone dialog. As mentioned earlier, you won't need it.

28
00:03:12,540 --> 00:03:17,950
Make sure the cursor is at the bottom of the paragraph and add a UVW Map modifier.

29
00:03:18,658 --> 00:03:25,246
Set it to Box mode and to use Real-World mapping. Again the code is updated.

30
00:03:26,099 --> 00:03:31,124
The code is almost ready to be tested but you can do one or two things to improve it further.

31
00:03:31,531 --> 00:03:36,005
Look at the first line, where an object is selected by its specific name.

32
00:03:36,600 --> 00:03:42,470
This can prove troublesome, as the shape and its name can change, so you need a better solution.

33
00:03:43,020 --> 00:03:49,630
Also, it would be good to work in a hierarchy mode where all levels are children of the main base 2D shape.

34
00:03:50,139 --> 00:03:53,400
This will simplify repositioning the building if you need to.

35
00:03:53,680 --> 00:04:00,981
With that in mind, you will define a variable name for the base spline, which the script will assume is already selected.

36
00:04:01,558 --> 00:04:07,221
Remove the first line and replace it by papa=$

37
00:04:07,660 --> 00:04:14,680
Here, the variable named "papa" is being assigned to the current selection, represented by a $ sign.

38
00:04:15,162 --> 00:04:23,026
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.

39
00:04:23,773 --> 00:04:32,357
Add a line right before the Extrude modifier action and write: nnl.parent=papa

40
00:04:32,690 --> 00:04:34,660
Let's take a look at what it means:

41
00:04:35,050 --> 00:04:41,280
The second line of code as mentioned earlier created a reference clone and assigned it to a variable named nnl.

42
00:04:41,978 --> 00:04:50,762
The third line, select nnl selects the new object. So by that time, the duplicate is selected and ready to be parented.

43
00:04:51,264 --> 00:05:01,998
The new line that you added, nnl.parent=papa is basically saying that the parent for the newly created clone, (which is now selected),

44
00:05:02,430 --> 00:05:07,020
is now in fact the original spline also known in code as papa.

45
00:05:07,813 --> 00:05:12,461
Disable the recorder when done. You can always enable it again later if you need to.

46
00:05:13,140 --> 00:05:18,200
For now, let's see how you can test and use the script you created.

47
00:05:18,780 --> 00:05:24,850
Co to Customize > Customize User Interface and choose the Toolbars tab.

48
00:05:25,502 --> 00:05:32,569
Click the New button and give your new toolbar a name, such as MyBuildingTools and click OK.

49
00:05:33,010 --> 00:05:38,550
A new toolbar is created but has no icons or functionality just yet.

50
00:05:39,120 --> 00:05:46,270
Select the script that you ended up with in the macro recorder and drag it to your newly created toolbar.

51
00:05:46,938 --> 00:05:51,356
A new button is created and you can control its appearance with a right-click.

52
00:05:51,851 --> 00:05:59,247
Use the Text Button option and give it a label such as: Create Floor, and then click OK.

53
00:06:00,250 --> 00:06:06,130
Dismiss the dialogs and delete or hide the extruded wall you created previously.

54
00:06:08,187 --> 00:06:13,926
Select the original 2D shape and test your script by pressing the Create Floor button.

55
00:06:14,130 --> 00:06:21,570
Voila! Magic… verify the modifiers and you'll find them to be set exactly as designed.

56
00:06:26,160 --> 00:06:33,706
What's more, the extruded floor is now a child of the base spline and that simplifies relocation.

57
00:06:34,170 --> 00:06:40,310
To create another floor, make sure the original shape is selected and hit Create Floor again.

58
00:06:41,150 --> 00:06:45,662
This creates a second extruded floor in exactly the same spot as the first one.

59
00:06:46,100 --> 00:06:50,380
You can move it up in Z so that one floor sits on top of the other.

60
00:06:51,024 --> 00:06:54,626
You can also automate that task with yet another script.

61
00:06:55,120 --> 00:06:58,410
Open the Listener Window again and delete the previous script.

62
00:06:58,902 --> 00:07:04,827
Instead, type the following line: selected=$

63
00:07:06,049 --> 00:07:12,117
As before, this is simply assigning a variable named "selected" to the currently selected object.

64
00:07:12,521 --> 00:07:17,892
In this case, the currently selected object is the upper floor that you need to move up.

65
00:07:18,825 --> 00:07:33,051
As a second line type in: temp = (pickobject prompt:"Pick Level...")

66
00:07:33,705 --> 00:07:41,974
This is assigning a variable named temp to an existing level you need to specify in the viewport, using the 'pickobject" command.

67
00:07:42,850 --> 00:08:04,904
Finally, add the line: selected.position.z=temp.position.z+(temp.modifiers[#Extrude].amount)

68
00:08:05,389 --> 00:08:18,499
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.

69
00:08:19,366 --> 00:08:23,564
Select those three lines and add them to your new toolbar.

70
00:08:24,674 --> 00:08:32,257
Name the tool: Align Level, and then dismiss the listener window.

71
00:08:32,890 --> 00:08:43,980
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.

72
00:08:45,128 --> 00:08:50,349
Keep in mind the script is still based on a manual operation and contains no "intelligence".

73
00:08:50,629 --> 00:08:57,399
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.

74
00:08:57,804 --> 00:09:06,233
Still, it's much faster than having to manually adjust the level using transform type-ins, align tool or snap modes.

75
00:09:11,950 --> 00:09:18,300
With the scripts in place, remove any floors you may have created and exit Isolate mode.

76
00:09:19,769 --> 00:09:26,638
Use the link tool to link the first level to the main base shape, since that level was built entirely manually.

77
00:09:27,200 --> 00:09:31,411
It may be easier to use the Select from Scene dialog to prevent any errors.

78
00:09:31,969 --> 00:09:38,646
This linking task will be automated for future floors as the process is now built into the script you created.

79
00:09:39,141 --> 00:09:43,679
Save your file, in the next movie, you finalize your first low-poly building.

Posted By
Tags
  • 3ds Max
  • Animation
  • Modeling
  • Scripting
  • 2014
  • Environment
  • Workflow
0 Comments
To post a comment please login or register
*Save $70 per month on Autodesk's Suggested Retail Price (SRP) when purchasing 1 year term 3ds Max or Maya subscription.