protected void ResetRectangle() { if (_mouseEvents != null) { _mouseEvents.OnMouseMove -= _onMouseMove_Delegate; _onMouseMove_Delegate = null; _mouseEvents.OnMouseClick -= _onMouseClick_Delegate; _onMouseClick_Delegate = null; _mouseEvents = null; } _rectangleLines = null; _horizontalMidPointAlign = null; _verticalMidPointAlign = null; _userInputEvents.OnContextMenu -= _userInputEvents_OnContextMenuDelegate; _userInputEvents_OnContextMenuDelegate = null; _planarSketch = null; _drawingSketch = null; _secondSelectedSketchEntity = null; _inferredOriginPoint = null; _inferredFinalPositionPoint = null; _firstSelectedSketchEntity = null; _pickedPoint2d = null; _pickedSketchPoint = null; _rectangleOriginSketchPoint = null; _rectangleCoordSet = null; _rectanglePointCoords = null; _rectangleInteractionGraphics = null; _rectangleGraphicsColorSet = null; _interactionEvents.OnTerminate -= _onTerminate_Delegate; _interactionEvents.Stop(); _interactionEvents = null; }
public InventorPlotter(DrawingSketch sketch) { this.sketch = sketch; this.app = (Application)sketch.Application; this.transGeom = this.app.TransientGeometry; this.yArrays = new List <float[]>(); this.initX = 0; this.initY = 0; this.length = 9; this.height = 6; this.xConverter = x => string.Format("{0:0}", x); this.yConverter = y => string.Format("{0:0}", y); colors = new List <Color>(); xlimManual = false; ylimManual = false; }
private static void createDrawing(Inventor.Application _invApp, string inputExcelData, string template) { try { Console.WriteLine("Inventor captured"); System.Threading.Thread.Sleep(5000); DrawingDocument idwDoc = _invApp.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, template, true) as DrawingDocument; Sheet sheet = idwDoc.ActiveSheet; DrawingSketch sketch = null; TransientGeometry tg = _invApp.TransientGeometry; if (sheet.Sketches.Count > 0) { sketch = sheet.Sketches[1]; } else { sketch = sheet.Sketches.Add(); } DataTable inputData = GetDataTableFromExcel(inputExcelData, true); bool fileCreated = false; foreach (DataRow iRow in inputData.Rows) { if (iRow.ItemArray[0].ToString().ToLower() == "rectangle") { fileCreated = CreateRectangle(iRow, sheet, sketch, tg); } else if (iRow.ItemArray[0].ToString().ToLower() == "circle") { fileCreated = CreateCircle(iRow, sheet, sketch, tg); } } Console.WriteLine(sheet.Height); Console.WriteLine(sheet.Width); string dir = System.IO.Path.GetDirectoryName(inputExcelData); string resultPath = System.IO.Path.Combine(dir, "ToolTestResult.dwg"); idwDoc.SaveAsInventorDWG(resultPath, true); MessageBox.Show("Drawing successfully created!"); } catch (Exception e) { Console.WriteLine(e.Message); } }
private static bool CreateCircle(DataRow iRow, Sheet iSheet, DrawingSketch iSketch, TransientGeometry tg) { bool isCircleCreated = false; try { int circleInst = Int32.Parse(iRow.ItemArray[iRow.ItemArray.Count() - 1].ToString()); int startNum = 0; string tempCoord = iRow.ItemArray[4].ToString(); string[] coord = tempCoord.Split(','); Double initX = Double.Parse(coord[0]); Double initY = Double.Parse(coord[1]); Double hOffset = Double.Parse(iRow.ItemArray[5].ToString()); Double vOffset = Double.Parse(iRow.ItemArray[6].ToString()); Double radius = Double.Parse(iRow.ItemArray[3].ToString()) / 2; do { iSketch.Edit(); Point2d cen; if (startNum < circleInst / 2) { cen = tg.CreatePoint2d(initX + (hOffset * startNum), initY); } else { cen = tg.CreatePoint2d(initX + (hOffset * (startNum - 4)), initY + vOffset); } SketchCircle iCircle = iSketch.SketchCircles.AddByCenterRadius(cen, 2); GeometryIntent oGeo1 = iSheet.CreateGeometryIntent(iCircle, null); iSketch.ExitEdit(); iSheet.DrawingDimensions.GeneralDimensions.AddDiameter(cen, oGeo1, false, false, false); isCircleCreated = true; startNum += 1; } while (startNum < circleInst); } catch (Exception e) { Console.WriteLine(e.Message); } return(isCircleCreated); }
//To execute this command, a drawing document with a view need to be available private void Border2_Click(object sender, EventArgs e) { DrawingDocument oDrawDoc = mApp.ActiveDocument as DrawingDocument; TransientGeometry oTG = mApp.TransientGeometry; //Create the new border definition BorderDefinition oBorderDef = oDrawDoc.BorderDefinitions.Add("Sample Border"); //Open the border definition's sketch for edit. This is done by calling the Edit // method of the BorderDefinition to obtain a DrawingSketch. This actually creates // a copy of the border definition's and opens it for edit. DrawingSketch oSketch = null; oBorderDef.Edit(out oSketch); //Use the functionality of the sketch to add geometry oSketch.SketchLines.AddAsTwoPointRectangle(oTG.CreatePoint2d(2, 2), oTG.CreatePoint2d(25.94, 19.59)); oBorderDef.ExitEdit(true, ""); }
public void CreateSketch() { DrawingDocument oDoc = (DrawingDocument)_InvApplication.ActiveDocument; Sheet oSheet = default(Sheet); oSheet = oDoc.ActiveSheet; // Create the sketch. DrawingSketch oSketch = default(DrawingSketch); oSketch = oSheet.Sketches.Add(); // Open the sketch for edit in the user interface. oSketch.Edit(); oSketch.SketchCircles.AddByCenterRadius(_InvApplication.TransientGeometry.CreatePoint2d(8, 8), 2); // Exit edit. oSketch.ExitEdit(); }
//creating a new sketched symbol definition object and // inserting it into the active sheet. // This sample consists of two subs. // The first demonstrates the creation of a sketched symbol definition and // the second inserts it into the active sheet. // To run the sample have a drawing document open and run the CreateSketchedSymbolDefinition Sub. // After this you can run the InsertSketchedSymbolOnSheet to insert the sketched symbol into the active sheet. // The insertion sub demonstrates the use of the insertion point in the symbol's definition while inserting the symbol. /// <summary> /// creating a new sketched symbol definition object ''' /// </summary> /// <remarks></remarks> public void CreateSketchedSymbolDefinition() { // Set a reference to the drawing document. // This assumes a drawing document is active. DrawingDocument oDrawDoc = (DrawingDocument)_InvApplication.ActiveDocument; // Create the new sketched symbol definition. SketchedSymbolDefinition oSketchedSymbolDef = oDrawDoc.SketchedSymbolDefinitions.Add("Circular Callout"); // Open the sketched symbol definition's sketch for edit. This is done by calling the Edit // method of the SketchedSymbolDefinition to obtain a DrawingSketch. This actually creates // a copy of the sketched symbol definition's and opens it for edit. DrawingSketch oSketch = null; oSketchedSymbolDef.Edit(out oSketch); TransientGeometry oTG = _InvApplication.TransientGeometry; // Use the functionality of the sketch to add sketched symbol graphics. SketchLine oSketchLine = oSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(0, 0), oTG.CreatePoint2d(20, 0)); SketchCircle oSketchCircle = oSketch.SketchCircles.AddByCenterRadius(oTG.CreatePoint2d(22, 0), 2); oSketch.GeometricConstraints.AddCoincident((SketchEntity)oSketchLine.EndSketchPoint, (SketchEntity)oSketchCircle); // Make the starting point of the sketch line the insertion point oSketchLine.StartSketchPoint.InsertionPoint = true; // Add a prompted text field at the center of the sketch circle. string sText = null; sText = "<Prompt>Enter text 1</Prompt>"; Inventor.TextBox oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(22, 0), sText); oTextBox.VerticalJustification = VerticalTextAlignmentEnum.kAlignTextMiddle; oTextBox.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter; oSketchedSymbolDef.ExitEdit(true); }
private static bool CreateRectangle(DataRow iRow, Sheet iSheet, DrawingSketch iSketch, TransientGeometry tg) { bool isRectangleCreated = false; try { string tempCoord = iRow.ItemArray[4].ToString(); string[] coord = tempCoord.Split(','); Double initX = Double.Parse(coord[0]); Double initY = Double.Parse(coord[1]); Double height = Double.Parse(iRow.ItemArray[1].ToString()); Double width = Double.Parse(iRow.ItemArray[2].ToString()); iSketch.Edit(); Point2d pt1 = tg.CreatePoint2d(initX, initY); Point2d pt2 = tg.CreatePoint2d(initX + width, initY); Point2d pt3 = tg.CreatePoint2d(initX + width, initY + height); Point2d pt4 = tg.CreatePoint2d(initX, initY + height); SketchLine l1 = iSketch.SketchLines.AddByTwoPoints(pt1, pt2); SketchLine l2 = iSketch.SketchLines.AddByTwoPoints(pt2, pt3); iSketch.SketchLines.AddByTwoPoints(pt3, pt4); iSketch.SketchLines.AddByTwoPoints(pt4, pt1); iSketch.ExitEdit(); GeometryIntent oGeo1 = iSheet.CreateGeometryIntent(l1, null); GeometryIntent oGeo2 = iSheet.CreateGeometryIntent(l2, null); LinearGeneralDimension iDim = iSheet.DrawingDimensions.GeneralDimensions.AddLinear(pt1, oGeo1); DimensionStyle iStyle = iDim.Style; iStyle.PartOffset = 45.0; iStyle.ShowDimensionLine = true; iSheet.DrawingDimensions.GeneralDimensions.AddLinear(pt2, oGeo2).Style = iStyle; isRectangleCreated = true; } catch (Exception e) { Console.WriteLine(e.Message); } return(isRectangleCreated); }
/// <summary> /// When the user clicks on a point in the model, this method runs and creates an interaction graphics rectangle. /// It also subscribes to the Mouse Move event to allow for the size of the rectangle to be driven by the location /// of the mouse on the sketch. Ultimately, this method waits for the next click event, in which case it calls a /// new method to actually create the sketched rectangle. It has separate paths to react to whether it's a part /// sketch or a drawing sketch. /// </summary> /// <param name="button"></param> /// <param name="shiftKeys"></param> /// <param name="modelPosition"></param> /// <param name="viewPosition"></param> /// <param name="view"></param> protected void OnMouseClick_CreateRectangle(MouseButtonEnum button, ShiftStateEnum shiftKeys, Point modelPosition, Point2d viewPosition, Inventor.View view) { try { if (button == MouseButtonEnum.kLeftMouseButton) { _onMouseMove_Delegate = new MouseEventsSink_OnMouseMoveEventHandler(OnMouseMove_DragCornerOfRectangle); _mouseEvents.OnMouseClick -= _onMouseClick_Delegate; _onMouseClick_Delegate = null; _userInputEvents.OnContextMenu -= _userInputEvents_OnContextMenuDelegate; _userInputEvents_OnContextMenuDelegate = null; if (_inventorApplication.ActiveEditObject is PlanarSketch) { _planarSketch = (PlanarSketch)_inventorApplication.ActiveEditObject; if (_mouseEvents.PointInferences.Count > 0) { _inferredOriginPoint = _mouseEvents.PointInferences[1]; switch (_inferredOriginPoint.InferenceType) { case PointInferenceEnum.kPtAtIntersection: _firstSelectedSketchEntity = (SketchEntity)_inferredOriginPoint.Entity[1]; _firstInferredIntersectedSketchEntity = (SketchEntity)_inferredOriginPoint.Entity[2]; break; case PointInferenceEnum.kPtOnCurve: _firstSelectedSketchEntity = (SketchEntity)_inferredOriginPoint.Entity[1]; break; case PointInferenceEnum.kPtOnPt: _firstSelectedSketchEntity = (SketchPoint)_inferredOriginPoint.Entity[1]; _pickedSketchPoint = (SketchPoint)_firstSelectedSketchEntity; _rectangleOriginSketchPoint = _pickedSketchPoint; break; case PointInferenceEnum.kPtAtMidPoint: _firstSelectedSketchEntity = (SketchLine)_inferredOriginPoint.Entity[1]; break; } } _pickedPoint2d = _planarSketch.ModelToSketchSpace(modelPosition); DrawInteractionRectangle(); _mouseEvents.OnMouseMove += _onMouseMove_Delegate; _mouseEvents.MouseMoveEnabled = true; } else if (_inventorApplication.ActiveEditObject is DrawingSketch) { _drawingSketch = (DrawingSketch)_inventorApplication.ActiveEditObject; if (_mouseEvents.PointInferences.Count > 0) { _inferredOriginPoint = _mouseEvents.PointInferences[1]; switch (_inferredOriginPoint.InferenceType) { case PointInferenceEnum.kPtAtIntersection: _firstSelectedSketchEntity = (SketchEntity)_inferredOriginPoint.Entity[1]; _firstInferredIntersectedSketchEntity = (SketchEntity)_inferredOriginPoint.Entity[2]; break; case PointInferenceEnum.kPtOnCurve: _firstSelectedSketchEntity = (SketchEntity)_inferredOriginPoint.Entity[1]; break; case PointInferenceEnum.kPtOnPt: _firstSelectedSketchEntity = (SketchPoint)_inferredOriginPoint.Entity[1]; _pickedSketchPoint = (SketchPoint)_firstSelectedSketchEntity; _rectangleOriginSketchPoint = _pickedSketchPoint; break; case PointInferenceEnum.kPtAtMidPoint: _firstSelectedSketchEntity = (SketchLine)_inferredOriginPoint.Entity[1]; break; } } PointToPoint2d(modelPosition, out _pickedPoint2d); DrawInteractionRectangle(); _mouseEvents.OnMouseMove += _onMouseMove_Delegate; _mouseEvents.MouseMoveEnabled = true; } else { MessageBox.Show("You must be editing a sketch in order to use this tool."); } } } catch (Exception e) { MessageBox.Show(e.ToString()); } }
/// <summary> /// When the user clicks on a point in the model, this method runs and creates an interaction graphics rectangle. /// It also subscribes to the Mouse Move event to allow for the size of the rectangle to be driven by the location /// of the mouse on the sketch. Ultimately, this method waits for the next click event, in which case it calls a /// new method to actually create the sketched rectangle. It has separate paths to react to whether it's a part /// sketch or a drawing sketch. /// </summary> /// <param name="button"></param> /// <param name="shiftKeys"></param> /// <param name="modelPosition"></param> /// <param name="viewPosition"></param> /// <param name="view"></param> protected void OnMouseClick_CreateRectangle(MouseButtonEnum button, ShiftStateEnum shiftKeys, Point modelPosition, Point2d viewPosition, Inventor.View view) { try { if (button == MouseButtonEnum.kLeftMouseButton) { _onMouseMove_Delegate = new MouseEventsSink_OnMouseMoveEventHandler(OnMouseMove_DragCornerOfRectangle); _mouseEvents.OnMouseClick -= _onMouseClick_Delegate; _onMouseClick_Delegate = null; _userInputEvents.OnContextMenu -= _userInputEvents_OnContextMenuDelegate; _userInputEvents_OnContextMenuDelegate = null; if (_inventorApplication.ActiveEditObject is PlanarSketch) { _planarSketch = (PlanarSketch)_inventorApplication.ActiveEditObject; if (_mouseEvents.PointInferences.Count > 0) { _inferredOriginPoint = _mouseEvents.PointInferences[1]; switch (_inferredOriginPoint.InferenceType) { case PointInferenceEnum.kPtAtIntersection: _firstSelectedSketchEntity = (SketchEntity)_inferredOriginPoint.Entity[1]; _firstInferredIntersectedSketchEntity = (SketchEntity)_inferredOriginPoint.Entity[2]; break; case PointInferenceEnum.kPtOnCurve: _firstSelectedSketchEntity = (SketchEntity)_inferredOriginPoint.Entity[1]; break; case PointInferenceEnum.kPtOnPt: _firstSelectedSketchEntity = (SketchPoint)_inferredOriginPoint.Entity[1]; _pickedSketchPoint = (SketchPoint)_firstSelectedSketchEntity; _rectangleOriginSketchPoint = _pickedSketchPoint; break; case PointInferenceEnum.kPtAtMidPoint: _firstSelectedSketchEntity = (SketchLine)_inferredOriginPoint.Entity[1]; break; } } _pickedPoint2d = _planarSketch.ModelToSketchSpace(modelPosition); DrawInteractionRectangle(); _mouseEvents.OnMouseMove += _onMouseMove_Delegate; _mouseEvents.MouseMoveEnabled = true; } else if (_inventorApplication.ActiveEditObject is DrawingSketch) { _drawingSketch = (DrawingSketch)_inventorApplication.ActiveEditObject; if (_mouseEvents.PointInferences.Count > 0) { _inferredOriginPoint = _mouseEvents.PointInferences[1]; switch (_inferredOriginPoint.InferenceType) { case PointInferenceEnum.kPtAtIntersection: _firstSelectedSketchEntity = (SketchEntity)_inferredOriginPoint.Entity[1]; _firstInferredIntersectedSketchEntity = (SketchEntity)_inferredOriginPoint.Entity[2]; break; case PointInferenceEnum.kPtOnCurve: _firstSelectedSketchEntity = (SketchEntity)_inferredOriginPoint.Entity[1]; break; case PointInferenceEnum.kPtOnPt: _firstSelectedSketchEntity = (SketchPoint)_inferredOriginPoint.Entity[1]; _pickedSketchPoint = (SketchPoint)_firstSelectedSketchEntity; _rectangleOriginSketchPoint = _pickedSketchPoint; break; case PointInferenceEnum.kPtAtMidPoint: _firstSelectedSketchEntity = (SketchLine)_inferredOriginPoint.Entity[1]; break; } } PointToPoint2d(modelPosition, out _pickedPoint2d); DrawInteractionRectangle(); _mouseEvents.OnMouseMove += _onMouseMove_Delegate; _mouseEvents.MouseMoveEnabled = true; } else MessageBox.Show("You must be editing a sketch in order to use this tool."); } } catch (Exception e) { MessageBox.Show(e.ToString()); } }