Exemplo n.º 1
0
        public static void InitializeSapModel(ref SapObject mySAPObject, ref cSapModel mySapModel, string units)
        {
            long ret = 0;

            //TO DO: Grab open Instance if already open!!!

            //Create SAP2000 Object
            mySAPObject = new SAP2000v20.SapObject();

            // get enum from Units
            eUnits Units = (eUnits)Enum.Parse(typeof(eUnits), units);

            //Start Application
            mySAPObject.ApplicationStart(Units, true);

            //Create SapModel object
            mySapModel = mySAPObject.SapModel;

            //initialize the model
            ret = mySapModel.InitializeNewModel(Units);

            //create new blank model
            ret = mySapModel.File.NewBlank();

            //SET UP ... SET UP ... SET UP ... SET UP
            DefineMaterials(ref mySapModel);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initialization Method - reads all constants from Configuration file
        /// </summary>
        /// <param name="units">Desired units to work in [default is Points]</param>
        /// <param name="xMaxBorder">X Max Limit for Ricochet Calculations</param>
        /// <param name="yMaxBorder">Y Max Limit for Ricochet Calculations</param>
        /// <param name="ricochetFactor">Ricochet Factor to use in calculations</param>
        public void InitializeRicochetCalc(eUnits units = eUnits.Pts, double xMaxBorder = -1, double yMaxBorder = -1, double ricochetFactor = -1)
        {
            if (!IsInitialized)
            {
                _xMinBorder    = 0;
                _yMinBorder    = 0;
                _ricocheFactor = (ricochetFactor > 0) ? ricochetFactor
                            : Configuration.Attributes.GetValue <double>(Configuration.Names.KEY_RICOCHET_FACTOR);
                switch (units)
                {
                case eUnits.Mm:
                    _xMaxBorder = (xMaxBorder > 0) ? xMaxBorder
                            : Configuration.Attributes.GetValue <double>(Configuration.Names.TABLE_WIDTH);
                    _yMaxBorder = (yMaxBorder > 0) ? yMaxBorder
                            : Configuration.Attributes.GetValue <double>(Configuration.Names.TABLE_HEIGHT);
                    break;

                case eUnits.Pts:
                    _xMaxBorder = (xMaxBorder > 0) ? xMaxBorder
                            : Configuration.Attributes.GetValue <double>(Configuration.Names.FOOSBOT_AXE_X_SIZE);
                    _yMaxBorder = (yMaxBorder > 0) ? yMaxBorder
                            : Configuration.Attributes.GetValue <double>(Configuration.Names.FOOSBOT_AXE_Y_SIZE);
                    break;

                default:
                    throw new NotSupportedException(String.Format(
                                                        "[{0}] Units [{1}] are not supported by RicochetCalc.",
                                                        MethodBase.GetCurrentMethod().Name, units.ToString()));
                }
                IsInitialized = true;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// This function starts the application.
        /// When the model is not visible it does not appear on screen and it does not appear in the Windows task bar.
        /// If no filename is specified, you can later open a model or create a model through the API.
        /// The file name must have an .sdb, .$2k, .s2k, .xls, or .mdb extension.
        /// Files with .sdb extensions are opened as standard SAP2000 files.
        /// Files with .$2k and .s2k extensions are imported as text files.
        /// Files with .xls extensions are imported as Microsoft Excel files.
        /// Files with .mdb extensions are imported as Microsoft Access files.
        /// </summary>
        /// <param name="units">The database units used when a new model is created.
        /// Data is internally stored in the program in the database units.</param>
        /// <param name="visible">True: The application is visible when started.
        /// False: The application is hidden when started.</param>
        /// <param name="modelPath">The full path of a model file to be opened when the application is started.
        /// If no file name is specified, the application starts without loading an existing model.</param>
        /// <exception cref="CSiException">API_DEFAULT_ERROR_CODE</exception>
        private void applicationStart(eUnits units     = eUnits.kip_in_F,
                                      bool visible     = true,
                                      string modelPath = "")
        {
#if BUILD_ETABS2015 || BUILD_ETABS2016 || BUILD_ETABS2017
            _callCode = _sapObject.ApplicationStart();
            if (_seed == null)
            {
                return;
            }

            Model.InitializeNewModel(units);
            if (!string.IsNullOrWhiteSpace(modelPath))
            {
                Model.File.Open(modelPath);
            }
            if (!visible)
            {
                Hide();
            }
#else
            _callCode = _sapObject.ApplicationStart(EnumLibrary.Convert <eUnits, CSiProgram.eUnits>(units), visible, modelPath);
#endif
            if (throwCurrentApiException(_callCode))
            {
                throw new CSiException(API_DEFAULT_ERROR_CODE);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Performs the application-specific steps of initializing the default installed program.
        /// This initializes SapObject and SapModel.
        /// </summary>
        /// <param name="units">The database units used when a new model is created.
        /// Data is internally stored in the program in the database units.</param>
        /// <param name="visible">True: The application is visible when started.
        /// False: The application is hidden when started.</param>
        /// <param name="modelPath">The full path of a model file to be opened when the application is started.
        /// If no file name is specified, the application starts without loading an existing model.</param>
        /// <returns><c>true</c> if program is successfully initialized, <c>false</c> otherwise.</returns>
        private bool initializeProgramFromLatestInstallation(eUnits units     = eUnits.kip_in_F,
                                                             bool visible     = true,
                                                             string modelPath = "")
        {
            try
            {
                Helper helper = Helper.Initialize();
                _sapObject = helper.CreateObjectProgId(TYPE_NAME);

                // start Sap2000 application
                applicationStart(units, visible, modelPath);

                // create SapModel object
                _sapModel = _sapObject.SapModel;
                _seed     = new CSiApiSeed(_sapObject, _sapModel);

#if BUILD_ETABS2015 || BUILD_ETABS2016 || BUILD_ETABS2017
                delayedETABSInitialization(units, visible, modelPath);
#endif

                // TODO: Assign path of installation to Path property.

                return(IsInitialized);
            }
            catch (Exception ex)
            {
                resetObject();
                throw new CSiException("Cannot start a new instance of the program.", ex);
                // TODO: Replace the exception with a logger.
                //return false;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Defines if given coordinates in table range.
        /// </summary>
        /// <param name="xCoordinate">X cooridanate to compare</param>
        /// <param name="units">Units to work in (mm/pts only) [default is mm]</param>
        /// <returns>[True] if in range, [False] otherwise</returns>
        public bool IsCoordinatesXInRange(int xCoordinate, eUnits units = eUnits.Mm)
        {
            VerifyUnitsSupported(units);
            int max = (units == eUnits.Mm) ? XMaxMm : XMaxPts;

            return(xCoordinate >= 0 && xCoordinate <= max);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Defines if given coordinates in table range.
        /// </summary>
        /// <param name="yCoordinate">Y cooridanate to compare</param>
        /// <param name="units">Units to work in (mm/pts only) [default is mm]</param>
        /// <returns>[True] if in range, [False] otherwise</returns>
        public bool IsCoordinatesYInRange(int yCoordinate, eUnits units = eUnits.Mm)
        {
            VerifyUnitsSupported(units);
            int max = (units == eUnits.Mm) ? YMaxMm : YMaxPts;

            return(yCoordinate >= 0 && yCoordinate <= max);
        }
Exemplo n.º 7
0
        /// <summary>
        /// This function starts the program.
        /// When the model is not visible it does not appear on screen and it does not appear in the Windows task bar.
        /// If no filename is specified, you can later open a model or create a model through the API.
        /// The file name must have an .sdb, .$2k, .s2k, .xls, or .mdb extension.
        /// Files with .sdb extensions are opened as standard SAP2000 files.
        /// Files with .$2k and .s2k extensions are imported as text files.
        /// Files with .xls extensions are imported as Microsoft Excel files.
        /// Files with .mdb extensions are imported as Microsoft Access files.
        /// </summary>
        /// <param name="applicationPath">The application path. If not specified, then the default installed application will be used.</param>
        /// <param name="units">The database units used when a new model is created.
        /// Data is internally stored in the program in the database units.</param>
        /// <param name="visible">True: The application is visible when started.
        /// False: The application is hidden when started.</param>
        /// <param name="modelPath">The full path of a model file to be opened when the application is started.
        /// If no file name is specified, the application starts without loading an existing model.</param>
        /// <returns><c>true</c> if the program is successfully initialied, <c>false</c> otherwise.</returns>
        /// <exception cref="IO.IOException">The following CSi program path is invalid: " + Path</exception>
        private bool initializeProgram(string applicationPath = "",
                                       eUnits units           = eUnits.kip_in_F,
                                       bool visible           = true,
                                       string modelPath       = "")
        {
            if (string.IsNullOrWhiteSpace(applicationPath))
            {
#if BUILD_ETABS2013
                // TODO: Consider ETABS2013 deprecation
#elif BUILD_SAP2000v16
                // TODO: Consider SAP2000v16 deprecation
                // No action needed, allow method to continute to next option.
#else
#endif
#if !BUILD_SAP2000v18 && !BUILD_SAP2000v17 && !BUILD_SAP2000v16 && !BUILD_CSiBridgev18 && !BUILD_CSiBridgev17 && !BUILD_CSiBridgev16 && !BUILD_ETABS2015
                return(initializeProgramFromLatestInstallation(units, visible, modelPath));
#else
                return(false);
#endif
            }

            if (!IO.File.Exists(applicationPath))
            {
                throw new IO.IOException("The following CSi program path is invalid: " + applicationPath);
            }
            return(initializeProgramSpecific(applicationPath, units, visible, modelPath));
        }
Exemplo n.º 8
0
 /// <summary>
 /// Ricochet Calculator Constructor
 /// </summary>
 /// <param name="doInit">Perform initialization flag [default is false]</param>
 /// <param name="units">Desired units to work in [default is Points]</param>
 public RicochetCalc(bool doInit = false, eUnits units = eUnits.Pts)
 {
     IsInitialized = false;
     if (doInit)
     {
         InitializeRicochetCalc(units);
     }
 }
Exemplo n.º 9
0
 /// <summary>
 /// Sets the units presently specified for the model.
 /// </summary>
 /// <param name="units">The units.</param>
 /// <exception cref="CSiException"></exception>
 /// <exception cref="MPT.CSI.API.Core.Support.CSiException"></exception>
 public void SetPresentUnits(eUnits units)
 {
     _callCode = _sapModel.SetPresentUnits(EnumLibrary.Convert <eUnits, CSiProgram.eUnits>(units));
     if (throwCurrentApiException(_callCode))
     {
         throw new CSiException();
     }
 }
Exemplo n.º 10
0
 /// <summary>
 /// Ricochet Calculator Constructor
 /// </summary>
 /// <param name="doInit">Perform initialization flag [default is false]</param>
 /// <param name="units">Desired units to work in [default is Points]</param>
 public RicochetCalc(bool doInit = false, eUnits units = eUnits.Pts)
 {
     IsInitialized = false;
     if (doInit)
     {
         InitializeRicochetCalc(units);
     }
 }
Exemplo n.º 11
0
 /// <summary>
 /// This function starts the application.
 /// When the model is not visible it does not appear on screen and it does not appear in the Windows task bar.
 /// If no filename is specified, you can later open a model or create a model through the API.
 /// The file name must have an .sdb, .$2k, .s2k, .xls, or .mdb extension.
 /// Files with .sdb extensions are opened as standard SAP2000 files.
 /// Files with .$2k and .s2k extensions are imported as text files.
 /// Files with .xls extensions are imported as Microsoft Excel files.
 /// Files with .mdb extensions are imported as Microsoft Access files.
 /// </summary>
 /// <param name="units">The database units used when a new model is created.
 /// Data is internally stored in the program in the database units.</param>
 /// <param name="visible">True: The application is visible when started.
 /// False: The application is hidden when started.</param>
 /// <param name="filePath">The full path of a model file to be opened when the application is started.
 /// If no file name is specified, the application starts without loading an existing model.</param>
 /// <exception cref="CSiException"></exception>
 public void ApplicationStart(eUnits units    = eUnits.kip_in_F,
                              bool visible    = true,
                              string filePath = "")
 {
     _callCode = _sapObject.ApplicationStart(EnumLibrary.Convert <eUnits, CSiProgram.eUnits>(units), visible, filePath);
     if (throwCurrentApiException(_callCode))
     {
         throw new CSiException();
     }
 }
Exemplo n.º 12
0
        //Initialize Model
        public int InitializeUnits(eUnits units = eUnits.N_mm_C)
        {
            int ret;

            //Initialize Model
            MySapObjectModel.InitializeNewModel((eUnits)units);
            //Create New Blank Model
            ret = MySapObjectModel.File.NewBlank();
            return(ret);
        }
Exemplo n.º 13
0
 /// <summary>
 /// This function clears the previous model and initializes the program for a new model.
 /// If it is later needed, you should save your previous model prior to calling this function.
 /// After calling the InitializeNewModel function, it is not necessary to also call the ApplicationStart function because the functionality of the ApplicationStart function is included in the InitializeNewModel function.
 /// </summary>
 /// <param name="units">The database units for the new model.
 /// All data is internally stored in the model in these units.</param>
 /// <returns><c>true</c> if a nuew model is successfully initialized, <c>false</c> otherwise.</returns>
 public bool InitializeNewModel(eUnits units = eUnits.kip_in_F)
 {
     _callCode = _sapModel.InitializeNewModel(EnumLibrary.Convert <eUnits, CSiProgram.eUnits>(units));
     if (!apiCallIsSuccessful(_callCode))
     {
         return(false);
     }
     _file = new CSiFile(_seed);
     return(true);
 }
Exemplo n.º 14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CSiApplication"/> class using the default installed application.
        /// When the model is not visible it does not appear on screen and it does not appear in the Windows task bar.
        /// If no filename is specified, you can later open a model or create a model through the API.
        /// The file name must have an .sdb, .$2k, .s2k, .xls, or .mdb extension.
        /// Files with .sdb extensions are opened as standard SAP2000 files.
        /// Files with .$2k and .s2k extensions are imported as text files.
        /// Files with .xls extensions are imported as Microsoft Excel files.
        /// Files with .mdb extensions are imported as Microsoft Access files.
        /// </summary>
        /// <param name="units">The database units used when a new model is created.
        /// Data is internally stored in the program in the database units.</param>
        /// <param name="visible">True: The application is visible when started.
        /// False: The application is hidden when started.</param>
        /// <param name="modelPath">The full path of a model file to be opened when the application is started.
        /// If no file name is specified, the application starts without loading an existing model.</param>
        /// <param name="numberOfExitAttempts">The number of exit attempts before the library stops attempting to exit the application.</param>
        /// <param name="intervalBetweenExitAttempts">The interval between exit attempts of the application.</param>
        public CSiApplication(eUnits units                    = eUnits.kip_in_F,
                              bool visible                    = true,
                              string modelPath                = "",
                              int numberOfExitAttempts        = 1,
                              int intervalBetweenExitAttempts = 0)
        {
            _numberOfExitAttempts        = numberOfExitAttempts;
            _intervalBetweenExitAttempts = intervalBetweenExitAttempts;

            initializeProgram("", units, visible, modelPath);
        }
        public void CSiApplication_Application_Start_with_Custom_Units()
        {
            bool   programWasOpened;
            eUnits units = eUnits.kgf_mm_C;

            using (CSiApplication app = new CSiApplication(CSiData.pathApp, units: units))
            {
                Assert.That(app.IsInitialized);
                programWasOpened = app.IsInitialized;
                Assert.AreEqual(units, app.Model.GetPresentUnits());
            }
            Assert.IsTrue(programWasOpened);
        }
Exemplo n.º 16
0
 /// <summary>
 /// Performs the rest of the applicationStart method for ETABS once the seed object has been created.
 /// </summary>
 /// <param name="units"></param>
 /// <param name="visible"></param>
 /// <param name="modelPath"></param>
 private void delayedETABSInitialization(eUnits units     = eUnits.kip_in_F,
                                         bool visible     = true,
                                         string modelPath = "")
 {
     Model.InitializeNewModel(units);
     if (!string.IsNullOrWhiteSpace(modelPath))
     {
         Model.File.Open(modelPath);
     }
     if (!visible)
     {
         Hide();
     }
 }
Exemplo n.º 17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CSiApplication" /> class using the default installed application.
 /// When the model is not visible it does not appear on screen and it does not appear in the Windows task bar.
 /// If no filename is specified, you can later open a model or create a model through the API.
 /// The file name must have an .sdb, .$2k, .s2k, .xls, or .mdb extension.
 /// Files with .sdb extensions are opened as standard SAP2000 files.
 /// Files with .$2k and .s2k extensions are imported as text files.
 /// Files with .xls extensions are imported as Microsoft Excel files.
 /// Files with .mdb extensions are imported as Microsoft Access files.
 /// </summary>
 /// <param name="units">The database units used when a new model is created.
 /// Data is internally stored in the program in the database units.</param>
 /// <param name="visible">True: The application is visible when started.
 /// False: The application is hidden when started.</param>
 /// <param name="modelPath">The full path of a model file to be opened when the application is started.
 /// If no file name is specified, the application starts without loading an existing model.</param>
 /// <param name="numberOfExitAttempts">The number of exit attempts before the library stops attempting to exit the application.</param>
 /// <param name="intervalBetweenExitAttempts">The interval between exit attempts of the application.</param>
 protected CSiApplication(eUnits units                    = eUnits.kip_in_F,
                          bool visible                    = true,
                          string modelPath                = "",
                          int numberOfExitAttempts        = 1,
                          int intervalBetweenExitAttempts = 0)
 {
     _apiApp = new ApiCSiApplication(units,
                                     visible,
                                     modelPath,
                                     numberOfExitAttempts,
                                     intervalBetweenExitAttempts);
     NumberOfExitAttempts        = numberOfExitAttempts;
     IntervalBetweenExitAttempts = intervalBetweenExitAttempts;
 }
Exemplo n.º 18
0
        /// <summary>
        /// Verify if units are supported by surveyor
        /// </summary>
        /// <param name="units">Units type</param>
        /// <exception cref="NotSupportedException">Thrown in case units not supported</exception>
        private void VerifyUnitsSupported(eUnits units)
        {
            switch (units)
            {
            case eUnits.Mm:
            case eUnits.Pts:
                return;

            default:
                throw new NotSupportedException(String.Format(
                                                    "[{0}] Units of type {1} are not supported by {2} class",
                                                    MethodBase.GetCurrentMethod().Name, units.ToString(), GetType().Name));
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// Performs the application-specific steps of initializing the program at the provided file path.
        /// This initializes SapObject and SapModel.
        /// </summary>
        /// <param name="applicationPath">Path to the CSi application that the class manipulates.
        /// Make sure this is a valid path before using this method.</param>
        /// <param name="units">The database units used when a new model is created.
        /// Data is internally stored in the program in the database units.</param>
        /// <param name="visible">True: The application is visible when started.
        /// False: The application is hidden when started.</param>
        /// <param name="modelPath">The full path of a model file to be opened when the application is started.
        /// If no file name is specified, the application starts without loading an existing model.</param>
        /// <returns><c>true</c> if program is successfully initialized, <c>false</c> otherwise.</returns>
        private bool initializeProgramSpecific(string applicationPath,
                                               eUnits units     = eUnits.kip_in_F,
                                               bool visible     = true,
                                               string modelPath = "")
        {
            try
            {
#if BUILD_ETABS2013
                //  Create program object
                Assembly myAssembly = Assembly.LoadFrom(applicationPath);

                //  Create an instance of ETABSObject and get a reference to cOAPI interface
                _sapObject = DirectCast(myAssembly.CreateInstance(TYPE_NAME), cOAPI);
#elif BUILD_SAP2000v16
                // NOTE: No path is needed for SAP2000v16. Instead, the tested program will automatically use the
                //    version currently installed. To change the version, say for testing, run the desired v16 version as
                //    administrator first in order to register.
                _sapObject = new SAP2000v16.SapObject;
#else
                // Old Method: 32bit OAPI clients can only call 32bit ETABS 2014 and 64bit OAPI clients can only call 64bit ETABS 2014
                // Create program object
                // _SapObject = DirectCast(myAssembly.CreateInstance("CSI.SAP2000.API.SapObject"), cOAPI)

                // New Method: 32bit & 64bit API clients can call 32 & 64bit program versions
                // Use the OAPI helper class to get a reference to cOAPI interface
                Helper helper = Helper.Initialize();
                _sapObject = helper.CreateObject(applicationPath);
#endif
                // start Sap2000 application
                applicationStart(units, visible, modelPath);

                // create SapModel object
                _sapModel = _sapObject.SapModel;
                _seed     = new CSiApiSeed(_sapObject, _sapModel);

#if BUILD_ETABS2015 || BUILD_ETABS2016 || BUILD_ETABS2017
                delayedETABSInitialization(units, visible, modelPath);
#endif

                Path = applicationPath;
                return(IsInitialized);
            }
            catch (Exception ex)
            {
                resetObject();
                throw new CSiException("Cannot start a new instance of the program from " + applicationPath, ex);
                // TODO: Replace the exception with a logger.
                //return false;
            }
        }
Exemplo n.º 20
0
        public static bool NewModel(eUnits units = eUnits.Ton_m_C)
        {
            mySapModel = mySapObject.SapModel;
            int flag = default(int);

            flag = mySapModel.InitializeNewModel(units);
            flag = mySapModel.File.NewBlank();
            if (flag != 0)
            {
                return(false);
            }
            //SetDefaultMaterials();
            return(true);
        }
Exemplo n.º 21
0
 public static bool StartApplication(bool attachToInstance, bool isVisible, eUnits units = eUnits.Ton_m_C)
 {
     if (attachToInstance == false)
     {
         try
         {
             cHelper myHelper = new Helper();
             mySapObject = myHelper.CreateObject(ProgramPath);
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
     else
     {
         try
         {
             mySapObject = (cOAPI)System.Runtime.InteropServices.Marshal.GetActiveObject("CSI.SAP2000.API.SapObject");
         }
         catch
         {
             try
             {
                 if (mySapObject == null)
                 {
                     cHelper myHelper = new Helper();
                     mySapObject = myHelper.CreateObject(ProgramPath);
                 }
             }
             catch (Exception ex)
             {
                 throw ex;
             }
         }
     }
     if (isVisible == true)
     {
         mySapObject.Visible();
     }
     else
     {
         mySapObject.Hide();
     }
     mySapObject.ApplicationStart(units);
     mySapModel = mySapObject.SapModel;
     return(true);
 }
Exemplo n.º 22
0
 public FNC(ushort maxBitWidth, ushort maxBitHeight, int rasterByteCount) : base(Lookups.StructuredFieldID <FNC>(), 0, 0, null)
 {
     Data              = new byte[28];
     PatternTech       = ePatternTech.LaserMatrixNBitWide;
     XUnitBase         = eUnitBase.RelativeMetrics;
     YUnitBase         = eUnitBase.RelativeMetrics;
     XUnits            = eUnits.OneThousandUnitsPerEm;
     YUnits            = eUnits.OneThousandUnitsPerEm;
     MaxBoxWidthIndex  = maxBitWidth;
     MaxBoxHeightIndex = maxBitHeight;
     FNORGLength       = 26; // Constant
     FNIRGLength       = 28; // Constant for raster
     PatternAlignment  = ePatternAlignment.OneByte;
     RasterDataCount   = rasterByteCount;
     FNPRGLength       = 22; // Constant
     FNMRGLength       = 8;  // Constant for raster
     XShapeResolution  = eUnits.ThreeHundredPPI;
     YShapeResolution  = eUnits.ThreeHundredPPI;
 }
Exemplo n.º 23
0
        public static void GrabOpenSAP(ref cSapModel mySapModel, ref string ModelUnits, string DynInputUnits = "kip_ft_F")
        {
            //dimension the SapObject as cOAPI type
            cOAPI mySapObject = null;

            //Use ret to check if functions return successfully (ret = 0) or fail (ret = nonzero)
            var ret = 0;

            //attach to a running instance of SAP2000
            try
            {
                //get the active SapObject

                //try the code form the example
                //mySapObject =(cOAPI) Marshal.GetActiveObject("CSI.SAP2000.API.SapObject");
                //get the active SapObject
                mySapObject = (cOAPI)System.Runtime.InteropServices.Marshal.GetActiveObject("CSI.SAP2000.API.SapObject");
            }
            catch (Exception ex)
            {
                Console.WriteLine("No running instance of the program found or failed to attach.");
                return;
            }

            //Create SapModel object
            mySapModel = mySapObject.SapModel;
            // get enum from Units & Set to model
            if (!String.IsNullOrEmpty(DynInputUnits))
            {
                eUnits Units = (eUnits)Enum.Parse(typeof(eUnits), DynInputUnits);
                try
                {
                    ret = mySapModel.SetPresentUnits(Units);
                }
                catch (Exception ex)
                {
                    string message = ex.Message;
                }
            }
            ModelUnits = mySapModel.GetPresentUnits().ToString();
        }
Exemplo n.º 24
0
        public static void GrabOpenSAP(ref cSapModel mySapModel, ref string ModelUnits, string DynInputUnits = "kip_ft_F")
        {
            Process[] SapInstances = Process.GetProcessesByName("SAP2000");

            //http://docs.csiamerica.com/help-files/sap2000-oapi/SAP2000_API_Fuctions/General_Functions/SetAsActiveObject.htm
            if (SapInstances.LongLength >= 1)
            {
                SapObject Obj;
                object    getObj = ROTHelper.GetActiveObject("SAP2000v20.SapObject");
                if (getObj == null)
                {
                    Obj    = new SapObject();
                    getObj = ROTHelper.GetActiveObject("SAP2000v20.SapObject");
                }
                if (getObj != null)
                {
                    Obj        = (SapObject)getObj;
                    mySapModel = Obj.SapModel;
                    // get enum from Units & Set to model
                    if (!String.IsNullOrEmpty(DynInputUnits))
                    {
                        eUnits Units = (eUnits)Enum.Parse(typeof(eUnits), DynInputUnits);
                        try
                        {
                            int ret = mySapModel.SetPresentUnits(Units);
                        }
                        catch (Exception ex) {
                            string message = ex.Message;
                        }
                    }
                    ModelUnits = mySapModel.GetPresentUnits().ToString();
                }

                //SET UP ... SET UP ... SET UP ... SET UP
                try
                {
                    DefineMaterials(ref mySapModel);
                }
                catch { }
            }
        }
Exemplo n.º 25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CSiApplication" /> class using the default installed application.
 /// When the model is not visible it does not appear on screen and it does not appear in the Windows task bar.
 /// If no filename is specified, you can later open a model or create a model through the API.
 /// The file name must have an .sdb, .$2k, .s2k, .xls, or .mdb extension.
 /// Files with .sdb extensions are opened as standard SAP2000 files.
 /// Files with .$2k and .s2k extensions are imported as text files.
 /// Files with .xls extensions are imported as Microsoft Excel files.
 /// Files with .mdb extensions are imported as Microsoft Access files.
 /// </summary>
 /// <param name="units">The database units used when a new model is created.
 /// Data is internally stored in the program in the database units.</param>
 /// <param name="visible">True: The application is visible when started.
 /// False: The application is hidden when started.</param>
 /// <param name="modelPath">The full path of a model file to be opened when the application is started.
 /// If no file name is specified, the application starts without loading an existing model.</param>
 /// <param name="numberOfExitAttempts">The number of exit attempts before the library stops attempting to exit the application.</param>
 /// <param name="intervalBetweenExitAttempts">The interval between exit attempts of the application.</param>
 /// <returns>CSiApplication.</returns>
 public static CSiApplication Factory(eUnits units                    = eUnits.kip_in_F,
                                      bool visible                    = true,
                                      string modelPath                = "",
                                      int numberOfExitAttempts        = 1,
                                      int intervalBetweenExitAttempts = 0)
 {
     try
     {
         CSiApplication app = new CSiApplication(units,
                                                 visible,
                                                 modelPath,
                                                 numberOfExitAttempts,
                                                 intervalBetweenExitAttempts);
         return(app);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         return(null);
     }
 }
Exemplo n.º 26
0
 /// <summary>
 /// Verify if units are supported by surveyor
 /// </summary>
 /// <param name="units">Units type</param>
 /// <exception cref="NotSupportedException">Thrown in case units not supported</exception>
 private void VerifyUnitsSupported(eUnits units)
 {
     switch(units)
     {
         case eUnits.Mm:
         case eUnits.Pts:
             return;
         default:
             throw new NotSupportedException(String.Format(
                 "[{0}] Units of type {1} are not supported by {2} class",
                     MethodBase.GetCurrentMethod().Name, units.ToString(), GetType().Name));
     }
 }
Exemplo n.º 27
0
        public void GetDatabaseUnits()
        {
            eUnits units = _app.Model.GetDatabaseUnits();

            Assert.AreEqual(eUnits.kip_in_F, units);
        }
Exemplo n.º 28
0
        // /////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Returns the requested TLE data field as a double or 
        /// as a text string in the units requested. 
        /// </summary>
        /// <remarks>
        /// The numeric return values are cached; requesting the same field 
        /// repeatedly incurs minimal overhead.
        /// </remarks>
        /// <param name="fld">The TLE field to retrieve</param>
        /// <param name="units">Specifies the units desired</param>
        /// <param name="str">If non-null, the field is returned as
        /// a string.</param>
        /// <param name="AppendUnits">
        /// If true, units are appended to text string.
        /// </param>
        /// <returns>
        /// The requested field, converted to the requested units if necessary.
        /// </returns>
        public double getField(eField fld,
            eUnits units,
            ref string str,
            bool AppendUnits)
        {
            if (str != null)
            {
                // Return requested field in string form.
                str = m_Field[fld].ToString();

                if (AppendUnits)
                    str += getUnits(fld);

                return 0.0;
            }
            else
            {
                // Return requested field in floating-point form.
                // Return cache contents if it exists, else populate cache.
                int key = Key(units, fld);

                if (m_Cache.ContainsKey(key))
                {
                    // return cached value
                    return (double)m_Cache[key];
                }
                else
                {
                    // Value not in cache; add it
                    double valNative = Double.Parse(m_Field[fld].ToString());
                    double valConv = ConvertUnits(valNative, fld, units);
                    m_Cache[key] = valConv;

                    return valConv;
                }
            }
        }
Exemplo n.º 29
0
 public Timer(eUnits t, Int64 timeAvg, Int64 timeVar)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 30
0
        /// <summary>
        /// Initialization Method - reads all constants from Configuration file
        /// </summary>
        /// <param name="units">Desired units to work in [default is Points]</param>
        /// <param name="xMaxBorder">X Max Limit for Ricochet Calculations</param>
        /// <param name="yMaxBorder">Y Max Limit for Ricochet Calculations</param>
        /// <param name="ricochetFactor">Ricochet Factor to use in calculations</param>
        public void InitializeRicochetCalc(eUnits units = eUnits.Pts, double xMaxBorder = -1, double yMaxBorder = -1, double ricochetFactor = -1)
        {
            if (!IsInitialized)
            {
                _xMinBorder = 0;
                _yMinBorder = 0;
                _ricocheFactor = (ricochetFactor > 0) ? ricochetFactor
                            : Configuration.Attributes.GetValue<double>(Configuration.Names.KEY_RICOCHET_FACTOR);
                switch(units)
                {
                    case eUnits.Mm:
                        _xMaxBorder = (xMaxBorder > 0) ? xMaxBorder
                            : Configuration.Attributes.GetValue<double>(Configuration.Names.TABLE_WIDTH);
                        _yMaxBorder = (yMaxBorder > 0) ? yMaxBorder
                            : Configuration.Attributes.GetValue<double>(Configuration.Names.TABLE_HEIGHT);
                        break;
                    case eUnits.Pts:
                        _xMaxBorder = (xMaxBorder > 0) ? xMaxBorder
                            : Configuration.Attributes.GetValue<double>(Configuration.Names.FOOSBOT_AXE_X_SIZE);
                        _yMaxBorder = (yMaxBorder > 0) ? yMaxBorder
                            : Configuration.Attributes.GetValue<double>(Configuration.Names.FOOSBOT_AXE_Y_SIZE);
                        break;
                    default:
                        throw new NotSupportedException(String.Format(
                            "[{0}] Units [{1}] are not supported by RicochetCalc.",
                                MethodBase.GetCurrentMethod().Name, units.ToString()));

                }
                IsInitialized = true;
            }
        }
Exemplo n.º 31
0
 /// <summary>
 /// This function clears the previous model and initializes the program for a new model.
 /// If it is later needed, you should save your previous model prior to calling this function.
 /// After calling the InitializeNewModel function, it is not necessary to also call the ApplicationStart function because the functionality of the ApplicationStart function is included in the InitializeNewModel function.
 /// </summary>
 /// <param name="units">The database units for the new model.
 /// All data is internally stored in the model in these units.</param>
 /// <returns><c>true</c> if a nuew model is successfully initialized, <c>false</c> otherwise.</returns>
 public bool InitializeNewModel(eUnits units = eUnits.kip_in_F)
 {
     UnitsInitial = units;
     return(_apiModel.InitializeNewModel(units));
 }
Exemplo n.º 32
0
        // what units to convert to
        // ///////////////////////////////////////////////////////////////////////////
        // Convert the given field into the requested units. It is assumed that
        // the value being converted is in the TLE format's "native" form.
        protected double ConvertUnits(double valNative, // value to convert
            eField fld,       // what field the value is
            eUnits units)
        {
            if (fld == eField.FLD_I ||
                fld == eField.FLD_RAAN ||
                fld == eField.FLD_ARGPER ||
                fld == eField.FLD_M)
            {
                // The native TLE format is DEGREES
                if (units == eUnits.U_RAD)
                    return valNative * Globals.RADS_PER_DEG;
            }

            return valNative; // return value in unconverted native format
        }
Exemplo n.º 33
0
 // Generates key for cache
 private int Key(eUnits u, eField f)
 {
     return ((int)u * 100) + (int)f;
 }
Exemplo n.º 34
0
 /// <summary>
 /// Defines if given coordinates in table range.
 /// </summary>
 /// <param name="xCoordinate">X coordinate to compare</param>
 /// <param name="units">Units to work in (mm/pts only) [default is mm]</param>
 /// <returns>[True] if in range, [False] otherwise</returns>
 public bool IsCoordinatesXInRange(int xCoordinate, eUnits units = eUnits.Mm)
 {
     VerifyUnitsSupported(units);
     int max = (units == eUnits.Mm) ? XMaxMm : XMaxPts;
     return (xCoordinate >= 0 && xCoordinate <= max);
 }
Exemplo n.º 35
0
 /// <summary>
 /// Sets the units presently specified for the model.
 /// </summary>
 /// <param name="units">The units.</param>
 /// <exception cref="CSiException"><see cref="CSiApiBase.API_DEFAULT_ERROR_CODE" /></exception>
 /// <exception cref="MPT.CSI.API.Core.Support.CSiException"></exception>
 public void SetPresentUnits(eUnits units)
 {
     _apiModel.SetPresentUnits(units);
     UnitsPresent = units;
 }
Exemplo n.º 36
0
 public void InitializeNewModel(eUnits units)
 {
 }
Exemplo n.º 37
0
 /// <summary>
 /// Defines if given coordinates in table range.
 /// </summary>
 /// <param name="yCoordinate">Y coordinate to compare</param>
 /// <param name="units">Units to work in (mm/pts only) [default is mm]</param>
 /// <returns>[True] if in range, [False] otherwise</returns>
 public bool IsCoordinatesYInRange(int yCoordinate, eUnits units = eUnits.Mm)
 {
     VerifyUnitsSupported(units);
     int max = (units == eUnits.Mm) ? YMaxMm : YMaxPts;
     return (yCoordinate >= 0 && yCoordinate <= max);
 }
Exemplo n.º 38
0
 public Timer(eUnits t, int timeAvg)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 39
0
 public void SetPresentUnits(eUnits units)
 {
 }
Exemplo n.º 40
0
 public Timer(eUnits t, int timeAvg, int timeVar, bool recreate, bool recAutostart)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 41
0
        public void GetPresentUnits()
        {
            eUnits units = _app.Model.GetPresentUnits();

            Assert.AreEqual(eUnits.kip_in_F, units);
        }
Exemplo n.º 42
0
 /// <summary>
 /// Defines if given coordinates in table range.
 /// </summary>
 /// <param name="xCoordinate">X coordinate to compare</param>
 /// <param name="yCoordinate">Y coordinate to compare</param>
 /// <param name="units">Units to work in (mm/pts only) [default is mm]</param>
 /// <returns>[True] if in range, [False] otherwise</returns>
 public bool IsCoordinatesInRange(int xCoordinate, int yCoordinate, eUnits units = eUnits.Mm)
 {
     return (IsCoordinatesXInRange(xCoordinate, units) && IsCoordinatesYInRange(yCoordinate, units));
 }