完善主體資料,免費贈送VIP會員!
      * 主體類型
      * 企業名稱
      * 信用代碼
      * 所在行業
      * 企業規模
      * 所在職位
      * 姓名
      * 所在行業
      * 學歷
      * 工作性質
      請先選擇行業
      您還可以選擇以下福利:
      行業福利,領完即止!

      下載app免費領取會員

      NULL

      ad.jpg

      二次開發教程:Revit開發創建部件和部件視圖

      發布于:2019-08-26 16:21:21

      網友投稿

      更多

      在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();

              }

          }


      本文版權歸腿腿教學網及原創作者所有,未經授權,謝絕轉載。

      未標題-1.jpg

      上一篇:二次開發教程:Revit開發之AddInManager安裝包簡單制作

      下一篇:二次開發教程:Revit開發之警告和錯誤處理

      主站蜘蛛池模板: 无码中文字幕人妻在线一区二区三区 | 搜日本一区二区三区免费高清视频 | 精品无码一区二区三区在线 | 国产成人无码一区二区在线播放 | 在线不卡一区二区三区日韩| 国产一区二区三区四| 久久毛片免费看一区二区三区| 日韩精品在线一区二区| 亚洲av日韩综合一区久热| 东京热无码av一区二区| 乱码精品一区二区三区| 一区二区三区在线|欧| 色一乱一伦一图一区二区精品| 亚洲制服中文字幕第一区| 国产精品制服丝袜一区| 国产中的精品一区的| 久久se精品一区精品二区国产| 中文字幕在线观看一区二区| 久久国产免费一区二区三区| 国产精品福利一区二区| 国产aⅴ一区二区| 精品少妇一区二区三区视频| 亚洲视频一区二区在线观看| 日本精品一区二区在线播放| 制服中文字幕一区二区 | 亚洲一区二区三区无码国产| 精品国产日韩亚洲一区91| 日韩精品无码一区二区视频| 亚洲AV一区二区三区四区| 国产高清一区二区三区四区| 麻豆AV一区二区三区| 国产一区在线播放| 末成年女A∨片一区二区| 日本一区二区三区中文字幕| 午夜福利一区二区三区在线观看| 日本精品3d动漫一区二区 | 久久精品国产第一区二区三区| 国产a久久精品一区二区三区| 激情内射亚洲一区二区三区| A国产一区二区免费入口| 精品国产免费一区二区|