Revit开发创建部件和部件视图
来源:互联网 发布:尤克里里调音软件 安卓 编辑:程序博客网 时间:2024/05/16 17:59
在Revit里可以把一部分构件组合起来创建为一个部件,
然后可以创建一些针对这个部件的视图
通过API来创建主要用到两个类
AssemblyInstance
AssemblyViewUtils
下面是一个小例子:
Command:
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
IList<Reference> refs = uidoc.Selection.PickObjects(ObjectType.Element);
List<Element> elems = new List<Element>();
List<ElementId> ids = new List<ElementId>();
foreach (Reference r in refs)
{
Element e = doc.GetElement(r);
elems.Add(e);
ids.Add(e.Id);
}
ViewModel myViewModel = new ViewModel(elems);
AssemblyViewWindow myWin = new AssemblyViewWindow(myViewModel);
if(myWin.ShowDialog()??false)
{
TransactionGroup transGrop = new TransactionGroup(doc, "transGroup");
transGrop.Start();
Transaction trans = new Transaction(doc, "trans");
trans.Start();
AssemblyInstance assemblyInstance = AssemblyInstance.Create(doc, ids, myViewModel.Category.Id);
trans.Commit();
trans = new Transaction(doc, "rename");//
trans.Start();
ElementId typeId = assemblyInstance.GetTypeId();
Element type = doc.GetElement(typeId);
type.Name = myViewModel.AssemblyInstanceName;
View3D view3d = AssemblyViewUtils.Create3DOrthographic(doc, assemblyInstance.Id);
trans.Commit();
transGrop.Assimilate();
}
return Result.Succeeded;
}
Window:
<Window x:Class="AssemblyView.AssemblyViewWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="新建部件" SizeToContent="WidthAndHeight">
<Window.Resources>
<Style TargetType="Label">
<Setter Property="Margin" Value="5"/>
<Setter Property="HorizontalAlignment" Value="Right"/>
</Style>
<Style TargetType="TextBox">
<Setter Property="Margin" Value="5"/>
<Setter Property="Width" Value="80"/>
</Style>
<Style TargetType="ComboBox">
<Setter Property="Margin" Value="5"/>
<Setter Property="Width" Value="80"/>
</Style>
<Style TargetType="Button">
<Setter Property="Margin" Value="5"/>
<Setter Property="Width" Value="75"/>
<Setter Property="Height" Value="23"/>
</Style>
</Window.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Label Content="类型名称:" Grid.Column="0" Grid.Row="0"/>
<TextBox Grid.Column="1" Grid.Row="0" Text="{Binding Path=AssemblyInstanceName, UpdateSourceTrigger=PropertyChanged}"/>
<Label Content="命名类别:" Grid.Column="0" Grid.Row="1"/>
<ComboBox Grid.Column="1" Grid.Row="1" ItemsSource="{Binding Path=Categories, UpdateSourceTrigger=PropertyChanged}" SelectedItem="{Binding Path=Category, UpdateSourceTrigger=PropertyChanged}" DisplayMemberPath="Name"/>
<StackPanel Orientation="Horizontal" Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2" HorizontalAlignment="Right">
<Button Content="确定" IsEnabled="{Binding Path=IsEnabled, UpdateSourceTrigger=PropertyChanged}" Command="{Binding Path=OK_Command}" CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType=Window}}"/>
<Button Content="取消" Command="{Binding Path=Cancel_Command}" CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor ,AncestorType=Window}}" />
</StackPanel>
</Grid>
</Window>
public partial class AssemblyViewWindow : Window
{
public AssemblyViewWindow()
{
InitializeComponent();
}
public AssemblyViewWindow(ViewModel viewModel)
{
InitializeComponent();
this.DataContext = viewModel;
}
}
ViewModel:
public class ViewModel:INotifyPropertyChanged
{
private string assemblyInstanceName = string.Empty;
public string AssemblyInstanceName
{
get
{
return assemblyInstanceName;
}
set
{
assemblyInstanceName = value;
NotifyPropertyChanged("AssemblyInstanceName");
CheckOkBtn();
}
}
private List<Category> categories = new List<Category>();
public List<Category> Categories
{
get
{
return categories;
}
}
private Category category = null;
public Category Category
{
get
{
return category;
}
set
{
category = value;
NotifyPropertyChanged("Category");
CheckOkBtn();
}
}
private bool isEnabled = false;
public bool IsEnabled
{
get { return isEnabled; }
set
{
isEnabled = value;
}
}
private OK_Command ok_Command = null;
public OK_Command OK_Command
{
get { return ok_Command; }
}
private Cancel_Command cancel_Command = null;
public Cancel_Command Cancel_Command
{
get { return cancel_Command; }
}
public ViewModel(List<Element> elems)
{
foreach(Element elm in elems)
{
if (categories.Where(m=>m.Name==elm.Category.Name).Count()==0)
categories.Add(elm.Category);
}
this.cancel_Command = new Cancel_Command();
this.ok_Command = new OK_Command();
}
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(string name)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
private void CheckOkBtn()
{
if (assemblyInstanceName == string.Empty || category == null)
IsEnabled = false;
else
IsEnabled = true;
NotifyPropertyChanged("IsEnabled");
}
}
ICommand:
public class OK_Command : ICommand
{
public bool CanExecute(object parameter)
{
return true;
}
public event EventHandler CanExecuteChanged;
public void Execute(object parameter)
{
AssemblyViewWindow myWin = parameter as AssemblyViewWindow;
myWin.DialogResult = true;
myWin.Close();
}
}
public class Cancel_Command : ICommand
{
public bool CanExecute(object parameter)
{
return true;
}
public event EventHandler CanExecuteChanged;
public void Execute(object parameter)
{
AssemblyViewWindow myWin = parameter as AssemblyViewWindow;
myWin.DialogResult = false;
myWin.Close();
}
}
如有错误欢迎指正
博主会经常更新一些技术文章,请大家多多关注,
源码下载请加qq群480950299
- Revit开发创建部件和部件视图
- SP2010开发和VS2010专家"食谱"--第五章节—Web部件(1)--创建可视Web部件
- SP2010开发和VS2010专家"食谱"--第五章节—Web部件(3)--创建启用AJAX的Web部件
- SP2010开发和VS2010专家"食谱"--第五章节—Web部件(5)--创建可连接的Web部件
- SP2010开发和VS2010专家"食谱"--第五章节—Web部件(6)--创建Silverlight Web部件
- android视图学习---添加窗口小部件以及AppWidget的创建详解和快捷方式
- 创建 ActiveX EXE 部件
- 创建图形界面的部件
- 桌面小部件创建?
- Android桌面部件开发
- SP2010开发和VS2010专家"食谱"--第五章节—Web部件(2)--创建纯代码部件(沙盒解决方案)
- 一步步学习SPD2010--第三章节--处理列表和库(7)----创建XSLT列表视图Web部件
- 这个例子演示了如何创建一个父窗口部件和子窗口部件。
- 部件和布局 - QGraphicsWidget
- 部件和布局
- android widget简单开发一之创建一个小部件
- Stbdroid之代码动态创建和删除小部件
- Dojo 利用 Dijit Button 和 FilteringSelect 创建自定义小部件
- Mybatis极其(最)简(好)单(用)的一个分页插件
- Objective-C Runtime[细读]
- c语言中对文件修改后放入同一文件中
- mysql导入数据load data infile用法(将txt文件中的数据导入表中)
- Structs2 输入校验,Action中校验,在xml中校验
- Revit开发创建部件和部件视图
- 相对布局(RelativeLayout)
- SPDY协议 - v3
- C语言的输入输出模型
- textarea回车符 \r\n 在各个浏览器中表现
- Git常用命令总结2
- c#第五章指导学习:库存管理
- *[Lintcode]Two Sum 两数之和
- CI框架源码解析二十之文件上传类文件Upload.php