' **************************************************************************** ' * READ ME for setcamera.swp ' * 01/18/2003 version 1.1 ' **************************************************************************** ' * by Stefan Berlitz ' * http://swtools.cad.de ' * http://solidworks.cad.de ' **************************************************************************** ' * This macro is intended to alter the graphic view of SolidWorks by entering ' * coordinates for a virtual camera, look at point, aperture angle and ' * camera orientation. ' **************************************************************************** Impatient right now? Download at http://swtools.cad.de/macros.htm and choose mm_20.zip History ------- Inspired by a excel sheet from Joe Jones (www.nhcad.com) I started to write my own macro for setting a virtual camera for SolidWorks. Joes tool unfortunately never worked for me, so I started to analyze his code and tried to understand the mathematics which is necessary to set the graphic view as expected. As I found some issues in his code I finally had an explanation, why it didn't work. Second, it was a very good example for using the new MathUtility object in the SolidWorks 2001Plus API. So here it is. WARNING -------------------------- First a word of warning: macros may contain malicious code!! The macros I offer at my websites are not intended to do any harm to your systems, I have tested them quiet a long time before I offer them to the public, but I can't guarantee that all works as you aspected. And I don't know where do you get this macro from. SO IT IS ALWAYS A GOOD IDEA TO TAKE A LOOK AT THE CODE OF A MACRO TO VERIFY THAT THERE IS NO MALICIOUS CODE IN THERE!!!! How to work with the macro -------------------------- If you want to take a picture of a real life model you fetch your camera, point it at the model, turn the camera, set up the correct focal length and hit the trigger. So you are twisting and setting up the CAMERA, and the model sits still. In SolidWorks it is the other way round. Imaging you are looking through a little window and you give commands to someone, who turns the model, twist it, rotate it and so on. You can't change the window size, you can't turn your head, you can't even close your eyes :-)) For normal working we become use to the second way, so there is no problem with this. But there are some situations, where it would be nice if we can set up the graphic view the way we take a picture with our camera. Say you want to look at your new design from a special angle, or want to look at a specific point from various locations. The macro takes care of the (quiet complex) mathematics behind this easy-looking task. Let's look how to enter the values the macro needs: First, you can choose the units in the drop down list at the top right. It defaults to the units of the model. Every coordinate you enter will have this unit as a base. In the first row you can enter the X,Y and Z coordinates for the camera position. Imaging you put your camera on a tripod. There a some restriction with the resulting image, so you can't put the camera inside a model, even it is hollow. SolidWorks takes care of this and will change the view, so that your virtual camera will always be outside of the volume. If you have a point or something similar in your model where the camera should be located you can select this point and hit the "GET" button in the first row, the macro will then get the coordinates for that point and write them in the text boxes. In the second line you enter the coordinates of the points, you want to look at. This point will ALWAYS be right in center of the (resulting) view. The camera point and the look at point will make up the line of sight. Like the camera point you can get the coordinates of an existing point or vertex for the look at point by selecting it and hitting the GET button in the second row. The orientation of the camera is set by two coordinates (X and Y). Think of these coordinates as a direction of an virtual flash light at the top of your camera. Now for a standard landscape orientation the flash light shows right upwards, resulting in 0,1 coordinates. If you rotate your camera 90 degrees to the left the flash light would point to the left, the orientation coordinates would be -1,0 As in SolidWorks you have to rotate the model and the camera stands still, the resulting view seem to rotate to the wrong direction, but it is correct. If you rotate your camera to the left, the model would have to turn to the right. Weird, hm? :-))) The last value entered is called "aperture angle" and can be entered directly or by using the slider. This is somewhat experimental, for there is no way to set up the correct distance from camera to the model, when projected to the screen (I could explain, but this would require some heavy maths, so I suggest you look at the code and do the maths by hand, you will see, there is one value missing to determine it exactly). So I decided it's the easiest way to do it with a slider. The values go from 1 to 180, the greater the value, the smaller the resulting model view. If you want to have the graphic feedback on every change (or by sliding) check the option to autoupdate. The macro will open the dialog modeless, so the dialog box will stay open and you can interact with SolidWorks as you used to and can set the camera any time you want. Hint ---- This macro also works with models which are opened view-only. The trick is to run the macro prior to switch to (or open) the view-only model, for the menu entries and the macro toolbar is grayed out when an view-only model is active. Another tip: please only enter values which are numeric, I haven't catched all errors, so don't enter a character or something similar. Oh yes, you have to have a model open and active if you want to start the macro. Feedback -------- If you have any feedback, any suggestions or ideas for other macros you are welcome to drop me a line. Write to stefan.berlitz@swtools.cad.de and be sure to visit my websites. Thanks for reading :-)) Stefan January 2003