Windows and Views
The VB API provides access to Creo Parametric windows and saved views. This section describes the methods that provide this access.
Windows
This section describes the VB API methods that access Window objects. The topics are as follows:
Getting a Window Object
Methods and Property Introduced:
  • IpfcBaseSession.CurrentWindow
  • IpfcBaseSession.CreateModelWindow()
  • IpfcModel.Display()
  • IpfcBaseSession.ListWindows()
  • IpfcBaseSession.GetWindow()
  • IpfcBaseSession.OpenFile()
  • IpfcBaseSession.GetModelWindow()
  • The property IpfcBaseSession.CurrentWindow provides access to the current active window in Creo Parametric.
    The method IpfcBaseSession.CreateModelWindow() creates a new window that contains the model that was passed as an argument.
    Note
    You must call the method IpfcModel.Display() for the model geometry to be displayed in the window.
    Use the method IpfcBaseSession.ListWindows() to get a list of all the current windows in session.
    The method IpfcBaseSession.GetWindow() gets the handle to a window given its integer identifier.
    The method IpfcBaseSession.OpenFile() returns the handle to a newly created window that contains the opened model.
    Note
    If a model is already open in a window the method returns a handle to the window.
    The method IpfcBaseSession.GetModelWindow() returns the handle to the window that contains the opened model, if it is displayed.
    Window Operations
    Methods and Properties Introduced:
  • IpfcWindow.Height
  • IpfcWindow.Width
  • IpfcWindow.XPos
  • IpfcWindow.YPos
  • IpfcWindow.GraphicsAreaHeight
  • IpfcWindow.GraphicsAreaWidth
  • IpfcWindow.Clear()
  • IpfcWindow.Repaint()
  • IpfcWindow.Refresh()
  • IpfcWindow.Close()
  • IpfcWindow.Activate()
  • IpfcWindow.GetId
  • IpfcBaseSession.FlushCurrentWindow()
  • The properties IpfcWindow.Height, IpfcWindow.Width, IpfcWindow.XPos, and IpfcWindow.YPos retrieve the height, width, x-position, and y-position of the window respectively. The values of these parameters are normalized from 0 to 1.
    The properties IpfcWindow.GraphicsAreaHeight and IpfcWindow.GraphicsAreaWidth retrieve the height and width of the Creo Parametric graphics area window without the border respectively. The values of these parameters are normalized from 0 to 1. For both the window and graphics area sizes, if the object occupies the whole screen, the window size returned is 1. For example, if the screen is 1024 pixels wide and the graphics area is 512 pixels, then the width of the graphics area window is returned as 0.5.
    The method IpfcWindow.Clear() removes geometry from the window.
    Both IpfcWindow.Repaint() and IpfcWindow.Refresh() repaint solid geometry. However, the Refresh() method does not remove highlights from the screen and is used primarily to remove temporary geometry entities from the screen.
    Use the method IpfcWindow.Close() to close the window. If the current window is the original window created when Creo Parametric started, this method clears the window. Otherwise, it removes the window from the screen.
    The method IpfcWindow.Activate() activates a window. This function is available only in the asynchronous mode.
    The method IpfcWindow.GetId() retrieves the ID of the Creo Parametric window.
    The method IpfcBaseSession.FlushCurrentWindow() flushes the pending display commands on the current window.
    Note
    It is recommended to call this method only after completing all the display operations. Excessive use of this method will cause major slow down of systems running on Windows Vista and Windows 7.
    Embedded Browser
    Methods Introduced:
  • IpfcWindow.GetURL()
  • IpfcWindow.SetURL()
  • IpfcWindow.GetBrowserSize()
  • IpfcWindow.SetBrowserSize()
  • The methods IpfcWindow.GetURL() and IpfcWindow.SetURL() enables you to find and change the URL displayed in the embedded browser in the Creo Parametric window.
    The methods IpfcWindow.GetBrowserSize() and IpfcWindow.SetBrowserSize() enables you to find and change the size of the embedded browser in the Creo Parametric window.
    Note
    The methods IpfcWindow.GetBrowserSize() and IpfcWindow.SetBrowserSize() are not supported if the browser is open in a separate window.
    Views
    This section describes the VB API methods that access IpfcView objects. The topics are as follows:
    Getting a View Object
    Methods Introduced:
  • IpfcViewOwner.RetrieveView()
  • IpfcViewOwner.GetView()
  • IpfcViewOwner.ListViews()
  • IpfcViewOwner.GetCurrentView()
  • Any solid model inherits from the interface IpfcViewOwner. This will enable you to use these methods on any solid object.
    The method IpfcViewOwner.RetrieveView() sets the current view to the orientation previously saved with a specified name.
    Use the method IpfcViewOwner.GetView() to get a handle to a named view without making any modifications.
    The method IpfcViewOwner.ListViews() returns a list of all the views previously saved in the model.
    From Creo Parametric 2.0 M120 onward, the method, IpfcViewOwner.GetCurrentView() has been deprecated. The method returns a view handle that represents the current orientation. Although this view does not have a name, you can use this view to find or modify the current orientation.
    View Operations
    Methods and Properties Introduced:
  • IpfcView.Name
  • IpfcView.IsCurrent
  • IpfcView.Reset()
  • IpfcViewOwner.SaveView()
  • To get the name of a view given its identifier, use the property IpfcView.Name.
    The property IpfcView.IsCurrent determines if the View object represents the current view.
    The method IpfcView.Reset() restores the current view to the default view.
    To store the current view under the specified name, call the method IpfcViewOwner.SaveView().
    Coordinate Systems and Transformations
    his section describes the various coordinate systems used by Creo Parametric and accessible from the VB API and how to transform from one coordinate system to another.
    Coordinate Systems
    Creo Parametric and the VB API use the following coordinate systems:
    The following sections describe each of these coordinate systems.
    Solid Coordinate System
    The solid coordinate system is the three-dimensional, Cartesian coordinate system used to describe the geometry of a Creo Parametric solid model. In a part, the solid coordinate system describes the geometry of the surfaces and edges. In an assembly, the solid coordinate system also describes the locations and orientations of the assembly members.
    You can visualize the solid coordinate system in Creo Parametric by creating a coordinate system datum with the option Default. Distances measured in solid coordinates correspond to the values of dimensions as seen by the Creo Parametric user.
    Solid coordinates are used by the VB API for all the methods that look at geometry and most of the methods that draw three-dimensional graphics.
    Screen Coordinate System
    The screen coordinate system is two-dimensional coordinate system that describes locations in a Creo Parametric window. This is an intermediate coordinate system after which the screen points are transformed to screen pixels. All the models are first mapped to the screen coordinate system. When the user zooms or pans the view, the screen coordinate system follows the display of the solid, so a particular point on the solid always maps to the same screen coordinate. The mapping changes only when the view orientation is changed.
    Screen coordinates are used by some of the graphics methods, the mouse input methods, and all methods that draw graphics or manipulate items on a drawing.
    Window Coordinate System
    The window coordinate system is similar to the screen coordinate system. After mapping the models to the screen coordinate system, they are mapped to the window coordinate before being drawn to screen pixels based on screen resolution. When pan or zoom values are applied to the coordinates in the screen coordinate system, they result in window coordinates. When an object is first displayed in a window, or the option View  Refit is used, the screen and window coordinates are the same.
    Window coordinates are needed only if you need to take account of zoom and pan—for example, to find out whether a point on the solid is visible in the window, or to draw two-dimensional text in a particular window location, regardless of pan and zoom.
    Drawing Coordinate System
    The drawing coordinate system is a two-dimensional system that describes the location on a drawing relative to the bottom, left corner, and measured in drawing units. For example, on a U.S. letter-sized, landscape-format drawing sheet that uses inches, the top, right-corner is (11, 8.5) in drawing coordinates.
    The VB API methods and properties that manipulate drawings generally use screen coordinates.
    Drawing View Coordinate System
    The drawing view coordinate system is used to describe the locations of entities in a drawing view.
    Assembly Coordinate System
    An assembly has its own coordinate system that describes the positions and orientations of the member parts, subassemblies, and the geometry of datum features created in the assembly.
    When an assembly is retrieved into memory each member is also loaded and continues to use its own solid coordinate system to describe its geometry.
    This is important when you are analyzing the geometry of a subassembly and want to extract or display the results relative to the coordinate system of the parent assembly.
    Datum Coordinate System
    A coordinate system datum can be created anywhere in any part or assembly, and represents a user-defined coordinate system. It is often a requirement in a VB API application to describe geometry relative to such a datum.
    Section Coordinate System
    Every sketch has a coordinate system used to locate entities in that sketch. Sketches used in features will use a coordinate system different from that of the solid model.
    Transformations
    Methods and Properties Introduced:
  • IpfcTransform3D.Invert()
  • IpfcTransform3D.TransformPoint()
  • IpfcTransform3D.TransformVector()
  • IpfcTransform3D.Matrix
  • IpfcTransform3D.GetOrigin()
  • IpfcTransform3D.GetXAxis()
  • IpfcTransform3D.GetYAxis
  • IpfcTransform3D.GetZAxis()
  • CMpfcBase.MakeMatrixOrthonormal()
  • All coordinate systems are treated in the VB API as if they were three-dimensional. Therefore, a point in any of the coordinate systems is always represented by the IpfcPoint3D class:
    Vectors store the same data but are represented for clarity by the IpfcVector3D class.
    Screen coordinates contain a z-value whose positive direction is outwards from the screen. The value of z is not generally important when specifying a screen location as an input to a method, but it is useful in other situations. For example, if you select a datum plane, you can find the direction of the plane by calculating the normal to the plane, transforming to screen coordinates, then looking at the sign of the z-coordinate.
    A transformation between two coordinate systems is represented by the IpfcTransform3D class. This class contains a 4x4 matrix that combines the conventional 3x3 matrix that describes the relative orientation of the two systems, and the vector that describes the shift between them.
    The 4x4 matrix used for transformations is as follows:
    Image
    The utility method IpfcTransform3D.Invert() inverts a transformation matrix so that it can be used to transform points in the opposite direction.
    the VB API provides two utilities for performing coordinate transformations. The method IpfcTransform3D.TransformPoint() transforms a three-dimensional point and IpfcTransform3D.TransformVector() transforms a three-dimensional vector.
    The following diagram summarizes the coordinate transformations needed when using the VB API and specifies the the VB API methods that provide the transformation matrix.
    Image
    The method CMpfcBase.MakeMatrixOrthonormal() converts a non-orthonormal matrix to an orthonormal matrix with the specified scaling factor. The input arguments follow:
    •  Matrix—The matrix to be converted to orthonormal.
    •  Scale—Scale factor to be applied on the matrix.
    Transforming to Screen Coordinates
    Methods and Properties Introduced:
  • IpfcView.Transform
  • IpfcView.Rotate()
  • IpfcViewOwner.GetCurrentViewTransform()
  • IpfcViewOwner.SetCurrentViewTransform()
  • IpfcViewOwner.CurrentViewRotate()
  • IpfcTransform3D.Invert()
  • The view matrix describes the transformation from solid to screen coordinates. The property IpfcView.Transform provides the view matrix for a model in the view.
    To get and set the transformation matrix for a model in the current view, use the methods IpfcViewOwner.GetCurrentViewTransform() and IpfcViewOwner.SetCurrentViewTransform().
    The method IpfcView.Rotate() rotates an object, relative to the X, Y, or Z axis for the specified rotation angle.
    To rotate an object in the current view, use the method IpfcViewOwner.CurrentViewRotate().
    To transform from screen to solid coordinates, invert the transformation matrix using the method IpfcTransform3D.Invert().
    Transforming to Coordinate System Datum Coordinates
    Property Introduced:
  • IpfcCoordSystem.CoordSys
  • The property IpfcCoordSystem.CoordSys provides the location and orientation of the coordinate system datum in the coordinate system of the solid that contains it. The location is in terms of the directions of the three axes and the position of the origin.
    Transforming Window Coordinates
    Properties Introduced
  • IpfcWindow.ScreenTransform
  • IpfcScreenTransform.PanX
  • IpfcScreenTransform.PanY
  • IpfcScreenTransform.Zoom
  • You can alter the pan and zoom of a window by using a Screen Transform object. This object contains three attributes. PanX and PanY represent the horizontal and vertical movement. Every increment of 1.0 moves the view point one screen width or height. Zoom represents a scaling factor for the view. This number must be greater than zero.
    Transforming Coordinates of an Assembly Member
    Method Introduced:
  • IpfcComponentPath.GetTransform()
  • The method IpfcComponentPath.GetTransform() provides the matrix for transforming from the solid coordinate system of the assembly member to the solid coordinates of the parent assembly, or the reverse.
    Example Code - Normalizing a Coordinate Transformation Matrix
    The sample code in the file pfcViewExamples.vb located at <creo_vbapi_loadpoint>/vbapi_examples uses two methods to transfer the view transformation from one view to another..