24
WS11-1 ADM704-705, Workshop 11, August 2005 Copyright 2005 MSC.Software Corporation WORKSHOP 11 MACROS: OVERVIEW

WS11-1 ADM704-705, Workshop 11, August 2005 Copyright 2005 MSC.Software Corporation WORKSHOP 11 MACROS: OVERVIEW

Embed Size (px)

Citation preview

Page 1: WS11-1 ADM704-705, Workshop 11, August 2005 Copyright  2005 MSC.Software Corporation WORKSHOP 11 MACROS: OVERVIEW

WS11-1ADM704-705, Workshop 11, August 2005Copyright 2005 MSC.Software Corporation

WORKSHOP 11

MACROS: OVERVIEW

Page 2: WS11-1 ADM704-705, Workshop 11, August 2005 Copyright  2005 MSC.Software Corporation WORKSHOP 11 MACROS: OVERVIEW

WS11-2ADM704-705, Workshop 11, August 2005Copyright 2005 MSC.Software Corporation

Page 3: WS11-1 ADM704-705, Workshop 11, August 2005 Copyright  2005 MSC.Software Corporation WORKSHOP 11 MACROS: OVERVIEW

WS11-3ADM704-705, Workshop 11, August 2005Copyright 2005 MSC.Software Corporation

WORKSHOP 11 - MACROS: OVERVIEW Problem statement

In this workshop you will become familiar with writing parameterless macros, while using the wing retraction model used previously in Workshop 9 – Understanding the Command Language and Workshop 10 – Conditional Constructs and Loops. You will be introduced to the differences between macros and command files, you will learn how to use the macro editor, and will write some parameterless macros.

Page 4: WS11-1 ADM704-705, Workshop 11, August 2005 Copyright  2005 MSC.Software Corporation WORKSHOP 11 MACROS: OVERVIEW

WS11-4ADM704-705, Workshop 11, August 2005Copyright 2005 MSC.Software Corporation

WORKSHOP 11 - MACROS: OVERVIEW

Getting started

To import the model:

1. Start ADAMS/View from the mod_11_parameterless_macros directory.

2. Import the wing retraction model, wing_retractor_start.cmd.

Page 5: WS11-1 ADM704-705, Workshop 11, August 2005 Copyright  2005 MSC.Software Corporation WORKSHOP 11 MACROS: OVERVIEW

WS11-5ADM704-705, Workshop 11, August 2005Copyright 2005 MSC.Software Corporation

WORKSHOP 11 - MACROS: OVERVIEW

Using Macro Record and Macro Replay One of the simplest ways to create a macro is to record one as you

perform operations in ADAMS/View. This recorded macro can then be played back later and the exact same operations will be executed again.

To record a series of operations: Use the macro record feature to save a favorite view and model

configuration.

1. Turn on Render view.

