IniReadInt() public method

Retrieves an integer associated with a key in the specified section.
public IniReadInt ( string section, string key, int def ) : int
section string The name of the section to which the string will be copied.
key string The name of the key to be associated with a string.
def int The default value to return if the key name cannot be found.
return int
Example #1
0
        private static bool AppendCommand()
        {
            // location of the Revit.ini file
            string iniFilename =
                "C:\\Program Files\\Autodesk\\Revit Architecture 2011\\Program\\Revit.ini";

            // verify the file Revit.ini exists
            if (!File.Exists(iniFilename))
            {
                Console.WriteLine("File \"{0}\" not found.", iniFilename);
                return(false);
            }
            // ExternalCommands section
            string commandSection = "ExternalCommands";

            // constants for you application
            string myCommandName        = "My Command";
            string myClassName          = "Test.Command";
            string myCommandDescription = "My Command Description";

            // create an instance of IniFile to read or write the ini file
            IniFile revitIni = new IniFile(iniFilename);

            // get the current command count if it exists. If it doesn't exist then 0 will be returned
            int ecCount = revitIni.IniReadInt(commandSection, "ECCount", 0);

            // increment the command count and use that number as the basis for our command entries
            ecCount++;

            // write the increased ECCount
            if (!revitIni.IniWriteString(commandSection, "ECCount", ecCount.ToString()))
            {
                return(false);
            }

            // write our command name that will appear in the menu to the ini file
            if (!revitIni.IniWriteString(commandSection, "ECName" + ecCount.ToString(), myCommandName))
            {
                return(false);
            }

            // write our class name to the ini file
            if (!revitIni.IniWriteString(commandSection, "ECClassName" + ecCount.ToString(), myClassName))
            {
                return(false);
            }

            // write our command description that will appear in the status bar to the ini file
            if (!revitIni.IniWriteString(commandSection, "ECDescription" + ecCount.ToString(), myCommandDescription))
            {
                return(false);
            }

            return(true);
        }
Example #2
0
        private static bool AppendCommand()
        {
            // location of the Revit.ini file
            string iniFilename =
                "C:\\Program Files\\Autodesk\\Revit Architecture 2011\\Program\\Revit.ini";

            // verify the file Revit.ini exists
            if (!File.Exists(iniFilename))
            {
                Console.WriteLine("File \"{0}\" not found.", iniFilename);
                return false;
            }
            // ExternalCommands section
            string commandSection = "ExternalCommands";

            // constants for you application
            string myCommandName = "My Command";
            string myClassName = "Test.Command";
            string myCommandDescription = "My Command Description";

            // create an instance of IniFile to read or write the ini file
            IniFile revitIni = new IniFile(iniFilename);

            // get the current command count if it exists. If it doesn't exist then 0 will be returned
            int ecCount = revitIni.IniReadInt(commandSection, "ECCount", 0);

            // increment the command count and use that number as the basis for our command entries
            ecCount++;

            // write the increased ECCount
            if (!revitIni.IniWriteString(commandSection, "ECCount", ecCount.ToString()))
                return false;

            // write our command name that will appear in the menu to the ini file
            if (!revitIni.IniWriteString(commandSection, "ECName" + ecCount.ToString(), myCommandName))
                return false;

            // write our class name to the ini file
            if (!revitIni.IniWriteString(commandSection, "ECClassName" + ecCount.ToString(), myClassName))
                return false;

            // write our command description that will appear in the status bar to the ini file
            if (!revitIni.IniWriteString(commandSection, "ECDescription" + ecCount.ToString(), myCommandDescription))
                return false;

            return true;
        }