99 lines
3.2 KiB
C#
99 lines
3.2 KiB
C#
|
|
|
|||
|
|
using Autodesk.Revit.Attributes;
|
|||
|
|
|
|||
|
|
using Autodesk.Revit.DB;
|
|||
|
|
using Autodesk.Revit.UI;
|
|||
|
|
|
|||
|
|
using Nice3point.Revit.Toolkit.External;
|
|||
|
|
|
|||
|
|
using System.Linq;
|
|||
|
|
|
|||
|
|
|
|||
|
|
namespace Szmedi.RvKits.InfoManager
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// Revit执行命令
|
|||
|
|
/// </summary>
|
|||
|
|
[Transaction(TransactionMode.Manual)]
|
|||
|
|
public class RemoveParamsCmd : ExternalCommand
|
|||
|
|
{
|
|||
|
|
public override void Execute()
|
|||
|
|
{
|
|||
|
|
//var bindings = Document.ParameterBindings;
|
|||
|
|
//foreach (ElementBinding item in bindings)
|
|||
|
|
//{
|
|||
|
|
// var de = GetDefinition(item, Document);
|
|||
|
|
//}
|
|||
|
|
//var b = IsExistProjectParam(Document, "备注", out var definition, out var bind);
|
|||
|
|
//var dict = SharedParameterAssists.GetParameterElementBindings(Document);
|
|||
|
|
//foreach (var d in dict)
|
|||
|
|
//{
|
|||
|
|
// Debug.WriteLine(d.Key.GetDefinition().Name);
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
//Document.Invoke(
|
|||
|
|
//_ =>
|
|||
|
|
//{
|
|||
|
|
|
|||
|
|
// Document.ParameterBindings.Remove(definition);
|
|||
|
|
//});
|
|||
|
|
WinDialogAssists.ShowOrActivate<RemoveParametersWin, RemoveParametersViewModel>(UiDocument);
|
|||
|
|
}
|
|||
|
|
private void RemoveSome(Element element, params string[] paramNames)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
public void IsProjectParameter(Document doc)
|
|||
|
|
{
|
|||
|
|
var parameterElements = doc.OfClass<ParameterElement>().Cast<ParameterElement>();
|
|||
|
|
var sharedParameterElements = doc.OfClass<SharedParameterElement>().Cast<SharedParameterElement>();
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
public void Delete(UIDocument uidoc, Parameter param)
|
|||
|
|
{
|
|||
|
|
var doc = uidoc.Document;
|
|||
|
|
BindingMap map = doc.ParameterBindings;
|
|||
|
|
var parameterElements = doc.OfClass<ParameterElement>().Cast<ParameterElement>();
|
|||
|
|
|
|||
|
|
if (param.IsShared)
|
|||
|
|
{
|
|||
|
|
//删除定义
|
|||
|
|
uidoc.Document.ParameterBindings.Remove(param.Definition);
|
|||
|
|
}
|
|||
|
|
else if (map.Contains(param.Definition))
|
|||
|
|
{
|
|||
|
|
var paramElement = parameterElements.Where(p => p.Name == param.Definition.Name).FirstOrDefault();
|
|||
|
|
uidoc.Document.Delete(paramElement.Id);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public bool IsExistProjectParam(Document doc, string paramName, out Definition definition, out ElementBinding binding)
|
|||
|
|
{
|
|||
|
|
DefinitionBindingMap map = doc.ParameterBindings;
|
|||
|
|
var dep = map.ForwardIterator();
|
|||
|
|
var isExist = false;
|
|||
|
|
binding = null;
|
|||
|
|
definition = null;
|
|||
|
|
while (dep.MoveNext())
|
|||
|
|
{
|
|||
|
|
definition = dep.Key;
|
|||
|
|
var definitionName = definition.Name;
|
|||
|
|
binding = dep.Current as ElementBinding;
|
|||
|
|
//ParameterType parameterType = definition.ParameterType;
|
|||
|
|
//InstanceBinding instanceBinding = dep.Current as InstanceBinding;
|
|||
|
|
//if (instanceBinding != null)
|
|||
|
|
//{
|
|||
|
|
// CategorySet categorySet = instanceBinding.Categories;
|
|||
|
|
//}
|
|||
|
|
if (definitionName == paramName)
|
|||
|
|
{
|
|||
|
|
isExist = true;
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return isExist;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|