118 lines
3.4 KiB
C#
118 lines
3.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Autodesk.Revit.DB;
|
|
|
|
namespace KMBIM.Utils
|
|
{
|
|
class SharedParameterBindingManager
|
|
{
|
|
public String parameterName { get; set; }
|
|
|
|
#if _22 || _23
|
|
public ForgeTypeId parameterType;
|
|
#else
|
|
public ParameterType parameterType { get; set; }
|
|
#endif
|
|
public bool UserModifiable { get; set; }
|
|
public bool UserVisible { get; set; }
|
|
public String Description { get; set; }
|
|
public bool Instance { get; set; }
|
|
public Definition Definition { get; set; }
|
|
public BuiltInParameterGroup ParameterGroup { get; set; }
|
|
|
|
|
|
public SharedParameterBindingManager()
|
|
{
|
|
parameterName = "Invalid";
|
|
#if _22 || _23
|
|
parameterType = new ForgeTypeId();
|
|
#else
|
|
parameterType = ParameterType.Invalid;
|
|
#endif
|
|
UserModifiable = true;
|
|
UserVisible = true;
|
|
Description = "";
|
|
Instance = true;
|
|
Definition = null;
|
|
ParameterGroup = BuiltInParameterGroup.PG_IDENTITY_DATA;
|
|
}
|
|
|
|
|
|
List<BuiltInCategory> m_categories = new List<BuiltInCategory>();
|
|
|
|
public ExternalDefinitionCreationOptions GetCreationOptions()
|
|
{
|
|
ExternalDefinitionCreationOptions options = new ExternalDefinitionCreationOptions(parameterName, parameterType);
|
|
options.UserModifiable = UserModifiable;
|
|
options.Visible = UserVisible;
|
|
|
|
options.Description = Description;
|
|
return options;
|
|
}
|
|
|
|
public void AddCategory(BuiltInCategory category)
|
|
{
|
|
m_categories.Add(category);
|
|
}
|
|
|
|
private CategorySet GetCategories(Document doc)
|
|
{
|
|
Categories categories = doc.Settings.Categories;
|
|
|
|
CategorySet categorySet = new CategorySet();
|
|
|
|
foreach (BuiltInCategory bic in m_categories)
|
|
{
|
|
var cat = categories.get_Item(bic);
|
|
if(cat!=null) categorySet.Insert(categories.get_Item(bic));
|
|
}
|
|
|
|
return categorySet;
|
|
}
|
|
|
|
public void AddBindings(Document doc)
|
|
{
|
|
Binding binding;
|
|
CategorySet cs = GetCategories(doc);
|
|
if (Instance)
|
|
{
|
|
binding = new InstanceBinding(cs);
|
|
}
|
|
else
|
|
{
|
|
binding = new TypeBinding(cs);
|
|
}
|
|
// assumes transaction open
|
|
|
|
try
|
|
{
|
|
doc.ParameterBindings.Insert(Definition, binding, ParameterGroup);
|
|
ExternalDefinition edef = Definition as ExternalDefinition;
|
|
if (edef != null)
|
|
{
|
|
SharedParameterElement sp = SharedParameterElement.Lookup(doc, edef.GUID);
|
|
if (sp != null)
|
|
{
|
|
InternalDefinition def = sp.GetDefinition();
|
|
if (def.VariesAcrossGroups != true)
|
|
{
|
|
// Must be within an outer transaction!
|
|
def.SetAllowVaryBetweenGroups(doc, true);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var is_readonly = cs.IsReadOnly;
|
|
string msg = ex.Message;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|