2. Turn on the visibility of icons (if they're not on already).

3. Initiate the macro recording operation: From the Tools menu, point to Macro, point to Record/Replay, and

then select Record Start.

Page 6: WS11-1 ADM704-705, Workshop 11, August 2005 Copyright  2005 MSC.Software Corporation WORKSHOP 11 MACROS: OVERVIEW

WS11-6ADM704-705, Workshop 11, August 2005Copyright 2005 MSC.Software Corporation

WORKSHOP 11 - MACROS: OVERVIEW

4. Select an Isometric view.

Your model should look similar to the following:

Page 7: WS11-1 ADM704-705, Workshop 11, August 2005 Copyright  2005 MSC.Software Corporation WORKSHOP 11 MACROS: OVERVIEW

WS11-7ADM704-705, Workshop 11, August 2005Copyright 2005 MSC.Software Corporation

WORKSHOP 11 - MACROS: OVERVIEW

5. Choose the center of the view to be near JOINT_15: From the View menu, point to Position/Orientation, select Center,

and then pick roughly at the location of JOINT_15 shown above.

Tip: The equivalent keyboard shortcut is c.

6. Zoom in dynamically using the z shortcut, until your view looks similar to the following:

Page 8: WS11-1 ADM704-705, Workshop 11, August 2005 Copyright  2005 MSC.Software Corporation WORKSHOP 11 MACROS: OVERVIEW

WS11-8ADM704-705, Workshop 11, August 2005Copyright 2005 MSC.Software Corporation

WORKSHOP 11 - MACROS: OVERVIEW

7. Stop the macro recording operation: From the Tools menu, point to Macro, point to Record/Replay, and

then select Record End.

8. Reset your view to a front view and fit to view.

9. Playback the macro you recorded: From the Tools menu, point to Macro, point to Record/Replay, and

then select Execute Recorded Macro. It should have returned your view to the zoomed-in Isometric view. You may have noticed that the cursor appears to be active,

highlighting objects as you move the mouse around. Almost as if it's in Pick mode, ready for you to pick something on the screen. Let’s investigate why.

10. Stop the highlighting mode by clicking the Select tool in the Main Toolbox.

Page 9: WS11-1 ADM704-705, Workshop 11, August 2005 Copyright  2005 MSC.Software Corporation WORKSHOP 11 MACROS: OVERVIEW

WS11-9ADM704-705, Workshop 11, August 2005Copyright 2005 MSC.Software Corporation

WORKSHOP 11 - MACROS: OVERVIEW

Reviewing the commands in a recorded macro

To review the commands:

1. Use the macro editor to see what commands were recorded: From the Tools menu, point to Macro, point to Edit, and then select

Modify.

In the Database Navigator, select record_macro.

Page 10: WS11-1 ADM704-705, Workshop 11, August 2005 Copyright  2005 MSC.Software Corporation WORKSHOP 11 MACROS: OVERVIEW

WS11-10ADM704-705, Workshop 11, August 2005Copyright 2005 MSC.Software Corporation

WORKSHOP 11 - MACROS: OVERVIEW

You should see commands in the editor that resemble the following:

Note: The text shown in the dialog box above may differ slightly from what you see. Every operation you performed has been recorded.

The second line shows an interface command being used. This was the one that put it in Pick mode, and can be removed because you won’t be prompted for the center (it was hardcoded with command C).

Page 11: WS11-1 ADM704-705, Workshop 11, August 2005 Copyright  2005 MSC.Software Corporation WORKSHOP 11 MACROS: OVERVIEW

WS11-11ADM704-705, Workshop 11, August 2005Copyright 2005 MSC.Software Corporation

WORKSHOP 11 - MACROS: OVERVIEW

2. Delete the commands B and E from the macro and select OK.

3. Reset the view to some other perspective of the model so you can test the macro.

4. Run the macro again.

The view returns to the zoomed view.

5. Run the macro again.

Notice that ADAMS/View zooms in more. That’s because the commands instruct ADAMS/View to increase the zoom, rather than set it to an exact value. If you don't want that effect, you have to change the commands. For example, you could insert commands for a Fit to View after the Iso.

6. Modify the recorded macro and insert the following command in the proper location: view zoom auto=on.

7. Run the macro a couple of times. It should no longer be zooming in more and more.

Page 12: WS11-1 ADM704-705, Workshop 11, August 2005 Copyright  2005 MSC.Software Corporation WORKSHOP 11 MACROS: OVERVIEW

WS11-12ADM704-705, Workshop 11, August 2005Copyright 2005 MSC.Software Corporation

WORKSHOP 11 - MACROS: OVERVIEW

Saving a recorded macro There can only be one macro named record_macro in the

database. If you were to start recording again, ADAMS/View would overwrite the one you just created. Rename the macro to save it in the database so it is not overwritten.

To save a recorded macro:1. Clear the select list by clicking the Select tool on the Main Toolbox.

2. From the Edit menu, select Rename.

Page 13: WS11-1 ADM704-705, Workshop 11, August 2005 Copyright  2005 MSC.Software Corporation WORKSHOP 11 MACROS: OVERVIEW

WS11-13ADM704-705, Workshop 11, August 2005Copyright 2005 MSC.Software Corporation

WORKSHOP 11 - MACROS: OVERVIEW

3. In the Database Navigator, perform the following: At the bottom to the right of the Filter box, choose All from the drop-

down list. This will allow the macro to be displayed above, as the Database Navigator normally filters macros out.

Select record_macro.

Select OK.

In the Rename Object dialog box that appears, in the New Name text box, enter .my_zoomed_view.

Select OK.

4. How do you think you can run the macro that you just saved?

_____Type my_zoomed_view at the command line.

_____Use the Command Navigator

_____All of the above.

_____None of the above.

Page 14: WS11-1 ADM704-705, Workshop 11, August 2005 Copyright  2005 MSC.Software Corporation WORKSHOP 11 MACROS: OVERVIEW

WS11-14ADM704-705, Workshop 11, August 2005Copyright 2005 MSC.Software Corporation

5. Export the macro to a file: From the Tools menu, point to Macro, and then select Write.

In the Macro_Name text box, enter .my_zoomed_view.

Leave the File Name text box blank.

Select OK.

6. Open the file with a text editor, and look at the command file that was written.

It shares more than just a strong resemblance to a command file because it is a command file. The reason it doesn't look special is because it's a parameterless macro. If the macro had parameters, it would look quite different. You'll learn more about these differences in the next workshop (Workshop 12 – Macros and Parameter Syntax). But for now you will practice recording another macro and then progress to writing a parameterless macro by hand.

WORKSHOP 11 - MACROS: OVERVIEW

Page 15: WS11-1 ADM704-705, Workshop 11, August 2005 Copyright  2005 MSC.Software Corporation WORKSHOP 11 MACROS: OVERVIEW

WS11-15ADM704-705, Workshop 11, August 2005Copyright 2005 MSC.Software Corporation

WORKSHOP 11 - MACROS: OVERVIEW

To record another macro:1. Now record another macro, whatever you'd like to try. Just make

sure you perform a variety of operations, at least five or six things.

2. Playback your newly recorded macro.

3. Did it work as expected? _____ Yes _____ No

You probably saw that it did more than you expected, or had problems because it couldn't do certain things twice. In general, the macro record operation is good for short tasks or a minimal set of operations.

4. Look at the recorded macro in the macro editor.

5. Are the commands fairly verbose and perhaps confusing to you?

_____ Yes ______ No

Page 16: WS11-1 ADM704-705, Workshop 11, August 2005 Copyright  2005 MSC.Software Corporation WORKSHOP 11 MACROS: OVERVIEW

WS11-16ADM704-705, Workshop 11, August 2005Copyright 2005 MSC.Software Corporation

WORKSHOP 11 - MACROS: OVERVIEW

6. Do you think it's possible to run the first macro (.my_zoomed_view) now that you've recorded a new macro? ______ Yes ______ No

7. Write T or F to indicate which of the following statements are true or false.

____ You can only run the last default macro you've created.

____ Although the Execute Recorded Macro menu option only lets you run a macro named record_macro, there are other ways to execute a macro.

____ You can run the macro by typing my_zoomed_view in the Command Window.

Page 17: WS11-1 ADM704-705, Workshop 11, August 2005 Copyright  2005 MSC.Software Corporation WORKSHOP 11 MACROS: OVERVIEW

WS11-17ADM704-705, Workshop 11, August 2005Copyright 2005 MSC.Software Corporation

WORKSHOP 11 - MACROS: OVERVIEW

Writing a parameterless macro As you saw earlier in the macro editor, the commands recorded

can be verbose and perhaps confusing. You can keep your macros concise, clean, and easier to read if you write them by hand.

Create a tool for previewing parts by writing a parameterless macro that displays each part, with a pause between each display operation, and then displays the model when it has finished.

To write a parameterless macro:1. From the Tools menu, point to Macro, point to Edit, and then

select New.

The Create /View Macro dialog box opens. By default, the macro name field is MACRO_1.

Page 18: WS11-1 ADM704-705, Workshop 11, August 2005 Copyright  2005 MSC.Software Corporation WORKSHOP 11 MACROS: OVERVIEW

WS11-18ADM704-705, Workshop 11, August 2005Copyright 2005 MSC.Software Corporation

WORKSHOP 11 - MACROS: OVERVIEW

2. If this macro were created, where do you think it would be stored in the database? Circle one:

a) .gui.MACRO_1

