//[Command] //public void Test() //{ // string activeDgnFileName = Program.GetActiveDgnFile().GetFileName(); // List<string> dgnFileNameList = new List<string> {activeDgnFileName}; // GetAttachmentsDgnFiles(ref dgnFileNameList, activeDgnFileName); //} private void GetLevelInfo(ref List <LevelInfo> levelInfos, string inDgnFileName) { BD.DgnDocument inDgnDocument = BD.DgnDocument.CreateForLocalFile(inDgnFileName); BD.DgnFile inDgnFile = BD.DgnFile.Create(inDgnDocument, BD.DgnFileOpenMode.ReadOnly).DgnFile; BD.StatusInt openFileStatusInt; if (BD.DgnFileStatus.Success != inDgnFile.LoadDgnFile(out openFileStatusInt)) { return; } if (BD.StatusInt.Success != inDgnFile.FillDictionaryModel()) { return; } string inDgnFileNameWithoutExt = Path.GetFileNameWithoutExtension(inDgnFile.GetFileName()); var fileLevelCache = inDgnFile.GetLevelCache(); var handles = fileLevelCache.GetHandles(); foreach (var handle in handles) { if (IsOnlyUsedLevel && !fileLevelCache.IsLevelUsedInFile(handle.LevelId)) { continue; } uint colorint = handle.GetByLevelColor().Color; BD.ColorInformation colorInformation = BD.DgnColorMap.ExtractElementColorInfo(colorint, handle.GetByLevelColor().GetDefinitionFile()); levelInfos.Add(new LevelInfo { DgnFileName = inDgnFileNameWithoutExt, LevelName = handle.Name, LevelColor = colorInformation.ColorDefinition.SystemColor }); } }
public void OpenCellLib() { OpenFileDialogService.Filter = "Cell Library (.cell)|*.cel|Dgn File(.dng)|*.dgn|All Files (*.*)|*.*"; OpenFileDialogService.Title = "选择Cell库文件"; string defaultDirec = string.Empty; #if DEBUG defaultDirec = @"D:\项目\BIM实习\梅山二期\建模中间文件\码头\celllib"; #endif bool DialogResult = OpenFileDialogService.ShowDialog(defaultDirec); if (DialogResult) { IntPtr filep; if (0 == PDIWT_MS.Marshal.BentleyMarshal.mdlCell_getLibraryObject(out filep, OpenFileDialogService.GetFullFileName(), true)) { CellLibPath = OpenFileDialogService.GetFullFileName(); BD.DgnFile dgnFile = BD.DgnFile.GetDgnFile(filep); int modelNum = 0; foreach (var index in dgnFile.GetModelIndexCollection()) { if (index.CellPlacementOptions == Bentley.DgnPlatformNET.CellPlacementOptions.CanBePlacedAsCell) { CellNameList.Add(new CellName { Name = index.Name, Id = modelNum++ }); } } PDIWT_MS.Program.COM_App.AttachCellLibrary(OpenFileDialogService.File.GetFullName()); } } }
public void OpenCellLib() { OpenFileDialog cellFileDialog = new OpenFileDialog() { Filter = Resources.CellLibraryFilter, Title = "选择Cell库文件" }; if (cellFileDialog.ShowDialog() == DialogResult.OK) { BD.DgnDocument cellFileDocument = BD.DgnDocument.CreateForLocalFile(cellFileDialog.FileName); BD.DgnFile cellDgnFile = BD.DgnFile.Create(cellFileDocument, BD.DgnFileOpenMode.ReadOnly).DgnFile; if (cellDgnFile == null) { Prompt = Resources.PromptHeader + $"无法读取{cellFileDialog.FileName}的DgnDocument对象"; Status = Resources.StatusHeader + Resources.ErrorString; return; } BD.StatusInt loadStatusInt; if (BD.DgnFileStatus.Success != cellDgnFile.LoadDgnFile(out loadStatusInt)) { Prompt = Resources.PromptHeader + "无法载入文件"; Status = Resources.StatusHeader + Resources.ErrorString; return; } if (cellDgnFile.FillDictionaryModel() != BD.StatusInt.Success) { Prompt = Resources.PromptHeader + "填充模型失败"; Status = Resources.StatusHeader + Resources.ErrorString; return; } CellNameTypes.Clear(); ElementProps.Clear(); int index = 0; foreach (var modelindex in cellDgnFile.GetModelIndexCollection()) { BD.DgnModel model = cellDgnFile.LoadRootModelById(out loadStatusInt, modelindex.Id); if (model != null && modelindex.CellPlacementOptions == BD.CellPlacementOptions.CanBePlacedAsCell) { CellNameTypes.Add(model.ModelName + "(" + model.GetModelInfo().CellType.ToString() + ")"); index++; } } string filename; if (CellFunction.AttachLibrary(out filename, cellFileDialog.FileName, "") != BD.StatusInt.Success) { Prompt = Resources.PromptHeader + "附加模型失败"; Status = Resources.StatusHeader + Resources.ErrorString; return; } Prompt = Resources.PromptHeader + $"{cellFileDialog.SafeFileName}已载入!"; Status = Resources.StatusHeader + Resources.SuccessString; } }
private void GetAttachmentsDgnFiles(ref List <string> dgnFileNameList, string inDgnFileName) { BD.DgnDocument inDgnDocument = BD.DgnDocument.CreateForLocalFile(inDgnFileName); BD.DgnFile inDgnFile = BD.DgnFile.Create(inDgnDocument, BD.DgnFileOpenMode.ReadOnly).DgnFile; BD.StatusInt openFileStatusInt; if (BD.DgnFileStatus.Success != inDgnFile.LoadDgnFile(out openFileStatusInt)) { return; } if (BD.StatusInt.Success != inDgnFile.FillDictionaryModel()) { return; } var dgnModelIndexs = inDgnFile.GetModelIndexCollection(); foreach (var dgnModelIndex in dgnModelIndexs) { BD.StatusInt loadModelStatusInt; var dgnModel = inDgnFile.LoadRootModelById(out loadModelStatusInt, dgnModelIndex.Id); if (BD.StatusInt.Success != loadModelStatusInt) { continue; } var dgnAttachmentList = dgnModel.GetDgnAttachments(); foreach (var dgnAttachment in dgnAttachmentList) { if (dgnAttachment.IsMissingFile || dgnAttachment.IsMissingModel) { continue; } var attachedDgnFileName = dgnAttachment.GetAttachFullFileSpec(true); if (!dgnFileNameList.Contains(attachedDgnFileName)) { dgnFileNameList.Add(attachedDgnFileName); } else { return; } if (attachedDgnFileName != null) { GetAttachmentsDgnFiles(ref dgnFileNameList, attachedDgnFileName); } } } }
//public static void TestSharedCell() //{ // BCOM.Application app = BM.InteropServices.Utilities.ComApp; // BM.MSDocumentManager msdm = BM.MSDocumentManager.Manager; // BM.MSDocumentOpenDialogParams msodp = new BM.MSDocumentOpenDialogParams(); // msodp.SetDialogTitle("载入CellLibrary"); // msodp.SetDefaultFilter("*.cel"); // BD.DgnDocument dgndoc = msdm.OpenDocumentDialog(msodp, BM.FileListAttr.Default, BD.DgnDocument.FetchMode.Read); // if (null != dgndoc) // { // app.AttachCellLibrary(dgndoc.FileName); // //BCOM.Point3d p = app.Point3dZero(); // //BCOM.SharedCellElement sharedcell = app.CreateSharedCellElement3("JD1", ref p, true); // BD.Elements.SharedCellElement sharecell = new BD.Elements.SharedCellElement(BM.Session.Instance.GetActiveDgnModel(), null, "JD1", BG.DPoint3d.Zero, BG.DMatrix3d.Identity, BG.DPoint3d.FromXYZ(1, 1, 1)); // System.Windows.MessageBox.Show($"CellName:{sharecell.CellName}\n"); // } //} public static void TestLibObj() { //var p = Program.GetActiveDgnFile().GetLoadedModelsCollection(); IntPtr filep; uint i = PDIWT_MS.Marshal.BentleyMarshal.mdlCell_getLibraryObject(out filep, @"D:\项目\BIM实习\梅山二期\建模中间文件\码头\celllib\节点库.cel", true); BD.DgnFile dgnFile = BD.DgnFile.GetDgnFile(filep); string name = string.Empty; foreach (var index in dgnFile.GetModelIndexCollection()) { if (index.CellPlacementOptions == Bentley.DgnPlatformNET.CellPlacementOptions.CanBePlacedAsCell) { name += " " + index.Name + "\n"; } } System.Windows.MessageBox.Show(name); }
protected override void OnInitializeInRuntime() { var alllevel = new ObservableCollection <BD.LevelHandle>(); BD.DgnFile activefile = Program.GetActiveDgnFile(); BD.FileLevelCache flevel = activefile.GetLevelCache(); foreach (var levelhandle in flevel.GetHandles()) { alllevel.Add(levelhandle); } AllDgnLevels = alllevel; //PileCrossSectionTypes = new Dictionary<string, PileCrossSectionType> //{ // {"圆形截面桩", PileCrossSectionType.Roundness }, // {"方形截面桩", PileCrossSectionType.Square }, // {"环形截面桩", PileCrossSectionType.Annular } //}; SelectedPileCrossSectionType = SoildPileCrossSectionType.Square; SelectedPileType = PileType.Solid; Eta = 1; PileWeight = 25; PileUnderwaterWeight = 15; }