本文整理汇总了C#中Application.OpenSharedParameterFile方法的典型用法代码示例。如果您正苦于以下问题:C# Application.OpenSharedParameterFile方法的具体用法?C# Application.OpenSharedParameterFile怎么用?C# Application.OpenSharedParameterFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Application
的用法示例。
在下文中一共展示了Application.OpenSharedParameterFile方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSharedParameterFile
/// <summary>
/// Get shared parameter DefinitionFile of given Revit DB Application.
/// </summary>
/// <param name="revitApp">Revit DB Application</param>
/// <returns>DefinitionFile of Revit DB Application</returns>
public static DefinitionFile GetSharedParameterFile(Application revitApp)
{
DefinitionFile file = null;
int count = 0;
// A count is to avoid infinite loop
while (null == file && count < 100)
{
file = revitApp.OpenSharedParameterFile();
if (file == null)
{
// If Shared parameter file does not exist, then create a new one.
string shapeFile =
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
+ "\\MultiplanarParameterFiles.txt";
// Fill Schema data of Revit shared parameter file.
// If no this schema data, OpenSharedParameterFile may alway return null.
System.Text.StringBuilder contents = new System.Text.StringBuilder();
contents.AppendLine("# This is a Revit shared parameter file.");
contents.AppendLine("# Do not edit manually.");
contents.AppendLine("*META VERSION MINVERSION");
contents.AppendLine("META 2 1");
contents.AppendLine("*GROUP ID NAME");
contents.AppendLine("*PARAM GUID NAME DATATYPE DATACATEGORY GROUP VISIBLE");
// Write Schema data of Revit shared parameter file.
File.WriteAllText(shapeFile, contents.ToString());
// Set Revit shared parameter file
revitApp.SharedParametersFilename = shapeFile;
}
// To avoid infinite loop.
++count;
}
return file;
}
示例2: GetSharedParamsFile
/// <summary>
/// Get shared parameters file.
/// </summary>
public static DefinitionFile GetSharedParamsFile(
Application app)
{
string sharedParamsFileName
= app.SharedParametersFilename;
if ( 0 == sharedParamsFileName.Length
|| null == app.OpenSharedParameterFile() )
{
StreamWriter stream;
stream = new StreamWriter( SharedParameterFilePath );
stream.Close();
app.SharedParametersFilename = SharedParameterFilePath;
sharedParamsFileName = app.SharedParametersFilename;
}
// Get the current file object and return it.
DefinitionFile sharedParametersFile
= app.OpenSharedParameterFile();
return sharedParametersFile;
}
示例3: SharedParamGuid
/// <summary>
/// Get GUID for a given shared param name.
/// </summary>
/// <param name="app">Revit application</param>
/// <param name="defGroup">Definition group name</param>
/// <param name="defName">Definition name</param>
/// <returns>GUID</returns>
static Guid SharedParamGuid( Application app, string defGroup, string defName )
{
Guid guid = Guid.Empty;
try
{
DefinitionFile file = app.OpenSharedParameterFile();
DefinitionGroup group = file.Groups.get_Item( defGroup );
Definition definition = group.Definitions.get_Item( defName );
ExternalDefinition externalDefinition = definition as ExternalDefinition;
guid = externalDefinition.GUID;
}
catch( Exception )
{
}
return guid;
}
示例4: SharedParamGuid
/// <summary>
/// Return GUID for a given shared parameter group and name.
/// </summary>
/// <param name="app">Revit application</param>
/// <param name="defGroup">Definition group name</param>
/// <param name="defName">Definition name</param>
/// <returns>GUID</returns>
public static Guid SharedParamGuid(
Application app,
string defGroup,
string defName)
{
DefinitionFile file = app.OpenSharedParameterFile();
DefinitionGroup group = ( null == file )
? null : file.Groups.get_Item( defGroup );
Definition definition = ( null == group )
? null : group.Definitions.get_Item( defName );
ExternalDefinition externalDefinition
= ( null == definition )
? null : definition as ExternalDefinition;
return ( null == externalDefinition )
? Guid.Empty
: externalDefinition.GUID;
}
示例5: AccessOrCreateSharedParameterFile
/// <summary>
/// Access an existing or create a new shared parameters file.
/// </summary>
/// <param name="app">Revit Application.</param>
/// <returns>the shared parameters file.</returns>
private static DefinitionFile AccessOrCreateSharedParameterFile(Application app)
{
// The location of this command assembly
string currentCommandAssemblyPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
// The path of ourselves shared parameters file
string sharedParameterFilePath = Path.GetDirectoryName(currentCommandAssemblyPath);
sharedParameterFilePath = sharedParameterFilePath + "\\MySharedParameterFile.txt";
//Method's return
DefinitionFile sharedParameterFile = null;
// Check if the file exits
System.IO.FileInfo documentMessage = new FileInfo(sharedParameterFilePath);
bool fileExist = documentMessage.Exists;
// Create file for external shared parameter since it does not exist
if (!fileExist)
{
FileStream fileFlow = File.Create(sharedParameterFilePath);
fileFlow.Close();
}
// Set ourselves file to the externalSharedParameterFile
app.SharedParametersFilename = sharedParameterFilePath;
sharedParameterFile = app.OpenSharedParameterFile();
return sharedParameterFile;
}
示例6: GetSharedParamsFile
/// <summary>
/// Helper to get shared parameters file.
/// </summary>
public static DefinitionFile GetSharedParamsFile(Application app)
{
// Get current shared params file name
string sharedParamsFileName;
try
{
sharedParamsFileName = app.SharedParametersFilename;
}
catch (Exception ex)
{
TaskDialog.Show("Get shared params file", "No shared params file set:" + ex.Message);
return null;
}
if (0 == sharedParamsFileName.Length ||
!System.IO.File.Exists(sharedParamsFileName))
{
StreamWriter stream;
stream = new StreamWriter(kSharedParamsPath);
stream.Close();
app.SharedParametersFilename = kSharedParamsPath;
sharedParamsFileName = app.SharedParametersFilename;
}
// Get the current file object and return it
DefinitionFile sharedParametersFile;
try
{
sharedParametersFile = app.OpenSharedParameterFile();
}
catch (Exception ex)
{
TaskDialog.Show("Get shared params file", "Cannnot open shared params file:" + ex.Message);
sharedParametersFile = null;
}
return sharedParametersFile;
}
示例7: CreateProjectParameter
/// <summary>
/// create project parameter
/// source :http://spiderinnet.typepad.com/blog/2011/05/parameter-of-revit-api-31-create-project-parameter.html
/// </summary>
/// <param name="app">revit application</param>
/// <param name="name">revit ui application</param>
/// <param name="type">parameter type</param>
/// <param name="cats">category set</param>
/// <param name="group">parameter group</param>
/// <param name="inst">is instance variable</param>
public void CreateProjectParameter(Application app, string name, ParameterType type, CategorySet cats, BuiltInParameterGroup group, bool instance)
{
string oriFile = app.SharedParametersFilename;
string tempFile = Path.GetTempFileName() + ".txt";
using (File.Create(tempFile)) { }
app.SharedParametersFilename = tempFile;
ExternalDefinitionCreationOptions edc=new ExternalDefinitionCreationOptions(name, type);
ExternalDefinition def = app.OpenSharedParameterFile().Groups.Create("TemporaryDefintionGroup").Definitions.Create(edc) as ExternalDefinition;
app.SharedParametersFilename = oriFile;
File.Delete(tempFile);
Autodesk.Revit.DB.Binding binding = app.Create.NewTypeBinding(cats);
if (instance) binding = app.Create.NewInstanceBinding(cats);
BindingMap map = (new UIApplication(app)).ActiveUIDocument.Document.ParameterBindings;
map.Insert(def, binding, group);
}
示例8: SharedParamGuid
/// <summary>
/// Return GUID for a given shared parameter group and name.
/// </summary>
/// <param name="app">Revit application</param>
/// <param name="defGroup">Definition group name</param>
/// <param name="defName">Definition name</param>
/// <returns>GUID</returns>
public static Guid SharedParamGuid(
Application app,
string defGroup,
string defName )
{
DefinitionFile file = app.OpenSharedParameterFile();
DefinitionGroup group = file.Groups.get_Item( defGroup );
Definition definition = group.Definitions.get_Item( defName );
ExternalDefinition externalDefinition = definition as ExternalDefinition;
return externalDefinition.GUID;
}