b) .mdi.MACRO_1

c) .MACRO_1

d) .<default_model>.MACRO_1

If you're not sure where an object (macro, dialog box, variable, and so on) will be stored by default, provide the absolute object name during creation (that is, .MACRO_1 instead of MACRO_1).

3. Clear the Macro Name text box and enter .Preview_Parts

Page 19: WS11-1 ADM704-705, Workshop 11, August 2005 Copyright  2005 MSC.Software Corporation WORKSHOP 11 MACROS: OVERVIEW

WS11-19ADM704-705, Workshop 11, August 2005Copyright 2005 MSC.Software Corporation

WORKSHOP 11 - MACROS: OVERVIEW

4. Clear the selection of Use Macro name.

Notice that you now have the option to enter your own command in the User-Entered Command text box to be used to execute the macro.

5. Select Use Macro name.

6. Check Yes for Wrap in undo.

7. Enter the following commands in the Commands area.

for var=the_part object=(eval(DB_CHILDREN(DB_DEFAULT (.System_Defaults,"model"),"part")))

part display part=(the_part) fit_to_view=yes

pause

end !for

model display fit_to_view=yes

Page 20: WS11-1 ADM704-705, Workshop 11, August 2005 Copyright  2005 MSC.Software Corporation WORKSHOP 11 MACROS: OVERVIEW

