public void InitializePreviewGraphics() { m_interactionEvents = m_inventorApplication.CommandManager.CreateInteractionEvents(); InteractionGraphics interactionGraphics = m_interactionEvents.InteractionGraphics; ClientGraphics previewClientGraphics = interactionGraphics.PreviewClientGraphics; m_previewClientGraphicsNode = previewClientGraphics.AddNode(1); m_triangleStripGraphics = m_previewClientGraphicsNode.AddTriangleStripGraphics(); GraphicsDataSets graphicsDataSets = interactionGraphics.GraphicsDataSets; m_graphicsCoordinateSet = graphicsDataSets.CreateCoordinateSet(1); m_graphicsColorSet = graphicsDataSets.CreateColorSet(1); m_graphicsColorSet.Add(1, 100, 100, 200); m_graphicsColorSet.Add(2, 150, 150, 250); m_graphicsColorIndexSet = graphicsDataSets.CreateIndexSet(1); m_triangleStripGraphics.CoordinateSet = m_graphicsCoordinateSet; m_triangleStripGraphics.ColorSet = m_graphicsColorSet; m_triangleStripGraphics.ColorIndexSet = m_graphicsColorIndexSet; m_triangleStripGraphics.ColorBinding = ColorBindingEnum.kPerItemColors; m_triangleStripGraphics.BurnThrough = true; }
//----------------------------------------------------------------------------- //----------------- MoveCmd implement ---------------------------------------- //----------------------------------------------------------------------------- public void InitializePreviewGraphics() { m_interactionEvents = m_inventorApplication.CommandManager.CreateInteractionEvents(); InteractionGraphics interactionGraphics = m_interactionEvents.InteractionGraphics; ClientGraphics previewClientGraphics = interactionGraphics.PreviewClientGraphics; m_previewClientGraphicsNode = previewClientGraphics.AddNode(1); m_pointGraphics = m_previewClientGraphicsNode.AddPointGraphics(); GraphicsDataSets graphicsDateSets = interactionGraphics.GraphicsDataSets; m_graphicsCoordinateSet = graphicsDateSets.CreateCoordinateSet(1); m_graphicsColorSet = graphicsDateSets.CreateColorSet(1); m_graphicsColorSet.Add(1, 255, 0, 0); m_graphicsColorIndexSet = graphicsDateSets.CreateIndexSet(1); m_pointGraphics.CoordinateSet = m_graphicsCoordinateSet; m_pointGraphics.BurnThrough = true; }
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 PointGraphics DrawPoint( double[] position, GraphicsNode node) { try { AdnGraphics graphicsData = WorkingGraphics; if (node == null) { node = graphicsData.ClientGraphics.AddNode( graphicsData.GetGraphicNodeFreeId()); } PointGraphics graphic = node.AddPointGraphics(); if (position != null) { GraphicsCoordinateSet coordSet = graphicsData.GraphicsDataSets.CreateCoordinateSet( graphicsData.GetDataSetFreeId()); coordSet.PutCoordinates(ref position); graphic.CoordinateSet = coordSet; } return(graphic); } catch { return(null); } }
/// <summary> /// When the appropriate rectangle button is clicked the button's OnExecute event handler /// calls this method to hook up the mouse click event which will wait for the user to select /// a point from which to start the drawing of the rectangle /// </summary> public virtual void StartRectangleInteraction() { _interactionEvents = _inventorApplication.CommandManager.CreateInteractionEvents(); _rectangleInteractionGraphics = _interactionEvents.InteractionGraphics; _rectangleClientGraphics = _rectangleInteractionGraphics.OverlayClientGraphics; _rectangleLineNode = _rectangleClientGraphics.AddNode(1); _rectangleGraphicsDataSets = _rectangleInteractionGraphics.GraphicsDataSets; _rectangleCoordSet = _rectangleGraphicsDataSets.CreateCoordinateSet(1); _rectangleIndexSet = _rectangleGraphicsDataSets.CreateIndexSet(1); _onTerminate_Delegate = new InteractionEventsSink_OnTerminateEventHandler(StopInteraction); _interactionEvents.OnTerminate += _onTerminate_Delegate; _userInputEvents = _inventorApplication.CommandManager.UserInputEvents; _userInputEvents_OnContextMenuDelegate = new UserInputEventsSink_OnContextMenuEventHandler(UserInputEvents_OnContextMenu); _userInputEvents.OnContextMenu += _userInputEvents_OnContextMenuDelegate; _mouseEvents = _interactionEvents.MouseEvents; _mouseEvents.PointInferenceEnabled = true; _onMouseClick_Delegate = new MouseEventsSink_OnMouseClickEventHandler(OnMouseClick_CreateRectangle); _mouseEvents.OnMouseClick += _onMouseClick_Delegate; _interactionEvents.StatusBarText = "Select a Point from which to start the rectangle"; _interactionEvents.AllowCommandAliases = true; _interactionEvents.Start(); }
public TriangleStripGraphics DrawTriangleStrip( double[] coordinates, GraphicsNode node) { try { AdnGraphics graphicsData = WorkingGraphics; if (node == null) { node = graphicsData.ClientGraphics.AddNode( graphicsData.GetGraphicNodeFreeId()); } TriangleStripGraphics graphic = node.AddTriangleStripGraphics(); if (coordinates != null) { GraphicsCoordinateSet coordSet = graphicsData.GraphicsDataSets.CreateCoordinateSet( graphicsData.GetDataSetFreeId()); coordSet.PutCoordinates(ref coordinates); graphic.CoordinateSet = coordSet; } return(graphic); } catch { return(null); } }
//-------------------------------------------------------- public BlockFormCmd() { m_blockForm = null; m_previewClientGraphicsNode = null; m_triangleStripGraphics = null; m_graphicsCoordinateSet = null; m_graphicsColorSet = null; m_graphicsColorIndexSet = null; }
////////////////////////////////////////////////////////////////////////////////////////////// // Description: Displays a LineGraphics between points [0, 0, 0] and [1, 1, 1]. // ////////////////////////////////////////////////////////////////////////////////////////////// static public void LineGraphicsDemo() { PartDocument doc = AdnInventorUtilities.InvApplication.ActiveDocument as PartDocument; // ClientId, can be any string // Typically use instead current add-in GUID string clientId = "{Add-in Guid}"; // Add a new graphics group. // This will fail if a group with same name already exists ClientGraphics graphics = doc.ComponentDefinition.ClientGraphicsCollection.Add(clientId); // Add a new graphic node, with Id=1. // Id needs to be unique within graphics group GraphicsNode node = graphics.AddNode(1); // Add new data set GraphicsDataSets dataSets = doc.GraphicsDataSetsCollection.Add(clientId); // Add new coordinate set // Id needs to be unique within data set GraphicsCoordinateSet coordSet = dataSets.CreateCoordinateSet(1); // Fill up coordinates // Point1: [0.0, 0.0, 0.0] // Point2: [1.0, 1.0, 1.0] double[] coords = new double[] { 0.0, 0.0, 0.0, 1.0, 1.0, 1.0 }; coordSet.PutCoordinates(ref coords); // Create new GraphicsPrimitive LineGraphics lineGraphPrimitive = node.AddLineGraphics(); lineGraphPrimitive.LineWeight = 5.0; // Set coordinates lineGraphPrimitive.CoordinateSet = coordSet; // Update the current view, so we see the graphics doc.Views[1].Update(); }
////////////////////////////////////////////////////////////////////////////////////////////// // Description: Displays a PointGraphics using custom bitmap image. // ////////////////////////////////////////////////////////////////////////////////////////////// static public void PointGraphicsDemo() { PartDocument doc = AdnInventorUtilities.InvApplication.ActiveDocument as PartDocument; string clientId = "{Add-in Guid}"; ClientGraphics graphics = null; GraphicsDataSets dataSets = null; try { graphics = doc.ComponentDefinition.ClientGraphicsCollection[clientId]; dataSets = doc.GraphicsDataSetsCollection[clientId]; } catch { graphics = doc.ComponentDefinition.ClientGraphicsCollection.Add(clientId); dataSets = doc.GraphicsDataSetsCollection.Add(clientId); } GraphicsNode node = graphics.AddNode(graphics.Count + 1); GraphicsCoordinateSet coordSet = dataSets.CreateCoordinateSet(dataSets.Count + 1); double[] coords = new double[] { 5.0, 0.0, 0.0 }; coordSet.PutCoordinates(ref coords); GraphicsImageSet imageSet = dataSets.CreateImageSet(dataSets.Count + 1); stdole.IPictureDisp image = PictureDispConverter.ToIPictureDisp(Resources.PointImage); imageSet.Add(1, image, null, -1, -1); PointGraphics pointGraphPrimitive = node.AddPointGraphics(); pointGraphPrimitive.CoordinateSet = coordSet; pointGraphPrimitive.SetCustomImage(imageSet, 1); doc.Views[1].Update(); }
public MoveCmd() { m_moveCmdDlg = null; m_selectFace = null; m_selectiFeature = null; m_UCS = null; m_previewClientGraphicsNode = null; m_pointGraphics = null; m_graphicsCoordinateSet = null; m_graphicsColorSet = null; m_graphicsColorIndexSet = null; m_highlightSet = null; }
public void TerminatePreviewGraphics() { m_graphicsCoordinateSet.Delete(); m_graphicsColorSet.Delete(); m_graphicsColorIndexSet.Delete(); m_pointGraphics.Delete(); m_previewClientGraphicsNode.Delete(); m_graphicsCoordinateSet = null; m_graphicsColorSet = null; m_graphicsColorIndexSet = null; m_pointGraphics = null; m_previewClientGraphicsNode = null; }
public TriangleGraphics DrawTriangle( double[] v1, double[] v2, double[] v3, GraphicsNode node) { try { AdnGraphics graphicsData = WorkingGraphics; if (node == null) { node = graphicsData.ClientGraphics.AddNode( graphicsData.GetGraphicNodeFreeId()); } TriangleGraphics graphic = node.AddTriangleGraphics(); if ((v1 != null) && (v2 != null) && (v3 != null)) { GraphicsCoordinateSet coordSet = graphicsData.GraphicsDataSets.CreateCoordinateSet( graphicsData.GetDataSetFreeId()); List <double> coordinates = new List <double>(); coordinates.AddRange(v1); coordinates.AddRange(v2); coordinates.AddRange(v3); double[] coordsArray = coordinates.ToArray(); coordSet.PutCoordinates(ref coordsArray); graphic.CoordinateSet = coordSet; } return(graphic); } catch { return(null); } }
void DoDemo() { Inventor.Application InvApp = AdnInventorUtilities.InvApplication; //Create new interaction event _interactionEvents = InvApp.CommandManager.CreateInteractionEvents(); //Store mouse events _mouseEvents = _interactionEvents.MouseEvents; //Enable mouse move. This is disabled by default for performance reasons _mouseEvents.MouseMoveEnabled = true; //Listen to OnMouseMove event _mouseEvents.OnMouseMove += new MouseEventsSink_OnMouseMoveEventHandler(MouseEvents_OnMouseMove); _interactionEvents.StatusBarText = "Select triangle vertex: "; //Retrieve InteractionGraphics InteractionGraphics ig = _interactionEvents.InteractionGraphics; //Create new node GraphicsNode node = ig.OverlayClientGraphics.AddNode(1); //Add Triangle primitive _triangleGraph = node.AddTriangleGraphics(); //Set up coordinates GraphicsCoordinateSet coordSet = ig.GraphicsDataSets.CreateCoordinateSet(1); double[] coords = new double[] { 0.0, 0.0, 0.0, //vertex 1 5.0, 0.0, 0.0, //vertex 2 2.5, 5.0, 0.0 //vertex 3 }; coordSet.PutCoordinates(ref coords); _triangleGraph.CoordinateSet = coordSet; _interactionEvents.Start(); }
public LineGraphics DrawLine( double[] startPoint, double[] endPoint, GraphicsNode node) { try { AdnGraphics graphicsData = WorkingGraphics; if (node == null) { node = graphicsData.ClientGraphics.AddNode( graphicsData.GetGraphicNodeFreeId()); } LineGraphics graphic = node.AddLineGraphics(); if ((startPoint != null) && (endPoint != null)) { GraphicsCoordinateSet coordSet = graphicsData.GraphicsDataSets.CreateCoordinateSet( graphicsData.GetDataSetFreeId()); double[] coordsArray = startPoint.Concat(endPoint).ToArray(); coordSet.PutCoordinates(ref coordsArray); graphic.CoordinateSet = coordSet; } return(graphic); } catch { return(null); } }
public void UpdatePreviewGraphics() { m_graphicsCoordinateSet = null; InteractionGraphics interactionGraphics = m_interactionEvents.InteractionGraphics; GraphicsDataSets graphicsDataSets = interactionGraphics.GraphicsDataSets; if (graphicsDataSets.Count != 0) { graphicsDataSets[1].Delete(); } // m_graphicsCoordinateSet = graphicsDataSets.CreateCoordinateSet(1); //m_pointGraphics.CoordinateSet = m_graphicsCoordinateSet; //TransientGeometry transientGeometry = m_inventorApplication.TransientGeometry; PartDocument oPartDoc; oPartDoc = (PartDocument)m_inventorApplication.ActiveDocument; PartComponentDefinition oPartCompDef; oPartCompDef = oPartDoc.ComponentDefinition; WorkAxis workAxis; workAxis = oPartCompDef.WorkAxes.AddByRevolvedFace(m_selectFace, true); if (m_UCS == null) { return; } WorkPoint workPoint; workPoint = oPartCompDef.WorkPoints.AddByCurveAndEntity(workAxis, m_UCS.XYPlane); Point transPoint = workPoint.Point; UnitVector xUnitVector = m_UCS.XAxis.Line.Direction; UnitVector yUnitVector = m_UCS.YAxis.Line.Direction; Double[] xCoords = new Double[3]; xUnitVector.GetUnitVectorData(ref xCoords); Double[] yCoords = new Double[3]; yUnitVector.GetUnitVectorData(ref yCoords); double xOffset = this.GetValueFromExpression(m_moveCmdDlg.xOffsetText.Text); double yOffset = this.GetValueFromExpression(m_moveCmdDlg.yOffsetText.Text); Double[] transCoords = new Double[3]; transCoords[0] = xOffset * xCoords[0] + yOffset * yCoords[0]; transCoords[1] = xOffset * xCoords[1] + yOffset * yCoords[1]; transCoords[2] = xOffset * xCoords[2] + yOffset * yCoords[2]; Vector transVector = m_inventorApplication.TransientGeometry.CreateVector(); transVector.PutVectorData(transCoords); transPoint.TranslateBy(transVector); Double[] oPointCoords = new Double[3]; oPointCoords[0] = transPoint.X; oPointCoords[1] = transPoint.Y; oPointCoords[2] = transPoint.Z; m_graphicsCoordinateSet = graphicsDataSets.CreateCoordinateSet(1); m_graphicsCoordinateSet.PutCoordinates(oPointCoords); m_pointGraphics.CoordinateSet = m_graphicsCoordinateSet; TransientGeometry transientGeometry = m_inventorApplication.TransientGeometry; // m_graphicsCoordinateSet.Add(1, transPoint); m_inventorApplication.ActiveView.Update(); }
////////////////////////////////////////////////////////////////////////////////////////////// // Description: Displays a LineGraphics using Index and Color Sets. // ////////////////////////////////////////////////////////////////////////////////////////////// static public void IndexSetDemo() { PartDocument doc = AdnInventorUtilities.InvApplication.ActiveDocument as PartDocument; string clientId = "{Add-in Guid}"; ClientGraphics graphics = null; GraphicsDataSets dataSets = null; // Add some error handling in case // graphics collection and data already exist try { graphics = doc.ComponentDefinition.ClientGraphicsCollection[clientId]; dataSets = doc.GraphicsDataSetsCollection[clientId]; } catch { graphics = doc.ComponentDefinition.ClientGraphicsCollection.Add(clientId); dataSets = doc.GraphicsDataSetsCollection.Add(clientId); } // Add new node and coord set // Id generation by increment - bad because previous nodes/sets // may have been deleted previously, hence making count invalid GraphicsNode node = graphics.AddNode(graphics.Count + 1); GraphicsCoordinateSet coordSet = dataSets.CreateCoordinateSet(dataSets.Count + 1); double[] coords = new double[] { 0.0, 0.0, 0.0, //point 1 1.0, 1.0, 0.0, //point 2 0.0, 1.0, 0.0, //point 3 1.0, 0.0, 0.0 //point 4 }; coordSet.PutCoordinates(ref coords); LineGraphics lineGraphPrimitive = node.AddLineGraphics(); lineGraphPrimitive.LineWeight = 5.0; //Create Coordinate Index Set GraphicsIndexSet indexSetCoords = dataSets.CreateIndexSet(dataSets.Count + 1); indexSetCoords.Add(1, 1); //from point 1 indexSetCoords.Add(2, 3); //connect to point 3 indexSetCoords.Add(3, 3); //from point 3 indexSetCoords.Add(4, 2); //connect to point 2 indexSetCoords.Add(5, 2); //from point 2 indexSetCoords.Add(6, 4); //connect to point 4 lineGraphPrimitive.CoordinateSet = coordSet; lineGraphPrimitive.CoordinateIndexSet = indexSetCoords; //Create the color set with two colors GraphicsColorSet colorSet = dataSets.CreateColorSet(dataSets.Count + 1); colorSet.Add(1, 221, 0, 0); colorSet.Add(2, 255, 170, 0); colorSet.Add(3, 119, 187, 17); //Create the index set for color GraphicsIndexSet indexSetColors = dataSets.CreateIndexSet(dataSets.Count + 1); indexSetColors.Add(1, 3); //line 1 uses color 3 indexSetColors.Add(2, 1); //line 2 uses color 1 indexSetColors.Add(3, 2); //line 3 uses color 2 lineGraphPrimitive.ColorSet = colorSet; lineGraphPrimitive.ColorIndexSet = indexSetColors; lineGraphPrimitive.ColorBinding = ColorBindingEnum.kPerItemColors; doc.Views[1].Update(); }
////////////////////////////////////////////////////////////////////////////////////////////// // Simple example using Inventor API directly // ////////////////////////////////////////////////////////////////////////////////////////////// public static void ClientFeatureDemo() { string clientId = AdnInventorUtilities.AddInGuid; Inventor.Application InvApp = AdnInventorUtilities.InvApplication; Document document = InvApp.ActiveDocument; // We will use late binding to retrieve ClientFeatures collection, // so we dont need to write specific code for PartDocument and // AssemblyDocument ComponentDefinition compDef = AdnInventorUtilities.GetCompDefinition(document); object features = AdnInventorUtilities.GetProperty(compDef, "Features"); ClientFeatures clientFeatures = AdnInventorUtilities.GetProperty(features, "ClientFeatures") as ClientFeatures; ClientFeatureDefinition cfDef = clientFeatures.CreateDefinition("Graphics Feature", null, null, null); ClientFeature clientFeature = clientFeatures.Add(cfDef, clientId); NativeBrowserNodeDefinition nodeDef = clientFeature.BrowserNode.BrowserNodeDefinition as NativeBrowserNodeDefinition; stdole.IPictureDisp pic = PictureDispConverter.ToIPictureDisp(Resources.PointImage); ClientNodeResource res = document.BrowserPanes.ClientNodeResources.Add( clientId, document.BrowserPanes.ClientNodeResources.Count + 1, pic); nodeDef.OverrideIcon = res; cfDef = clientFeature.Definition; cfDef.HighlightClientGraphicsWithFeature = true; GraphicsDataSets sets = cfDef.GraphicsDataSetsCollection.Add2(clientId, true); GraphicsCoordinateSet coordSet = sets.CreateCoordinateSet(1); double[] coords = new double[] { 0.0, 0.0, 0.0, 5.0, 0.0, 0.0, 2.5, 5.0, 0.0 }; coordSet.PutCoordinates(ref coords); ClientGraphics cg = cfDef.ClientGraphicsCollection.Add(clientId); GraphicsNode node = cg.AddNode(1); node.RenderStyle = document.RenderStyles["Green (Flat)"]; TriangleGraphics primitive = node.AddTriangleGraphics(); primitive.CoordinateSet = coordSet; InvApp.ActiveView.Update(); }
////////////////////////////////////////////////////////////////////////////////////////////// // Description: Displays a TriangleFan Graphics. // ////////////////////////////////////////////////////////////////////////////////////////////// static public void TriangleFanGraphicsDemo() { PartDocument doc = AdnInventorUtilities.InvApplication.ActiveDocument as PartDocument; string clientId = "{Add-in Guid}"; ClientGraphics graphics = null; GraphicsDataSets dataSets = null; try { graphics = doc.ComponentDefinition.ClientGraphicsCollection[clientId]; dataSets = doc.GraphicsDataSetsCollection[clientId]; } catch { graphics = doc.ComponentDefinition.ClientGraphicsCollection.Add(clientId); dataSets = doc.GraphicsDataSetsCollection.Add(clientId); } GraphicsNode node = graphics.AddNode(graphics.Count + 1); GraphicsCoordinateSet coordSet = dataSets.CreateCoordinateSet(dataSets.Count + 1); double[] coords = new double[] { 0.0, 0.0, 0.0, //point 1 1.0, 1.0, 0.0, //point 2 2.0, 0.0, 0.0, //point 3 3.0, 1.0, 0.0, //point 4 4.0, 0.0, 0.0, //point 5 5.0, 1.0, 0.0, //point 6 6.0, 0.0, 0.0, //point 7 }; coordSet.PutCoordinates(ref coords); TriangleFanGraphics triFanPrimitive = node.AddTriangleFanGraphics(); int[] strips = new int[] { 3, //points 1,2,3 for strip 1 4 //points 4,5,6,7 for strip 2 }; triFanPrimitive.PutStripLengths(ref strips); //Create the color set with 3 colors GraphicsColorSet colorSet = dataSets.CreateColorSet(dataSets.Count + 1); colorSet.Add(1, 221, 0, 0); colorSet.Add(2, 119, 187, 17); colorSet.Add(3, 119, 187, 17); //Create the index set for color GraphicsIndexSet indexSetColors = dataSets.CreateIndexSet(dataSets.Count + 1); indexSetColors.Add(1, 2); //strip 1 uses color 1 indexSetColors.Add(2, 1); //strip 2 uses color 2 triFanPrimitive.CoordinateSet = coordSet; triFanPrimitive.ColorIndexSet = indexSetColors; triFanPrimitive.ColorSet = colorSet; triFanPrimitive.ColorBinding = ColorBindingEnum.kPerStripColors; doc.Views[1].Update(); }
/// <summary> /// When the appropriate rectangle button is clicked the button's OnExecute event handler /// calls this method to hook up the mouse click event which will wait for the user to select /// a point from which to start the drawing of the rectangle /// </summary> public virtual void StartRectangleInteraction() { _interactionEvents = _inventorApplication.CommandManager.CreateInteractionEvents(); _rectangleInteractionGraphics = _interactionEvents.InteractionGraphics; _rectangleClientGraphics = _rectangleInteractionGraphics.OverlayClientGraphics; _rectangleLineNode = _rectangleClientGraphics.AddNode(1); _rectangleGraphicsDataSets = _rectangleInteractionGraphics.GraphicsDataSets; _rectangleCoordSet = _rectangleGraphicsDataSets.CreateCoordinateSet(1); _rectangleIndexSet = _rectangleGraphicsDataSets.CreateIndexSet(1); _onTerminate_Delegate = new InteractionEventsSink_OnTerminateEventHandler(StopInteraction); _interactionEvents.OnTerminate += _onTerminate_Delegate; _userInputEvents = _inventorApplication.CommandManager.UserInputEvents; _userInputEvents_OnContextMenuDelegate = new UserInputEventsSink_OnContextMenuEventHandler(UserInputEvents_OnContextMenu); _userInputEvents.OnContextMenu += _userInputEvents_OnContextMenuDelegate; _mouseEvents = _interactionEvents.MouseEvents; _mouseEvents.PointInferenceEnabled = true; _onMouseClick_Delegate = new MouseEventsSink_OnMouseClickEventHandler(OnMouseClick_CreateRectangle); _mouseEvents.OnMouseClick += _onMouseClick_Delegate; _interactionEvents.StatusBarText = "Select a Point from which to start the rectangle"; _interactionEvents.AllowCommandAliases = true; _interactionEvents.Start(); }
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; }
private void m_MouseEvents_OnMouseDown(Inventor.MouseButtonEnum Button, Inventor.ShiftStateEnum ShiftKeys, Inventor.Point ModelPosition, Inventor.Point2d ViewPosition, Inventor.View View) { //if the interaction event is MyScreenshot, //then get the view position and model position if (m_InteractionEvents.Name == "MyScreenshot") { m_MouseStartViewPt = ViewPosition; m_StartModelPt = ModelPosition; m_flagMouseDown = true; //clean the last graphics m_InteractionEvents.InteractionGraphics.PreviewClientGraphics.Delete(); m_inventorApplication.ActiveView.Update(); //gi node oGiNode = m_InteractionEvents.InteractionGraphics.PreviewClientGraphics.AddNode(1); oCoordSet = m_InteractionEvents.InteractionGraphics.GraphicsDataSets.CreateCoordinateSet(1); //color set oColorSet = m_InteractionEvents.InteractionGraphics.GraphicsDataSets.CreateColorSet(1); oColorSet.Add(1, 255, 0, 0); TransientGeometry tg = m_inventorApplication.TransientGeometry; Inventor.Point tempP = tg.CreatePoint(ViewPosition.X, ViewPosition.Y, 0); oCoordSet.Add(1, tempP); oCoordSet.Add(2, tempP); oCoordSet.Add(3, tempP); oCoordSet.Add(4, tempP); oCoordSet.Add(5, tempP); try { if (oGiLineStripG != null) { oGiLineStripG.Delete(); oGiLineStripG = null; } oGiLineStripG = oGiNode.AddLineStripGraphics(); oGiLineStripG.CoordinateSet = oCoordSet; oGiLineStripG.ColorSet = oColorSet; oGiLineStripG.BurnThrough = true; } catch (Exception ex) { //a problem in Inventor 2009( R13 ) with //LineStripGraphics.BurnThrough. Use LineGraphics as workaround if (oGiLineG != null) { oGiLineG.Delete(); oGiLineG = null; } oGiLineG = oGiNode.AddLineGraphics(); oGiLineG.CoordinateSet = oCoordSet; oGiLineG.ColorSet = oColorSet; oGiLineG.BurnThrough = true; } } }
public void UpdatePreviewGraphics() { //remove the existing co-ordinates m_graphicsCoordinateSet = null; InteractionGraphics interactionGraphics = m_interactionEvents.InteractionGraphics; GraphicsDataSets graphicsDataSets = interactionGraphics.GraphicsDataSets; m_graphicsCoordinateSet = graphicsDataSets.CreateCoordinateSet(1); //remove the existing color indices m_graphicsColorIndexSet = null; m_graphicsColorIndexSet = graphicsDataSets.CreateIndexSet(1); m_triangleStripGraphics.CoordinateSet = m_graphicsCoordinateSet; m_triangleStripGraphics.ColorIndexSet = m_graphicsColorIndexSet; TransientGeometry transientGeometry = m_inventorApplication.TransientGeometry; Point point1 = transientGeometry.CreatePoint(0, 0, 0); Point point2 = transientGeometry.CreatePoint(m_length, 0, 0); Point point3 = transientGeometry.CreatePoint(m_length, m_width, 0); Point point4 = transientGeometry.CreatePoint(0, m_width, 0); Point point5 = transientGeometry.CreatePoint(0, 0, m_height); Point point6 = transientGeometry.CreatePoint(m_length, 0, m_height); Point point7 = transientGeometry.CreatePoint(m_length, m_width, m_height); Point point8 = transientGeometry.CreatePoint(0, m_width, m_height); AddGraphicsPoints(point1); AddColorIndex(1); AddGraphicsPoints(point6); AddColorIndex(1); AddGraphicsPoints(point2); AddColorIndex(1); AddGraphicsPoints(point3); AddColorIndex(1); AddGraphicsPoints(point1); AddColorIndex(2); AddGraphicsPoints(point4); AddColorIndex(2); AddGraphicsPoints(point8); AddColorIndex(1); AddGraphicsPoints(point3); AddColorIndex(1); AddGraphicsPoints(point7); AddColorIndex(2); AddGraphicsPoints(point6); AddColorIndex(2); AddGraphicsPoints(point8); AddColorIndex(1); AddGraphicsPoints(point5); AddColorIndex(1); AddGraphicsPoints(point1); AddColorIndex(2); AddGraphicsPoints(point6); AddColorIndex(2); m_inventorApplication.ActiveView.Update(); //Get the CommandManager object CommandManager oCommandManager; oCommandManager = m_inventorApplication.CommandManager; //Get control definition for the homeview command ControlDefinition oControlDef; oControlDef = oCommandManager.ControlDefinitions["AppIsometricViewCmd"]; //Excute the command oControlDef.Execute(); }