S3D 模型对象权限检查

效果展示:

image

image

代码如下

 

 public class CheckPG : BaseModalCommand
 {
     public override void OnStart(int instanceId, object argument)
     {
         base.OnStart(instanceId, argument);
         if (ClientServiceProvider.SelectSet.Count == 0)
         {
             System.Windows.Forms.MessageBox.Show("请选择对象");
             return;
         }
         var ss = ClientServiceProvider.SelectSet.SelectedObjects.FirstOrDefault();
         var ft = new Filter();
         ft.Definition.AddHierarchy(ss is ISystem ? HierarchyTypes.System : HierarchyTypes.Assembly, new System.Collections.ObjectModel.ReadOnlyCollection<BusinessObject>(new BusinessObject[] { ss }), true);
         var objs = ClientServiceProvider.WorkingSet.GetObjectsByFilter(ft, ClientServiceProvider.WorkingSet.ActiveConnection);
         var fn = $"C:\\{(ss is ISystem ? HierarchyTypes.System.ToString() : HierarchyTypes.Assembly.ToString())} Objects Under {ss.GetName()}-{NsAPI.CommonTools.DateTimeStamp}.xlsx";
         FileInfo newFile = new FileInfo(fn);
         if (newFile.Exists)
         {
             newFile.Delete(); // ensures we create a new workbook
             newFile = new FileInfo(fn);
         }
         using (OfficeOpenXml.ExcelPackage package = new OfficeOpenXml.ExcelPackage(newFile))
         {
             var ws = package.Workbook.Worksheets.Add("Sheet1");
             var listObjects = new List<ObjectInfo>();
             foreach (var item in objs)
             {
                 try
                 {
                     listObjects.Add(new ObjectInfo(item));
                 }
                 catch (System.Exception)
                 {
                     continue;
                 }
             }
             ws.Cells[1, 1].LoadFromCollection(listObjects, true);
             ws.Cells.AutoFitColumns();
             package.Save();
             package.Dispose();
         }
         Process.Start(fn);
     }
 }

 

  public class ObjectInfo
  {
      public string ClassName { get; set; }
      public string PGName { get; set; }
      public string PGLocation { get; set; }
      public string BOCDisPlayName { get; set; }
      public string BOCPath { get; set; }
      public string BOCName { get; set; }
      public string ObjectID { get; set; }
      public string Name { get; set; }
      public string UserCreated { get; set; }
      public string UserLastModified { get; set; }
      public string DateCreated { get; set; }
      public string DateLastModified { get; set; }

      public ObjectInfo(BusinessObject curObj)
      {
          ClassName = curObj.ClassInfo.IsUserClass ? curObj.UserClassInfo.DisplayName : curObj.ClassInfo.DisplayName;
          PGName = curObj.PermissionGroup.Name;
          PGLocation = curObj.PermissionGroup.PGLocation.ToString();
          var bocInfo = ((curObj.UserClassInfo != null) ? curObj.UserClassInfo : curObj.ClassInfo).BOC;
          BOCDisPlayName = bocInfo.DisplayName;
          BOCPath = bocInfo.BOCPath;
          BOCName = bocInfo.Name;
          ObjectID = curObj.ObjectID;
          Name = curObj.ToString();
          UserCreated = curObj.UserCreated;
          UserLastModified = curObj.UserLastModified;
          DateCreated = curObj.DateCreated.ToString();
          DateLastModified = curObj.DateLastModified.ToString();
      }

  }

 

posted @ 2025-11-09 11:19  南胜NanSheng  阅读(5)  评论(0)    收藏  举报