INSERTING OBJECTS and ELEMENTS
In this lecture, we will discuss the ability to insert an object into MathCAD as well as certain types of MathCAD elements. In our case, consider an object any file not native to MathCAD. This may include Excel spreadsheets, MS Word documents, AutoCAD drawings, a number of graphic formats, or any other file generated by a program that supports Object Linking and Embedding (OLE). To insert a file into MathCAD, a program capable of generating the file must be installed on your computer. However, depending upon how you inserted the file, a user does not necessarily have to own the client program to view the inserted object. More on this later.

The Insert menu includes a number of items that can be inserted into a MathCAD document. At this time, we will concentrate only on 'Object', 'Picture', and 'Reference' as found on the pull-down menu.

One can argue that the 'Picture' and 'Reference' items are not objects, at least not in the same sense as the OLE object described above. We might consider these MathCAD elements. However, they are handled in much the same fashion as an OLE object, thus are discussed here.

A MathCAD 'Component', as found on the 'Insert' menu, is an object with the ability to interact with MathCAD. We will save our discussion of component objects for Week 8 when we look at the interaction of third-party programs, such as Excel, Databases, MatLAB, etc. with MathCAD.
The figure to the left is an object insertion of an existing AutoCAD drawing. It was inserted by selecting 'Insert > Object' from the insert menu. By selecting 'Create from File' in the resulting dialogue, one can browse to the file location. You then select the file and click 'OK' on the dialogue box. Once the file is inserted, you can double click on the object to edit the file with AutoCAD. Obviously, you must have AutoCAD installed. The inserted object may also be resized by clicking on the object once with the mouse, then dragging the image using the black 'handles' on the right, bottom and bottom right corner of the object.
This image is simply a GIF file inserted as an object in a fashion identical to the AutoCAD drawing above. A GIF file is one of several graphics files used on the internet; thus you can actually download and use an image from the internet if you so desire as long as you do not violate copyright laws.
The objects at the left is somewhat unique. They are sound objects in .wav format. To play the sound, double click on the object.
All of the above objects were inserted from existing files that do not exist within the same directory as this MathCAD document. Yet the files are available within this document for viewing. With object insertion, we can also create documents within MathCAD and we can link to existing documents from MathCAD allowing for 'automatic' update. The text below is actually an inserted WordPad document. It outlines issues surrounding object insertion.
This is a Microsoft WordPad Object.

This object is inserted using the Insert > Object menu item. You can insert any file into MathCAD as long as the program used to create the file supports Object Linking and Embedding (OLE).

If you double click on this object, you will open the MS WordPad program. When you do so, notice the change in the toolbars. The MathCAD toolbars are replaced with the toolbars of the object program, thus you have full editing capabilities of that program.

When you insert an object, a dialogue box will appear allowing you to select the type of object to insert. Which programs appear within the dialogue box are dependent upon what software is installed on your computer. In other words, you cannot insert an AutoCAD drawing into MathCAD if you do not have AutoCAD installed on your computer. In a similar vein, assume you have created a MathCAD worksheet with an AutoCAD object inserted, then you email the MathCAD file to a person who does not own AutoCAD. The person receiving the file is able to view the inserted AutoCAD drawing. However, s/he will not be able to edit the drawing. An attempt to do so will result in a 'Server Not Available' error.

When you open the 'Insert > Object' dialogue box, you have the option to create a 'NEW' file or to insert an existing file. These options are rather self-explanatory. If you select 'Create New...', you have an additional option to 'Display as Icon'. When doing so, the program associated to the file you wish to insert will open outside of MathCAD. Under this circumstance, the 'File' menu item of the newly opened program will have slightly modified 'Save' options. One of those options allows you to save a copy of the file to disk. The other two options update the newly created file within MathCAD. When you close the program, the file you just created will be displayed in MathCAD as the Icon normally assiciated with the program. To edit the file, you double click the icon and the associated program is opened outside of MathCAD. Obviously if you send the MathCAD file to another person and the program associated with the inserted file is not installed on his or her computer, that person will not be able to open the file by double clicking the icon. This option MUST be selected upon creation/insertion of the object. You cannot change it later.

