mirror of
https://github.com/jeremytammik/RevitSdkSamples.git
synced 2026-09-26 04:34:47 +00:00
cleaned up old snapshots
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
//
|
||||
// (C) Copyright 2003-2009 by Autodesk, Inc.
|
||||
//
|
||||
// Permission to use, copy, modify, and distribute this software in
|
||||
// object code form for any purpose and without fee is hereby granted,
|
||||
// provided that the above copyright notice appears in all copies and
|
||||
// that both that copyright notice and the limited warranty and
|
||||
// restricted rights notice below appear in all supporting
|
||||
// documentation.
|
||||
//
|
||||
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
|
||||
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
|
||||
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
|
||||
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
|
||||
// UNINTERRUPTED OR ERROR FREE.
|
||||
//
|
||||
// Use, duplication, or disclosure by the U.S. Government is subject to
|
||||
// restrictions set forth in FAR 52.227-19 (Commercial Computer
|
||||
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
|
||||
// (Rights in Technical Data and Computer Software), as applicable.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Revit.SDK.Samples.ModifyIniFile.CS
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains methods to read and write value to specialized key in an ini file
|
||||
/// </summary>
|
||||
public class IniFile
|
||||
{
|
||||
//path of ini file
|
||||
private string m_path;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the path of ini file
|
||||
/// </summary>
|
||||
public string Path
|
||||
{
|
||||
get { return m_path; }
|
||||
set { m_path = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies a string into the specified section of an initialization file.
|
||||
/// </summary>
|
||||
/// <param name="section">The name of the section to which the string will be copied.
|
||||
/// If the section does not exist, it is created. The name of the section is case-independent;
|
||||
/// the string can be any combination of uppercase and lowercase letters. </param>
|
||||
/// <param name="key">The name of the key to be associated with a string.
|
||||
/// If the key does not exist in the specified section, it is created. If this parameter is NULL,
|
||||
/// the entire section, including all entries within the section, is deleted.</param>
|
||||
/// <param name="val">A string to be written to the file. If this parameter is NULL,
|
||||
/// the key pointed to by the key parameter is deleted.</param>
|
||||
/// <param name="filePath">The name of the initialization file.</param>
|
||||
/// <returns>If the function successfully copies the string to the initialization file,
|
||||
/// the return value is nonzero. If the function fails, or if it flushes the cached version of
|
||||
/// the most recently accessed initialization file, the return value is zero.</returns>
|
||||
[DllImport("kernel32")]
|
||||
private static extern int WritePrivateProfileString(string section, string key, string val, string filePath);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves an integer associated with a key in the specified section of an initialization file.
|
||||
/// </summary>
|
||||
/// <param name="section">The name of the section in the initialization file. </param>
|
||||
/// <param name="key">The name of the key whose value is to be retrieved. This value is
|
||||
/// in the form of a string; the GetPrivateProfileInt function converts the string into an integer
|
||||
/// and returns the integer.</param>
|
||||
/// <param name="def">The default value to return if the key name cannot be found in the initialization file.</param>
|
||||
/// <param name="filePath">The name of the initialization file. If this parameter does not contain
|
||||
/// a full path to the file, the system searches for the file in the Windows directory. </param>
|
||||
/// <returns> The integer equivalent of the string following the specified key name in the
|
||||
/// specified initialization file. If the key is not found, the return value is the specified
|
||||
/// default value. </returns>
|
||||
[DllImport("kernel32")]
|
||||
private static extern int GetPrivateProfileInt(string section, string key, int def, string filePath);
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of IniFile to read and write
|
||||
/// </summary>
|
||||
/// <param name="inipath">Path of ini file to read or write</param>
|
||||
public IniFile(string inipath)
|
||||
{
|
||||
m_path = inipath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies a string into the specified section of an initialization file.
|
||||
/// </summary>
|
||||
/// <param name="section">The name of the section to which the string will be copied.</param>
|
||||
/// <param name="key">The name of the key to be associated with a string.</param>
|
||||
/// <param name="value">A string to be written to the file.</param>
|
||||
/// <returns>If the function successfully copies the string return true otherwise false</returns>
|
||||
public bool IniWriteString(string section, string key, string value)
|
||||
{
|
||||
return WritePrivateProfileString(section, key, value, this.m_path) == 0 ? false : true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves an integer associated with a key in the specified section.
|
||||
/// </summary>
|
||||
/// <param name="section">The name of the section to which the string will be copied.</param>
|
||||
/// <param name="key">The name of the key to be associated with a string.</param>
|
||||
/// <param name="def">The default value to return if the key name cannot be found.</param>
|
||||
/// <returns>The integer equivalent of the string following the specified key name,
|
||||
/// If the key is not found, the return value is the specified default value.</returns>
|
||||
public int IniReadInt(string section, string key, int def)
|
||||
{
|
||||
return GetPrivateProfileInt(section, key, def, this.m_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{7663477E-7A3A-44A8-B846-DD3E9237BA80}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>ModifyIniFile</RootNamespace>
|
||||
<AssemblyName>ModifyIniFile</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Core">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="IniFile.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -0,0 +1,88 @@
|
||||
//
|
||||
// (C) Copyright 2003-2009 by Autodesk, Inc.
|
||||
//
|
||||
// Permission to use, copy, modify, and distribute this software in
|
||||
// object code form for any purpose and without fee is hereby granted,
|
||||
// provided that the above copyright notice appears in all copies and
|
||||
// that both that copyright notice and the limited warranty and
|
||||
// restricted rights notice below appear in all supporting
|
||||
// documentation.
|
||||
//
|
||||
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
|
||||
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
|
||||
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
|
||||
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
|
||||
// UNINTERRUPTED OR ERROR FREE.
|
||||
//
|
||||
// Use, duplication, or disclosure by the U.S. Government is subject to
|
||||
// restrictions set forth in FAR 52.227-19 (Commercial Computer
|
||||
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
|
||||
// (Rights in Technical Data and Computer Software), as applicable.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace Revit.SDK.Samples.ModifyIniFile.CS
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
if(!AppendCommand())
|
||||
{
|
||||
Console.WriteLine("Add External Command failed.");
|
||||
}
|
||||
}
|
||||
|
||||
private static bool AppendCommand()
|
||||
{
|
||||
// location of the Revit.ini file
|
||||
string iniFilename =
|
||||
"C:\\Program Files\\Autodesk Revit Architecture 2010\\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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
//
|
||||
// (C) Copyright 2003-2009 by Autodesk, Inc.
|
||||
//
|
||||
// Permission to use, copy, modify, and distribute this software in
|
||||
// object code form for any purpose and without fee is hereby granted,
|
||||
// provided that the above copyright notice appears in all copies and
|
||||
// that both that copyright notice and the limited warranty and
|
||||
// restricted rights notice below appear in all supporting
|
||||
// documentation.
|
||||
//
|
||||
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
|
||||
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
|
||||
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
|
||||
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
|
||||
// UNINTERRUPTED OR ERROR FREE.
|
||||
//
|
||||
// Use, duplication, or disclosure by the U.S. Government is subject to
|
||||
// restrictions set forth in FAR 52.227-19 (Commercial Computer
|
||||
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
|
||||
// (Rights in Technical Data and Computer Software), as applicable.
|
||||
//
|
||||
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("ModifyIniFile")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("ModifyIniFile")]
|
||||
[assembly: AssemblyCopyright("Copyright © Autodesk, Inc. 2009")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("b2dec21d-a7e4-4da4-b880-72ed805bd07a")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
Binary file not shown.
Reference in New Issue
Block a user