private void DatabaseToBlock(BlockReference block, Transaction tr) { try { Dictionary <string, AttributeReference> attribs = GetBlockAttributes(block, tr); DrawingsDataContext dc = DBCommon.NewDC; Drawing drawing = GetDrawing(dc, attribs["DRAWING-NUMBER"].TextString, attribs["SHEET"].TextString); if (drawing == null) { _ed.WriteMessage("Drawing was not found, check Drawing Number AND Sheet Number are correct \n"); return; } foreach (var kvp in attribs) { if (DrawingHelper.AttributeExists(kvp.Key)) //only save the desired attributes { kvp.Value.TextString = drawing.GetAttribute(kvp.Key); } } SetBlockSheetSize(block, drawing.SheetSize, tr); _ed.WriteMessage("Data successfully fetched from the database and put in block " + block.Name + "\n"); } catch (Exception ex) { _ed.WriteMessage("Exception at DatabaseToBlock(block, tr): " + ex.Message + ex.StackTrace + "\n"); } }
private bool BlockToDatabase(BlockReference block, Transaction tr) { try { Dictionary <string, AttributeReference> attribs = GetBlockAttributes(block, tr); if (String.IsNullOrEmpty(attribs["DRAWING-NUMBER"].TextString)) { PromptResult pr1 = _ed.GetString("Drawing Number:"); attribs["DRAWING-NUMBER"].TextString = pr1.StringResult; } if (String.IsNullOrEmpty(attribs["SHEET"].TextString)) { PromptResult pr1 = _ed.GetString("Sheet Number:"); attribs["SHEET"].TextString = pr1.StringResult; } if (String.IsNullOrEmpty(attribs["DRAWING-NUMBER"].TextString) || String.IsNullOrEmpty(attribs["SHEET"].TextString)) { _ed.WriteMessage("No drawing/sheet number forthcoming, returning.\n"); return(false); } DrawingsDataContext dc = DBCommon.NewDC; Drawing drawing = GetDrawing(dc, attribs["DRAWING-NUMBER"].TextString, attribs["SHEET"].TextString); if (drawing == null) { drawing = new Drawing(); dc.Drawings.InsertOnSubmit(drawing); } foreach (var kvp in attribs) { if (DrawingHelper.AttributeExists(kvp.Key)) //only save the desired attributes { drawing.SetAttribute(kvp.Key, kvp.Value.TextString); } } drawing.SheetSize = GetSheetSizeFromBlock(block, tr); //TODO: check this if (_db.Filename.EndsWith("sv$", StringComparison.OrdinalIgnoreCase)) { _ed.WriteMessage("File has not been saved since autosave, filename not put into the database.\n"); } else { drawing.FileName = _db.Filename; //drawing.Filename = _db.OriginalFileName; } //If we're putting this in via the CAD, then it must be electronic drawing.Electronic = true; dc.SubmitChanges(); if (drawing.Category == DrawingCategory.Undefined) { _ed.WriteMessage("WARNING: Drawing Category is undefined!\n"); } if (drawing.Status == DrawingStatus.Undefined) { _ed.WriteMessage("WARNING: Drawing Status is undefined!\n"); } _ed.WriteMessage("Data successfully written to the database from block " + block.Name + "\n"); return(true); } catch (Exception ex) { _ed.WriteMessage(ex.Message); return(false); } }