If you select 'Create from File...', you also have the option to 'Link' the file you are inserting in addition to the option to 'Display as Icon'. In both cases, you are inserting an existing file which you created outside of MathCAD. If the file is inserted but not linked, the inserted file becomes part of the MathCAD file. If you update the file outside of MathCAD, the version inserted into MathCAD will NOT be updated. However, the MathCAD file remains portable. That is, you can send it to a colleague even if your colleague does not have the program necessary to view or edit that file installed on their computer.

A linked file works in the opposite fashion. If you update the inserted file outside of MathCAD, that file will update within MathCAD the next time you open MathCAD. The downside is if you wish to send your MathCAD file to a colleague, you must also send a copy of the inserted file. This also means your colleague must have the program associated with the file installed on their computer. Thus the option to link becomes a judgement call. In short, your MathCAD file worsheet remains far more portable if you insert the file without linking and by not displaying as an icon, but at the expense of a larger file size

As implied above, you can insert a file from any third party program as long as that program supports OLE. This includes MS Excel documents. However, if you do insert an Excel document as an object, you will not be able to share data between it and MathCAD. If you need to do this, you must insert Excel as a component. The specific topic of inserting an Excel component is discussed in a future lecture. In the meantime, you will have the opportunity to practice object insertion on a number of upcoming homework assignments.
<= This is a WordPad/Word document inserted in MathCAD, linked and displayed as an icon. Double click on the icon to open the document in WordPad or Word (depending upon local file associations).
You can also use the 'Picture' object to insert a graphic into MathCAD. This only works for graphic objects. However, there is a distinct difference between inserting a graphic as a picture and inserting a graphic as an object. In the later case, you can double click on the object to edit the object. In the former case, you no longer have this feature available. However, since the picture object includes a placeholder within which one can place an eqaution, it is actually possible to automatically change the picture though MathCAD's string functions and/or programming functions. These are covered later in the quarter.
The picture to the left is a PICTURE inserted using the 'Insert > Picture' menu. Upon insertion, the object will have a placeholder represented by a solid black square. In this case, the placeholder contains a string defining the filename of the picture. The string is entered by first pressing the double quote key ("), then entering the name of the file you wish to insert. When inserting a graphic in this fashion, the graphic will be updated within MathCAD if you update the graphic outside of MathCAD. If you send this MathCAD file to a friend, you must also send the graphic.
The argument for the picture object can also be a single matrix containing values representing gray scale colors. This is shown below. Starting with matrices 'O', 'N' and 'M', we perform a series of matix operations to generate a rather large matrix, 'U'. Matrices are discussed in week 3, so do not concern yourself with the particulars at this time. Suffice it to say, the resulting matrix, 'U', contains grayscale data that can be displayed as an image as shown.

Alternatively, we can also specify a series of three matrices as aruguments to the picture object. Depending upon how you process the matrices, the matrices will represent Red-Greeen-Blue (RGB), Hue-Saturation-Value (HSV), or Hue-Lightness-Saturation (HLS) color data. This is useful in a number of image processing applications.

We will not be addressing such advanced techniques. Suffice it to say such techniques are useful in many areas of engineering. For example, if one were to use MathCAD to do finite element analysis, one could generate a set of data to display a color image of the element we are studying. The colors may represent temperature within the object, stress within the object or deformation of the object to name but a few.
The final object we will insert is a 'Reference' object. This refers strictly to the insertion of another MathCAD worksheet into the one you are currently developing. This is somewhat analagous to the use of a subroutine in a programming language. Instead of recreating something you've already done, simply insert the existing MathCAD worksheet as a 'Referenced' object. All variables within the referenced object are available for use in the current worksheet. For example, the variables 'a', 'b', and 'd' as shown immediately below are undefined. The referenced MathCAD sheet defines each of these three variables and, as indicated below the reference line, allows variables defined within the referenced worksheet to be available to the current worksheet.
Reference:G:\usr1\m260\insert_objects_ref.mcd(R)
The referenced worksheet contains three defined variables: 'a', 'b' and 'c'. If you double-click on the above reference, the worksheet will open. Notice we can also retreive the value of the variables by simply using them.