WS11-20ADM704-705, Workshop 11, August 2005Copyright 2005 MSC.Software Corporation

WORKSHOP 11 - MACROS: OVERVIEW8. Select OK to create the macro.

9. Run the macro by entering preview at the command line.

Note: You were able to execute your macro “Preview_Parts” with the abbreviated command preview because it was unique.

10. Press Enter on the keyboard when the Pause dialog box appears (as shown below).

Notice that the advantage of using a macro is you now have a command you can use, instead of needing to import a command file every time you want to perform a set of commands.

11. Look in the Command Navigator. See if you can find the command for your macro.

12. Export the macro, Preview_Parts, (using the Tools menu, pointing to Macro, and selecting Write), and name the file Preview_Parts.cmd.

Page 21: WS11-1 ADM704-705, Workshop 11, August 2005 Copyright  2005 MSC.Software Corporation WORKSHOP 11 MACROS: OVERVIEW

WS11-21ADM704-705, Workshop 11, August 2005Copyright 2005 MSC.Software Corporation

WORKSHOP 11 - MACROS: OVERVIEW

Creating a macro by importing a file Now that you've written a parameterless macro by hand and

learned that they're nothing more than command files, it is fairly straightforward to import them.

To import a macro:1. Create a parameterless macro from the command file

task_1_decision.cmd you used in the last workshop (Workshop 10 –Conditional Constructs and Loops).

From the Tools menu, point to Macro, and then select Read.

Complete the dialog box as follows: Macro Name: .wing_tip_generate

File Name: Browse to task_1_decision.cmd User Entered Command: marker generate wing_tip Wrap In Undo: yes Create Panel: no

Page 22: WS11-1 ADM704-705, Workshop 11, August 2005 Copyright  2005 MSC.Software Corporation WORKSHOP 11 MACROS: OVERVIEW

WS11-22ADM704-705, Workshop 11, August 2005Copyright 2005 MSC.Software Corporation

WORKSHOP 11 - MACROS: OVERVIEW

2. Select OK.

3. Run the macro.

Tip: Use the User-Entered Command.

4. Export the macro.

Tip: From the Tools menu, point to Macro, and then select Write.

5. Open the file in a text editor.

6. Do you notice anything that looks different?

The first line has a special entry, which is particular to macros. You will learn more about that in the next Module (Macros: Syntax and Parameters).

7. Save your database.

8. Exit ADAMS/View.

Page 23: WS11-1 ADM704-705, Workshop 11, August 2005 Copyright  2005 MSC.Software Corporation WORKSHOP 11 MACROS: OVERVIEW

WS11-23ADM704-705, Workshop 11, August 2005Copyright 2005 MSC.Software Corporation

WORKSHOP 11 - MACROS: OVERVIEW Optional tasks

1. Create a parameterless macro from the file show_joint_and_parents_only.cmd.

The Preview_parts concept has been extended further to show a joint and its parent parts. It also animates the degrees-of-freedom (DOF) for the joint. To see it in action:

Start a new database.

Import the file completed/optional/test_model.cmd.

Wiggle the joint DOFs by importing the file, create_parameterless_macro.cmd.

This file imports the following macros:   show_joints_and_parents_only.cmd

  user_entered command = show_joints_and_parents

  constraint_dof_wiggler.cmd    user_entered command = constraint wiggler

Page 24: WS11-1 ADM704-705, Workshop 11, August 2005 Copyright  2005 MSC.Software Corporation WORKSHOP 11 MACROS: OVERVIEW

WS11-24ADM704-705, Workshop 11, August 2005Copyright 2005 MSC.Software Corporation

WORKSHOP 11 - MACROS: OVERVIEW

Run the macros using their command.

Open the file, constraint_DOF_wiggler.cmd to see how this macro was created using ADAMS/View commands. Notice how important comments are in documenting your work in a macro.