public void CreateCloudHatch() { Excel.Shape cloudPart = null; Excel.Shape hatchArea = null; Excel.ShapeRange shapeRange = null; try { if (ErrorHandler.IsEnabled(true) == false) { return; } ErrorHandler.CreateLogRecord(); string shapeName = AssemblyInfo.Title.ToLower(); double x = Globals.ThisAddIn.Application.Selection.Left; double y = Globals.ThisAddIn.Application.Selection.Top; double h = Globals.ThisAddIn.Application.Selection.Height; double w = Globals.ThisAddIn.Application.Selection.Width; cloudPart = CreateCloudPart("ALL"); hatchArea = CreateHatchArea(x, y, h, w); if (cloudPart != null && hatchArea != null) { object[] shapes = { cloudPart.Name, hatchArea.Name }; shapeRange = Globals.ThisAddIn.Application.ActiveSheet.Shapes.Range(shapes); //.Group(); shapeRange.Group(); shapeRange.Name = shapeName + new string(' ', 1) + DateTime.Now.ToString(Properties.Settings.Default.Markup_ShapeDateFormat); Properties.Settings.Default.Markup_LastShapeName = shapeRange.Name; Marshal.FinalReleaseComObject(cloudPart); Marshal.FinalReleaseComObject(hatchArea); } } catch (Exception ex) { ErrorHandler.DisplayMessage(ex); } finally { if (cloudPart != null) { Marshal.ReleaseComObject(cloudPart); } if (hatchArea != null) { Marshal.ReleaseComObject(hatchArea); } if (shapeRange != null) { Marshal.ReleaseComObject(shapeRange); } } }
public Excel.Shape CreateCloudLine(double x1, double y1, double x2, double y2) { Excel.Shape cloudArc = null; Excel.Shape cloudLine = null; Excel.ShapeRange shapeRange = null; try { string shapeName = AssemblyInfo.Title.ToLower(); double length = Properties.Settings.Default.Markup_ShapeLineSpacing; int i = 0; double x = 0; double y = 0; double dx = x2 - x1; double dy = y2 - y1; double d = Math.Sqrt(dx * dx + dy * dy); double segments = Math.Ceiling(d / length); if (segments < 2) { segments = 2; } double deltax = (dx / segments); double deltay = (dy / segments); double xp = x1; double yp = y1; object[] shapes = new object[Convert.ToInt32(segments)]; for (i = 1; i <= Convert.ToInt32(segments); i++) { x = xp + deltax; y = yp + deltay; cloudArc = CreateArc(xp, yp, x, y, length); shapes[i - 1] = cloudArc.Name; xp = x; yp = y; } shapeRange = Globals.ThisAddIn.Application.ActiveSheet.Shapes.Range(shapes); //.Group(); shapeRange.Group(); shapeRange.Name = shapeName + new string(' ', 1) + DateTime.Now.ToString(Properties.Settings.Default.Markup_ShapeDateFormat) + LineNbr.ToString(); LineNbr += 1; cloudLine = Globals.ThisAddIn.Application.ActiveSheet.Shapes(shapeRange.Name); Properties.Settings.Default.Markup_LastShapeName = shapeRange.Name; return(cloudLine); } catch (Exception ex) { ErrorHandler.DisplayMessage(ex, true); return(null); } }
public Excel.Shape CreateHatchArea(double x, double y, double h, double w) { string shapeName = AssemblyInfo.Title.ToLower(); double length = Properties.Settings.Default.Markup_ShapeLineSpacing; double xx1 = 0; double yy1 = 0; double xx2 = 0; double yy2 = 0; double x1 = x + y; double x2 = Math.Floor(x1 / length); double x3 = (x2 + 1) * length; double xDiff = x3 - x1; double xl = x; double xr = x + w; double xw = w; double yt = y; double yb = y + h; double yw = h; double xsp = x + xDiff; double ysp = yt + xDiff; Excel.Shape hatchLine1 = null; Excel.Shape hatchLine2 = null; Excel.Shape hatchArea = null; Excel.ShapeRange shapeRange = null; List <object> shapesList = new List <object>(); try { if (xw >= yw) { while (xsp < xr + yw) { if (xsp - xl < yb - yt) { xx1 = xsp; yy1 = yt; xx2 = xl; yy2 = yt + (xx1 - xl); } else { if (xsp <= xr) { xx1 = xsp; yy1 = yt; xx2 = xx1 - yw; yy2 = yb; } else { xx2 = xsp - yw; yy2 = yb; xx1 = xr; yy1 = yb - (xr - xx2); } } hatchLine1 = Globals.ThisAddIn.Application.ActiveSheet.Shapes.AddLine(Convert.ToSingle(xx1), Convert.ToSingle(yy1), Convert.ToSingle(xx2), Convert.ToSingle(yy2)); hatchLine1.Select(); hatchLine1.Name = shapeName + new string(' ', 1) + DateTime.Now.ToString(Properties.Settings.Default.Markup_ShapeDateFormat) + LineNbr.ToString(); shapesList.Add(hatchLine1.Name); SetLineColor(); xsp = xsp + length; LineNbr += 1; } } else { while (ysp < yb + xw) { if (ysp - yt < xw) { xx2 = xl; yy2 = ysp; xx1 = xl + (yy2 - yt); yy1 = yt; } else { if (ysp <= yb) { xx2 = xl; yy2 = ysp; xx1 = xr; yy1 = yy2 - xw; } else { xx1 = xr; xx2 = xl + (ysp - yb); yy2 = yb; yy1 = yb - (xr - xx2); } } hatchLine2 = Globals.ThisAddIn.Application.ActiveSheet.Shapes.AddLine(Convert.ToSingle(xx1), Convert.ToSingle(yy1), Convert.ToSingle(xx2), Convert.ToSingle(yy2)); hatchLine2.Select(); hatchLine2.Name = shapeName + new string(' ', 1) + DateTime.Now.ToString(Properties.Settings.Default.Markup_ShapeDateFormat) + LineNbr.ToString(); shapesList.Add(hatchLine2.Name); SetLineColor(); ysp = ysp + length; LineNbr += 1; } } object[] shapes = shapesList.ToArray(); shapeRange = Globals.ThisAddIn.Application.ActiveSheet.Shapes.Range(shapes); shapeRange.Group(); shapeRange.Name = shapeName + new string(' ', 1) + DateTime.Now.ToString(Properties.Settings.Default.Markup_ShapeDateFormat); hatchArea = Globals.ThisAddIn.Application.ActiveSheet.Shapes(shapeRange.Name); Properties.Settings.Default.Markup_LastShapeName = shapeRange.Name; return(hatchArea); } catch (System.Runtime.InteropServices.COMException ex) { ErrorHandler.DisplayMessage(ex, true); return(null); } catch (Exception ex) { ErrorHandler.DisplayMessage(ex, true); return(null); } finally { if (shapeRange != null) { Marshal.FinalReleaseComObject(shapeRange); } if (hatchLine1 != null) { Marshal.FinalReleaseComObject(hatchLine1); } if (hatchLine2 != null) { Marshal.FinalReleaseComObject(hatchLine2); } } }
public Excel.Shape CreateCloudPart(string cloudPart) { if (ErrorHandler.IsEnabled(true) == false) { return(null); } Excel.Shape cloudLineBottom = null; Excel.Shape cloudLineTop = null; Excel.Shape cloudLineLeft = null; Excel.Shape cloudLineRight = null; Excel.Shape cloudLine = null; Excel.ShapeRange shapeRange = null; try { double x = Globals.ThisAddIn.Application.Selection.Left; double y = Globals.ThisAddIn.Application.Selection.Top; double h = Globals.ThisAddIn.Application.Selection.Height; double w = Globals.ThisAddIn.Application.Selection.Width; if (cloudPart == "B" | cloudPart == "ALL") { cloudLineBottom = CreateCloudLine(x, y + h, x + w, y + h); } if (cloudPart == "T" | cloudPart == "ALL") { cloudLineTop = CreateCloudLine(x + w, y, x, y); } if (cloudPart == "L" | cloudPart == "ALL") { cloudLineLeft = CreateCloudLine(x, y, x, y + h); } if (cloudPart == "R" | cloudPart == "ALL") { cloudLineRight = CreateCloudLine(x + w, y + h, x + w, y); } if (cloudPart == "ALL" && cloudLineBottom != null && cloudLineTop != null && cloudLineLeft != null && cloudLineRight != null) { string shapeName = AssemblyInfo.Title.ToLower(); object[] shapes = { cloudLineBottom.Name, cloudLineTop.Name, cloudLineLeft.Name, cloudLineRight.Name }; shapeRange = Globals.ThisAddIn.Application.ActiveSheet.Shapes.Range(shapes); //.Group(); shapeRange.Group(); shapeRange.Name = shapeName + new string(' ', 1) + DateTime.Now.ToString(Properties.Settings.Default.Markup_ShapeDateFormat); cloudLine = Globals.ThisAddIn.Application.ActiveSheet.Shapes(shapeRange.Name); Properties.Settings.Default.Markup_LastShapeName = shapeRange.Name; return(cloudLine); } else { return(null); } } catch (Exception ex) { ErrorHandler.DisplayMessage(ex); return(null); } finally { if (cloudLineBottom != null) { Marshal.ReleaseComObject(cloudLineBottom); } if (cloudLineTop != null) { Marshal.ReleaseComObject(cloudLineTop); } if (cloudLineLeft != null) { Marshal.ReleaseComObject(cloudLineLeft); } if (cloudLineRight != null) { Marshal.ReleaseComObject(cloudLineRight); } if (cloudLine != null) { Marshal.ReleaseComObject(cloudLine); } if (shapeRange != null) { Marshal.ReleaseComObject(shapeRange); } } }
public void CreateCloudHold() { Excel.Shape cloudLineTop = null; Excel.Shape cloudLineRight = null; Excel.Shape cloudLineBottom = null; Excel.Shape cloudLineLeft = null; Excel.ShapeRange shapeRange = null; try { if (ErrorHandler.IsEnabled(true) == false) { return; } ErrorHandler.CreateLogRecord(); string shapeName = AssemblyInfo.Title.ToLower(); double x = Globals.ThisAddIn.Application.Selection.Left; double y = Globals.ThisAddIn.Application.Selection.Top; double h = Globals.ThisAddIn.Application.Selection.Height; double w = Globals.ThisAddIn.Application.Selection.Width; double off = 7.5; x = x - off / 2; w = w + off; y = y - off / 2; h = h + off; cloudLineTop = CreateCloudLine(x, y, x + w, y); cloudLineRight = CreateCloudLine(x + w, y, x + w, y + h); cloudLineBottom = CreateCloudLine(x + w, y + h, x, y + h); cloudLineLeft = CreateCloudLine(x, y + h, x, y); if (cloudLineBottom != null && cloudLineTop != null && cloudLineLeft != null && cloudLineRight != null) // only if there are no errors in returning an Excel shape { object[] shapes = { cloudLineBottom.Name, cloudLineTop.Name, cloudLineLeft.Name, cloudLineRight.Name }; shapeRange = Globals.ThisAddIn.Application.ActiveSheet.Shapes.Range(shapes); shapeRange.Group(); shapeRange.Name = shapeName + new string(' ', 1) + DateTime.Now.ToString(Properties.Settings.Default.Markup_ShapeDateFormat); Properties.Settings.Default.Markup_LastShapeName = shapeRange.Name; } } catch (Exception ex) { ErrorHandler.DisplayMessage(ex); } finally { if (cloudLineTop != null) { Marshal.ReleaseComObject(cloudLineTop); } if (cloudLineRight != null) { Marshal.ReleaseComObject(cloudLineRight); } if (cloudLineBottom != null) { Marshal.ReleaseComObject(cloudLineBottom); } if (cloudLineLeft != null) { Marshal.ReleaseComObject(cloudLineLeft); } if (shapeRange != null) { Marshal.ReleaseComObject(shapeRange); } } }
public void CreateRevisionTriangle() { Excel.Shape shpTriangle = null; Excel.Shape txtTriangle = null; Excel.ShapeRange shapeRange = null; try { if (ErrorHandler.IsEnabled(true) == false) { return; } ErrorHandler.CreateLogRecord(); string shapeName = AssemblyInfo.Title.ToLower(); Single[,] triArray = new Single[4, 2]; double x = 0; double y = Globals.ThisAddIn.Application.Selection.Top; double h = Globals.ThisAddIn.Application.Selection.RowHeight; double w = Convert.ToInt32(h * 2.2 / Math.Sqrt(3)); double f = Globals.ThisAddIn.Application.Selection.Font.Size; double selWidth = Globals.ThisAddIn.Application.Selection.Width; double selLeft = Globals.ThisAddIn.Application.Selection.Left; double selHorAli = Globals.ThisAddIn.Application.Selection.HorizontalAlignment; double xlAliCntr = Convert.ToDouble(Excel.XlHAlign.xlHAlignCenter); if (selHorAli == xlAliCntr & selWidth > w) { x = selLeft + (selWidth - w) / 2; } else { x = selLeft; } triArray[0, 0] = Convert.ToSingle(x + w / 2); triArray[0, 1] = Convert.ToSingle(y); triArray[1, 0] = Convert.ToSingle(x); triArray[1, 1] = Convert.ToSingle(y + h); triArray[2, 0] = Convert.ToSingle(x + w); triArray[2, 1] = Convert.ToSingle(y + h); triArray[3, 0] = Convert.ToSingle(x + w / 2); triArray[3, 1] = Convert.ToSingle(y); shpTriangle = Globals.ThisAddIn.Application.ActiveSheet.Shapes.AddPolyline(triArray); shpTriangle.Name = shapeName + new string(' ', 1) + DateTime.Now.ToString(Properties.Settings.Default.Markup_ShapeDateFormat) + "1"; shpTriangle.Line.Weight = Convert.ToSingle(1.5); //add a textbox to the triangle txtTriangle = Globals.ThisAddIn.Application.ActiveSheet.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, Convert.ToSingle(x), Convert.ToSingle(y + h * 0.2), Convert.ToSingle(w), Convert.ToSingle(h * 0.8)); txtTriangle.Select(); txtTriangle.TextEffect.Text = Properties.Settings.Default.Markup_TriangleRevisionCharacter; Globals.ThisAddIn.Application.Selection.Font.Color = Properties.Settings.Default.Markup_ShapeLineColor; Globals.ThisAddIn.Application.Selection.Font.Size = f; Globals.ThisAddIn.Application.Selection.Border.LineStyle = Excel.Constants.xlNone; Globals.ThisAddIn.Application.Selection.Interior.ColorIndex = Excel.Constants.xlNone; Globals.ThisAddIn.Application.Selection.Shadow = false; Globals.ThisAddIn.Application.Selection.RoundedCorners = false; txtTriangle.TextFrame.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter; txtTriangle.TextFrame.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter; txtTriangle.TextFrame.AutoSize = true; txtTriangle.Name = shapeName + new string(' ', 1) + DateTime.Now.ToString(Properties.Settings.Default.Markup_ShapeDateFormat) + "2"; //group both shapes together object[] shapes = { shpTriangle.Name, txtTriangle.Name }; shapeRange = Globals.ThisAddIn.Application.ActiveSheet.Shapes.Range(shapes); shapeRange.Group(); shapeRange.Name = shapeName + new string(' ', 1) + DateTime.Now.ToString(Properties.Settings.Default.Markup_ShapeDateFormat) + "3"; shpTriangle.Select(); Globals.ThisAddIn.Application.Selection.Interior.Pattern = Excel.XlPattern.xlPatternNone; SetLineColor(); Globals.ThisAddIn.Application.ActiveCell.Select(); Properties.Settings.Default.Markup_LastShapeName = shapeRange.Name; } catch (Exception ex) { ErrorHandler.DisplayMessage(ex); } finally { if (shapeRange != null) { Marshal.ReleaseComObject(shapeRange); } if (txtTriangle != null) { Marshal.ReleaseComObject(txtTriangle); } if (shpTriangle != null) { Marshal.ReleaseComObject(shpTriangle); } } }