public static string ImagePreviewFile(DwgBaseItem selectedItem, string baseFolder) { try { var imgFile = DwgBaseHelpers.FindImageFile(selectedItem, baseFolder); // Если файл есть if (!string.IsNullOrEmpty(imgFile)) { if (File.Exists(imgFile)) { return(imgFile); } return(CreateImageFile(selectedItem, baseFolder)); } return(CreateImageFile(selectedItem, baseFolder)); } catch (System.Exception exception) { ExceptionBox.Show(exception); } return(string.Empty); }
public static string FindImageFile(DwgBaseItem selectedItem, string baseFolder) { var file = string.Empty; var dwgFile = new FileInfo(Path.Combine(baseFolder, selectedItem.SourceFile)); if (Directory.Exists(dwgFile.DirectoryName)) { file = Path.Combine(dwgFile.DirectoryName, dwgFile.Name + " icons", selectedItem.BlockName + ".bmp"); if (File.Exists(file)) { return(file); } file = string.Empty; } return(file); }
private static string CreateImageFile(DwgBaseItem selectedItem, string baseFolder) { string file; var sourceDb = new Database(false, true); // Read the DWG into a side database sourceDb.ReadDwgFile(Path.Combine(baseFolder, selectedItem.SourceFile), FileOpenMode.OpenForReadAndAllShare, true, string.Empty); var dwgFile = new FileInfo(Path.Combine(baseFolder, selectedItem.SourceFile)); // ReSharper disable once AssignNullToNotNullAttribute var iconPath = Path.Combine(dwgFile.DirectoryName, $"{dwgFile.Name} icons"); using (var tr = sourceDb.TransactionManager.StartTransaction()) { var bt = (BlockTable)tr.GetObject(sourceDb.BlockTableId, OpenMode.ForRead); file = ExtractThumbnails(iconPath, tr, bt[selectedItem.BlockName]); tr.Commit(); } return(file); }
/// <summary> /// Добавление атрибутов для спецификации /// </summary> public static void AddAttributesForSpecification( Transaction tr, BlockReference blkRef, DwgBaseItem dwgBaseItem) { if (HasAttributesForSpecification(tr, blkRef.ObjectId)) { // update attributes foreach (ObjectId id in blkRef.AttributeCollection) { var attr = tr.GetObject(id, OpenMode.ForWrite) as AttributeReference; if (attr != null) { if (attr.Tag.ToLower().Equals("mp:позиция") || attr.Tag.ToLower().Equals("mp:position")) { attr.TextString = dwgBaseItem.PositionValue; } if (attr.Tag.ToLower().Equals("mp:обозначение") || attr.Tag.ToLower().Equals("mp:designation")) { attr.TextString = dwgBaseItem.DesignationValue; } if (attr.Tag.ToLower().Equals("mp:наименование") || attr.Tag.ToLower().Equals("mp:name")) { attr.TextString = dwgBaseItem.NominationValue; } if (attr.Tag.ToLower().Equals("mp:масса") || attr.Tag.ToLower().Equals("mp:mass")) { attr.TextString = dwgBaseItem.MassValue; } if (attr.Tag.ToLower().Equals("mp:примечание") || attr.Tag.ToLower().Equals("mp:note")) { attr.TextString = dwgBaseItem.NoteValue; } } } } else { // add attributes BlockTableRecord acBlkTblRec; if (blkRef.IsDynamicBlock) // get the real dynamic block name. { acBlkTblRec = tr.GetObject(blkRef.DynamicBlockTableRecord, OpenMode.ForWrite) as BlockTableRecord; } else { acBlkTblRec = tr.GetObject(blkRef.BlockTableRecord, OpenMode.ForWrite) as BlockTableRecord; } if (acBlkTblRec != null) { // blkName = acBlkTblRec.Name; var addAttrDefenitions = AddAttrDefinitions(acBlkTblRec, blkRef, tr); if (addAttrDefenitions.Any()) { foreach (ObjectId id in blkRef.AttributeCollection) { var attr = tr.GetObject(id, OpenMode.ForWrite) as AttributeReference; if (attr != null) { if (attr.Tag.ToLower().Equals("mp:позиция") || attr.Tag.ToLower().Equals("mp:position")) { attr.TextString = dwgBaseItem.PositionValue; } if (attr.Tag.ToLower().Equals("mp:обозначение") || attr.Tag.ToLower().Equals("mp:designation")) { attr.TextString = dwgBaseItem.DesignationValue; } if (attr.Tag.ToLower().Equals("mp:наименование") || attr.Tag.ToLower().Equals("mp:name")) { attr.TextString = dwgBaseItem.NominationValue; } if (attr.Tag.ToLower().Equals("mp:масса") || attr.Tag.ToLower().Equals("mp:mass")) { attr.TextString = dwgBaseItem.MassValue; } if (attr.Tag.ToLower().Equals("mp:примечание") || attr.Tag.ToLower().Equals("mp:note")) { attr.TextString = dwgBaseItem.NoteValue; } } } } } } }