©2013AutodeskRevit工作集协同模式的API应用探究刘培珺Autodesk中国研究院开发经理首届中国开发者训练营——DevCampChina1st©2013Autodesk刘培珺职务/Autodesk中国研究院开发经理部门/IPG2004年毕业于浙江大学CAD&CG国家重点实验室并获得工学博士学位。毕业后加入阿尔卡特从事无线研发工作。2006年加入AutodeskAEC部门,RevitAPI团队开发经理,负责RevitAPI的设计、开发与测试。认识我©2013Autodesk对于大型的设计项目,有效地协同工作、工作共享可以提高建筑设计的效率,优化建筑的经济性,对于设计团队来说无疑是非常重要的话题。本课程将从二次开发的角度,介绍工作共享相关API的设计与使用。课程简介©2013AutodeskRevit工作共享主要工作流程工作共享中的数据操作工作共享中的工作集管理工作共享中的权限管理工作共享的显示模式工作共享相关的事件日程©2013Autodesk什么是工作共享?©2013AutodeskRevit工作协同功能©2013Autodesk工作协同主要流程©2013Autodesk创建中心文件保存打开工作共享©2013Autodesk创建本地文件打开保存©2013Autodesk数据保存保存权限同步到中心文件©2013Autodesk数据提取载入最新工作集保存©2013Autodesk数据修改修改权限授权没有权限授权©2013AutodeskWorksharingAPI©2013AutodeskSave,SaveAs,SaveOptions和WorksharingSaveAsOptionsOpen和OpenOptionsReloadLatest,HasAllChangesFromCentral和ReloadLatestOptionsSynchronizeWithCentral,SynchronizeWithCentralOptions,RelinquishOptions和TransactWithCentralOptions工作共享数据操作©2013AutodeskSave,SaveAs,SaveOptions,SaveAsOptions和WorksharingSaveAsOptions©2013AutodeskOpen,OpenOptions和DetachFromCentralOptionOpenOptionsopenOptions=newOpenOptions();WorksetConfigurationconfig=openOptions.GetOpenWorksetsConfiguration();if(null==config){config=newWorksetConfiguration();openOptions.SetOpenWorksetsConfiguration(config);}config.OpenLastViewed();DocumentnewDoc=RevitApp.OpenDocumentFile(ModelPathUtils.ConvertUserVisiblePathToModelPath(OpenDocument.rvt),openOptions);©2013AutodeskReloadLatestTransactiontrans=newTransaction(RevitDoc,RL);trans.Start();ReloadLatestOptionsoptions=newReloadLatestOptions();RevitDoc.ReloadLatest(options);boolisUpdated=RevitDoc.HasAllChangesFromCentral();trans.Commit();©2013AutodeskSynchronizeWithCentralSynchronizeWithCentralOptionsoptions=newSynchronizeWithCentralOptions();options.Comment=@RelinquishOptions;RelinquishOptionsnewRelinqOptions=newRelinquishOptions(false);newRelinqOptions.CheckedOutElements=true;newRelinqOptions.StandardWorksets=false;options.SetRelinquishOptions(newRelinqOptions);TransactWithCentralOptionstransOptions=newTransactWithCentralOptions();CallBackcallInst=newCallBack();transOptions.SetLockCallback(callInst);RevitDoc.SynchronizeWithCentral(transOptions,options);©2013AutodeskWorkset和WorksetTableWorksetDefaultVisibilitySettingsWorksetVisibilityElementWorksetFilterFilteredWorksetCollector和WorksetKindFilter工作共享中的工作集管理©2013AutodeskWorkset和WorksetTableWorksetTableworksetTable=RevitDoc.GetWorksetTable();WorksetIdactiveId=worksetTable.GetActiveWorksetId();WorksetactiveWorkset=worksetTable.GetWorkset(activeId);WorksetwallWorkset=worksetTable.GetWorkset(wall.WorksetId);©2013AutodeskWorksetDefaultVisibilitySettingsWorksetDefaultVisibilitySettingsdefaultVisibility=WorksetDefaultVisibilitySettings.GetWorksetDefaultVisibilitySettings(RevitDoc);boolisVisible=defaultVisibility.IsWorksetVisible(worksetId);defaultVisibility.SetWorksetVisibility(worksetId,!isVisible);©2013AutodeskWorksetVisibilityViewview=getActiveView();WorksetVisibilityvisibility=view.GetWorksetVisibility(worksetId);view.SetWorksetVisibility(worksetId,WorksetVisibility.Hidden);visibility=view.GetWorksetVisibility(worksetId);view.SetWorksetVisibility(worksetId,WorksetVisibility.UseGlobalSetting);visibility=view.GetWorksetVisibility(worksetId);view.SetWorksetVisibility(worksetId,WorksetVisibility.Visible);©2013AutodeskFilteredWorksetCollectorcollector=newFilteredWorksetCollector(RevitDoc);collector.OfKind(WorksetKind.UserWorkset);IListWorksetworksets=collector.ToWorksets();WorksetKindFilterstandardFilter=newWorksetKindFilter(WorksetKind.StandardWorkset,true);collector.WherePasses(standardFilter);FilteredWorksetCollector和WorksetKindFilterFilteredWorksetCollector(RevitDoc);collector.OfKind(WorksetKind.UserWorkset);WorksetKindFilter(WorksetKind.StandardWorkset,true);©2013AutodeskElementWorksetFilterElementWorksetFilterelmentWorksetFilter=newElementWorksetFilter(worksetId,false);FilteredElementCollectorcollector=newFilteredElementCollector(RevitDoc);ICollectionElementworksetElemsfounds=collector.WherePasses(elmentWorksetFilter).ToElements();©2013AutodeskEnableWorksharingCheckoutElements和RelinquishOwnership工作共享权限管理©2013Autodesk开启工作共享RevitDoc.EnableWorksharing(abc,def);Assert.IsTrue(RevitDoc.IsWorkshared);©2013Autodesk获得编辑权限ICollectionElementIdcheckedOutElementIds=WorksharingUtils.CheckoutElements(RevitDoc,elementsToBeCheckedout);©2013Autodesk放弃编辑权限TransactWithCentralOptionstransOptions=newTransactWithCentralOptions();RelinquishOptionsrelinqOptions=newRelinquishOptions(false);relinqOptions.CheckedOutElements=true;relinqOptions.FamilyWorksets=false;relinqOptions.StandardWorksets=false;relinqOptions.UserWorksets=false;relinqOptions.ViewWorksets=false;//relinquishcheckedoutelementsRelinquishedItemsitems=WorksharingUtils.RelinquishOwnership(RevitDoc,relinqOptions,transOptions);©2013AutodeskWorksharingDisplayModeWorksharingDisplaySettingsWorksharingDisplayGraphicSettings工作共享的显示模式©2013AutodeskWorksharingDisplayModeWorksharingDisplayModewsDisplayMode=view.GetWorksharingDisplayMode();view.SetWorksharingDisplayMode(