/*------------------------------------------------------------------------------* * File Name: ResizeLayer.c * * Creation: ER, 01/17/05 * * Purpose: Programming Example * * Copyright (c) OriginLab Corp.2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 * * All Rights Reserved * * * * Modification Log: * *------------------------------------------------------------------------------*/ #include ///////////////////////////////////////////////////////////////////////////////// // This example shows how to resize the current graph layer. // The size is changed such that the aspect ratio of the layer is 1::1 // NOTE: It is assumed that a graph layer is active. // void resize_layer() { // Declare graph layer and check validity GraphLayer gly = Project.ActiveLayer(); if( !gly ) { out_str("Active layer is not a graph layer!"); return; } // Check current units used for layer dimension int nUnitsType = gly.Dimension.Units.nVal; bool bChangedUnits; Tree trFormat; // If units are not set to inches, change to inches now // and get dimension properties into a tree if( nUnitsType != 1 ) { gly.Dimension.Units.nVal = 1; trFormat = gly.Dimension; bChangedUnits = true; } // Report current dimensions out_str("Current settings for layer dimension:"); out_tree(trFormat); // Now set the width to be same as the height trFormat.Width.dVal = trFormat.Height.dVal; // Apply tree back to make the change gly.Dimension = trFormat; // Report new dimensions out_str("New settings for layer dimension:"); out_tree(trFormat); // Change units back to previous type if needed if( bChangedUnits ) gly.Dimension.Units.nVal = nUnitsType; // Note: The reason we changed the units to inches before // setting width to be same as height is that if units are // in say % of Page size (which is the default), setting width // to be equal to height will not work correctly. // One does not have to switch only to inches. // Other untis like mm will work as well. } /////////////////////////////////////////////////////////////////////////////////