代码revit二次开发

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

//============代码片段2-1:外部命令中Excute函数的定义============publicinterfaceIExternalCommand{publicAutodesk.Revit.UI.ResultExecute(Autodesk.Revit.UI.ExternalCommandDatacommandData,refstringmessage,Autodesk.Revit.DB.ElementSetelements)}//============代码片段2-2:从commandData中取到Document============UIApplicationuiApplication=commandData.Application;Applicationapplication=uiApplication.Application;UIDocumentuiDocument=uiApplication.ActiveUIDocument;Documentdocument=uiDocument.Document;//============代码片段2-3:使用message参数============publicclasscommand:IExternalCommand{publicResultExecute(ExternalCommandDatacommandData,refstringmessage,ElementSetelements){message=messagetest;returnResult.Failed;}}//============代码片段2-4:使用element参数============publicResultExecute(ExternalCommandDatacommandData,refstringmessage,ElementSetelements){message=PleasetakeattentiononthehighlightedWalls!;//先从UI选取元素,然后执行该插件ElementSetelems=commandData.Application.ActiveUIDocument.Selection.Elements;foreach(Elementeleminelems){Wallwall=elemasWall;if(null!=wall){elements.Insert(elem);}}returnResult.Failed;}//============代码片段2-5:外部命令中Excute函数的返回值============publicResultExecute(ExternalCommandDatacommandData,refstringmessage,ElementSetelements){try{UIDocumentuiDoc=commandData.Application.ActiveUIDocument;Documentdoc=uiDoc.Document;ListElementIdselectedElem=newListElementId();foreach(ElementeleminuiDoc.Selection.Elements){selectedElem.Add(elem.Id);}doc.Delete(selectedElem);TaskDialogResultresult=TaskDialog.Show(Revit,Yestoreturnsucceededanddeleteallselection,+Notocancelallcommands.,TaskDialogCommonButtons.Yes|TaskDialogCommonButtons.No);if(TaskDialogResult.Yes==result){returnResult.Succeeded;}elseif(TaskDialogResult.No==result){elements=uiDoc.Selection.Elements;message=Failedtodeleteselection.;returnResult.Failed;}else{returnResult.Cancelled;}}catch{message=UnexpectedExceptionisthrownout.;returnResult.Failed;}}//============代码片段2-6:IExternalApplication接口定义============publicinterfaceIExternalApplication{Autodesk.Revit.UI.ResultOnShutdown(UIControlledApplicationapplication);Autodesk.Revit.UI.ResultOnStartup(UIControlledApplicationapplication);}//============代码片段2-7:使用IExternalApplication定制UI============publicAutodesk.Revit.UI.ResultOnStartup(UIControlledApplicationapplication){//添加一个新的Ribbon面板RibbonPanelribbonPanel=application.CreateRibbonPanel(NewRibbonPanel);//在新的Ribbon面板上添加一个按钮//点击这个按钮,调用本章第四节第一个实例。PushButtonpushButton=ribbonPanel.AddItem(newPushButtonData(HelloRevit,HelloRevit,@C:\Projects\HelloRevit\HelloRevit.dll,HelloRevit.Class1))asPushButton;returnResult.Succeeded;}publicResultOnShutdown(UIControlledApplicationapplication){//UI定制不需要特别在OnShutdown方法中做处理。returnResult.Succeeded;}//============代码片段2-8:IExternalDBApplication接口定义============publicinterfaceIExternalDBApplication{Autodesk.Revit.DB.ExternalDBApplicationResultOnShutdown(UIControlledApplicationapplication);Autodesk.Revit.DB.ExternalDBApplicationResultOnStartup(UIControlledApplicationapplication);}//============代码片段2-9:ExternalCommand的.addin文件格式示例============?xmlversion=1.0encoding=utf-8standalone=no?RevitAddInsAddInType=CommandAssemblyc:\MyProgram\MyProgram.dll/AssemblyAddInId76eb700a-2c85-4888-a78d-31429ecae9ed/AddInIdFullClassNameRevit.Samples.SampleCommand/FullClassNameTextSamplecommand/TextVisibilityModeNotVisibleInFamily/VisibilityModeVisibilityModeNotVisibleInMEP/VisibilityModeAvailabilityClassNameRevit.Samples.SampleAccessibilityCheck/AvailabilityClassNameLongDescriptionpThisisthelongdescriptionformycommand./ppThisisanotherdescriptiveparagraph,withnotesabouthowtousethecommandproperly./p/LongDescriptionTooltipImagec:\MyProgram\Autodesk.jpg/TooltipImageLargeImagec:\MyProgram\MyProgramIcon.png/LargeImageVendorIdADSK/VendorIdVendorDescriptionAutodesk,============代码片段2-10:ExternalApplication的.addin文件格式示例============?xmlversion=1.0encoding=utf-8standalone=no?RevitAddInsAddInType=ApplicationNameSampleApplication/NameAssemblyc:\MyProgram\MyProgram.dll/AssemblyAddInId604B1052-F742-4951-8576-C261D1993107/AddInIdFullClassNameRevit.Samples.SampleApplication/FullClassNameVendorIdADSK/VendorIdVendorDescriptionAutodesk,============代码片段2-11:数据库级别ExternalApplication的.addin文件格式示例============?xmlversion=1.0standalone=no?RevitAddInsAddInType=DBApplicationAssemblyc:\MyDBLevelApplication\MyDBLevelApplication.dll/AssemblyAddInIdDA3D570A-1AB3-4a4b-B09F-8C15DFEC6BF0/AddInIdFullClassNameMyCompany.MyDBLevelAddIn/FullClassNameNameMyDB-LevelAddIn/NameVendorIdADSK/VendorIdVendorDescriptionAutodesk,============代码片段2-12:外部命令中Excute函数的Transaction属性============[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Automatic)]publicclassClass1:IExternalCommand{}//============代码片段2-13:外部命令中Excute函数的Journaling属性===

1 / 103
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功