//////////////////////////////////////////////////////////////////////////////////////////////
        // Description: Displays PointGraphics with various RenderStyles
        //
        //////////////////////////////////////////////////////////////////////////////////////////////
        static public void PointGraphicsRenderDemo()
        {
            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);
            }

            TransientGeometry Tg = AdnInventorUtilities.InvApplication.TransientGeometry;


            GraphicsNode node = graphics.AddNode(graphics.Count + 1);

            PointGraphics[] pointGraphics = new PointGraphics[4];

            pointGraphics[0] = node.AddPointGraphics();
            pointGraphics[1] = node.AddPointGraphics();
            pointGraphics[2] = node.AddPointGraphics();
            pointGraphics[3] = node.AddPointGraphics();

            pointGraphics[0].PointRenderStyle = PointRenderStyleEnum.kCirclePointStyle;
            pointGraphics[0].CoordinateSet    = dataSets.CreateCoordinateSet(dataSets.Count + 1);
            pointGraphics[0].CoordinateSet.Add(1, Tg.CreatePoint(5, 5, 0));

            pointGraphics[1].PointRenderStyle = PointRenderStyleEnum.kCrossPointStyle;
            pointGraphics[1].CoordinateSet    = dataSets.CreateCoordinateSet(dataSets.Count + 1);
            pointGraphics[1].CoordinateSet.Add(1, Tg.CreatePoint(10, 0, 0));

            pointGraphics[2].PointRenderStyle = PointRenderStyleEnum.kXPointStyle;
            pointGraphics[2].CoordinateSet    = dataSets.CreateCoordinateSet(dataSets.Count + 1);
            pointGraphics[2].CoordinateSet.Add(1, Tg.CreatePoint(5, -5, 0));

            pointGraphics[3].PointRenderStyle = PointRenderStyleEnum.kFilledCircleSelectPointStyle;
            pointGraphics[3].CoordinateSet    = dataSets.CreateCoordinateSet(dataSets.Count + 1);
            pointGraphics[3].CoordinateSet.Add(1, Tg.CreatePoint(0, 0, 0));

            doc.Views[1].Update();
        }
Esempio n. 2
0
        private void CreatePart_Click(object sender, EventArgs e)
        {
            if (inventor == null)
            {
                MessageBox.Show("No inventor instance detected", "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            PartDocument doc = inventor.Documents.Add(DocumentTypeEnum.kPartDocumentObject, null, true) as PartDocument;

            doc.PropertySets["{F29F85E0-4FF9-1068-AB91-08002B27B3D9}"]["Author"].Value = "Vladyslav Romanchuk";

            //User-defined property
            doc.PropertySets["{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"].Add("Parts R Us", "Supplier");
            PartComponentDefinition partDefinition = (PartComponentDefinition)doc.ComponentDefinition;

            // Create a 2D sketch on the X-Y plane.
            PlanarSketch      sketch1 = (PlanarSketch)partDefinition.Sketches.Add(partDefinition.WorkPlanes[3]);
            TransientGeometry tg      = inventor.TransientGeometry;

            Point2d[] points = new Point2d[5] {
                tg.CreatePoint2d(0, 0), tg.CreatePoint2d(0, 20), tg.CreatePoint2d(20, 20), tg.CreatePoint2d(20, -10), tg.CreatePoint2d(10, -10)
            };
            SketchLine[] lines = new SketchLine[5];
            lines[0] = sketch1.SketchLines.AddByTwoPoints(points[0], points[1]);
            for (int i = 1; i < lines.Length - 1; i++)
            {
                lines[i] = sketch1.SketchLines.AddByTwoPoints(lines[i - 1].EndSketchPoint, points[i + 1]);
            }
            sketch1.SketchArcs.AddByCenterStartEndPoint(tg.CreatePoint2d(10, 0), lines[3].EndSketchPoint, lines[0].StartSketchPoint, false);

            //Extrude
            Profile           profile           = sketch1.Profiles.AddForSolid();
            ExtrudeDefinition extrudeDefinition = partDefinition.Features.ExtrudeFeatures.CreateExtrudeDefinition(profile, PartFeatureOperationEnum.kNewBodyOperation);

            extrudeDefinition.SetDistanceExtent(6, PartFeatureExtentDirectionEnum.kSymmetricExtentDirection);
            ExtrudeFeature extrude = (ExtrudeFeature)partDefinition.Features.ExtrudeFeatures.Add(extrudeDefinition);

            //second scatch
            Face topCap = extrude.EndFaces[1];

            sketch1 = partDefinition.Sketches.Add(topCap, false);

            Point2d      center = sketch1.ModelToSketchSpace(tg.CreatePoint(2.5, 1.5, 1.5));
            SketchCircle Circle = sketch1.SketchCircles.AddByCenterRadius(center, 1);

            profile           = sketch1.Profiles.AddForSolid(true, null, null);
            extrudeDefinition = partDefinition.Features.ExtrudeFeatures.CreateExtrudeDefinition(profile, PartFeatureOperationEnum.kJoinOperation);
            extrudeDefinition.SetDistanceExtent(4, PartFeatureExtentDirectionEnum.kSymmetricExtentDirection);
            extrude = (ExtrudeFeature)partDefinition.Features.ExtrudeFeatures.Add(extrudeDefinition);
            Edges          cylinderEdges = extrude.SideFaces[1].Edges;
            EdgeCollection filletEdges   = inventor.TransientObjects.CreateEdgeCollection(null);

            //foreach (var el in cylinderEdges)
            //    filletEdges.Add(el);
            filletEdges.Add(cylinderEdges[2]);
            //adding fillet
            partDefinition.Features.FilletFeatures.AddSimple(filletEdges, 0.25, false, false, false, false, false, true);
            //doc.SaveAs("D:\\SaveTest2.ipt", false);
        }
Esempio n. 3
0
        public void GetDistance()
        {
            PartComponentDefinition partComponentDefinition = InventorDocument.ComponentDefinition;
            /*Inventor.WorkPlane*/
            int countWorkPlanes = partComponentDefinition.WorkPlanes.Count;

            foreach (WorkPlane workPlane in partComponentDefinition.WorkPlanes)
            {
                var origin   = TransientGeometry.CreatePoint(0, 0, 0);
                var distance = workPlane.Plane.DistanceTo(origin);
            }
        }
Esempio n. 4
0
        /////////////////////////////////////////////////////////////
        // Use: Returns direction of the cone side as Line object.
        //
        /////////////////////////////////////////////////////////////
        public static Line GetConeSideDirection(
            Cone cone,
            UnitVector xAxis)
        {
            UnitVector yAxis = cone.AxisVector;

            double height =
                (cone.IsExpanding ? -1.0 : 1.0)
                * cone.Radius / Math.Tan(cone.HalfAngle);

            Point p1 = _Tg.CreatePoint(
                cone.BasePoint.X + xAxis.X * cone.Radius,
                cone.BasePoint.Y + xAxis.Y * cone.Radius,
                cone.BasePoint.Z + xAxis.Z * cone.Radius);

            Point p2 = _Tg.CreatePoint(
                cone.BasePoint.X + yAxis.X * height,
                cone.BasePoint.Y + yAxis.Y * height,
                cone.BasePoint.Z + yAxis.Z * height);

            return(_Tg.CreateLine(p1, p1.VectorTo(p2)));
        }
Esempio n. 5
0
        // version 2010-05-23: to solve the issue in Perspective View
        private void m_MouseEvents_OnMouseMove(Inventor.MouseButtonEnum Button, Inventor.ShiftStateEnum ShiftKeys, Inventor.Point ModelPosition, Inventor.Point2d ViewPosition, Inventor.View View)
        {
            //if the interaction event is MyScreenshot, draw selecting rectangle.
            if (m_InteractionEvents.Name == "MyScreenshot" && m_flagMouseDown)
            {
                TransientGeometry tg = m_inventorApplication.TransientGeometry;

                Inventor.Point P1 = tg.CreatePoint(m_MouseStartViewPt.X, -m_MouseStartViewPt.Y, 0);
                Inventor.Point P3 = tg.CreatePoint(ViewPosition.X, -ViewPosition.Y, 0);
                Inventor.Point P4 = tg.CreatePoint(P1.X, P3.Y, 0);
                Inventor.Point P2 = tg.CreatePoint(P3.X, P1.Y, 0);

                //update coordinates

                oCoordSet[1] = P1;
                oCoordSet[2] = P2;
                oCoordSet[3] = P3;
                oCoordSet[4] = P4;
                oCoordSet[5] = P1;

                //add line strip
                if (oGiLineStripG != null)
                {
                    //SetTransformBehavior, default value for PixelScale is 1
                    oGiLineStripG.SetTransformBehavior(P1, DisplayTransformBehaviorEnum.kFrontFacingAndPixelScaling, 1);
                    oGiLineStripG.SetViewSpaceAnchor(P1, m_MouseStartViewPt, ViewLayoutEnum.kTopLeftViewCorner);
                }
                else if (oGiLineG != null)
                {
                    //SetTransformBehavior, default value for PixelScale is 1
                    oGiLineG.SetTransformBehavior(P1, DisplayTransformBehaviorEnum.kFrontFacingAndPixelScaling, 1);
                    oGiLineG.SetViewSpaceAnchor(P1, m_MouseStartViewPt, ViewLayoutEnum.kTopLeftViewCorner);
                }


                m_inventorApplication.ActiveView.Update();
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Inserts a member (part/Subassembly or 3D model) in assembly and returns the created occurance
        /// </summary>
        /// <param name="assy"></param>
        /// <param name="inventor">inventor assembly</param>
        /// <param name="member">any of the supported <see cref="Document"/> types to insert into assembly</param>
        /// <param name="position">position of the member relative to assembly's origin</param>
        /// <param name="rotation">rotation about the X and Y and Z axis</param>
        /// <returns><see cref="ComponentOccurrence"/> that is created inside the assembly</returns>
        /// <remarks>remeber that Inventors internal units for length are centimeters</remarks>
        public static ComponentOccurrence AddMemeber(this AssemblyDocument assy, Application inventor, Document member, double[] position, double[] rotation)
        {
            if (member.DocumentType == DocumentTypeEnum.kDrawingDocumentObject ||
                member.DocumentType == DocumentTypeEnum.kNoDocument ||
                member.DocumentType == DocumentTypeEnum.kPresentationDocumentObject ||
                member.DocumentType == DocumentTypeEnum.kUnknownDocumentObject)
            {
                throw new ArgumentException("documnet type is not supported", nameof(member));
            }

            if (member.FullFileName == "")
            {
                throw new Exception("FullFileName of the part object was null, you need to save the part before passing to this method");
            }

            if (position.Length > 3 || rotation.Length > 3)
            {
                throw new ArgumentOutOfRangeException("position or rotaion array cannot have more than three memebers");
            }

            // Set a reference to the assembly component definition.
            AssemblyComponentDefinition oAsmCompDef = assy.ComponentDefinition;

            // Set a reference to the transient geometry object.
            TransientGeometry oTG = inventor.TransientGeometry;

            // Create a matrix.  A new matrix is initialized with an identity matrix.
            Matrix tempMatrix  = oTG.CreateMatrix();
            Matrix transMatrix = oTG.CreateMatrix();

            //for all rotational directions . . .
            for (int i = 0; i < rotation.Length; i++)
            {
                var index = new List <int>(new[] { 0, 0, 0 });
                index[i] = 1;
                var origin = oTG.CreatePoint(0, 0, 0);

                //rotate about an axis that goeas through origin point and is along the rotaional direction
                tempMatrix.SetToRotation(MathHelper.ToRadian(rotation[i]), oTG.CreateVector(index[0], index[1], index[2]), origin);
                transMatrix.TransformBy(tempMatrix);
                tempMatrix.SetToIdentity();
            }

            //move the object to the position
            transMatrix.SetTranslation(oTG.CreateVector(position[0], position[1], position[2]));

            // Add the occurrence.
            return(oAsmCompDef.Occurrences.Add(member.FullFileName, transMatrix));
        }
        //////////////////////////////////////////////////////////////////////////////////////////////
        // OnMouseMove Event is used to transform  current GraphicsNode moved by the user
        //
        //////////////////////////////////////////////////////////////////////////////////////////////
        void MouseEvents_OnMouseMove(
            MouseButtonEnum Button,
            ShiftStateEnum ShiftKeys,
            Inventor.Point ModelPosition,
            Point2d ViewPosition,
            Inventor.View View)
        {
            if (_symbolNode == null)
            {
                // Define symbol inputs: center, normal, radius
                Point center = _Tg.CreatePoint(0, 0, 0);

                UnitVector normal = _Tg.CreateUnitVector(0, 0, 1);

                double radius = _sheet.Width / 30;

                _symbolNode = DrawSymbol(normal, center, radius);
            }

            SetNodePosition(_symbolNode, ModelPosition);

            _clientGraphicsMng.UpdateView();
        }
        private void CreateShaft3dmodel(object sender, EventArgs e)
        {
            if (listViewShaftElements.Items.Count > 0)
            {

                if ((!ModelCreated) & (HeightOfNeighbourElementsIsDifferent()))
                {
                    PlanarSketch oSketch = default(PlanarSketch);
                    SketchPoints oSkPnts = default(SketchPoints);
                    Object actObj = ThisApplication.ActiveEditObject;
                    oSketch = (PlanarSketch)actObj;
                    oSkPnts = oSketch.SketchPoints;

                    oTransGeom = ThisApplication.TransientGeometry;
                    partDoc = (Inventor.PartDocument)ThisApplication.ActiveDocument;
                    oPartCompDef = partDoc.ComponentDefinition;

                    int TotalLenght2 = 0;
                    foreach (ListViewItem eachItem in listViewShaftElements.Items)
                    {
                        PartOfShaft POShaft = new PartOfShaft();
                        POShaft.PartHeight = Convert.ToInt32(eachItem.SubItems[1].Text);
                        POShaft.PartWidth = Convert.ToInt32(eachItem.SubItems[2].Text);
                        POShaft.CRectangle(POShaft.PartWidth, POShaft.PartHeight, TotalLenght2);

                        TotalLenght2 = TotalLenght2 + POShaft.PartWidth;
                        tbLenghtOfShaft.Text = Convert.ToString(TotalLenght2);
                    }

                    // Создание центральной оси для будущего вращения прямоугольников вокруг нее.
                    Point2d CentralLine_StartPoint = oTransGeom.CreatePoint2d(0, 0);
                    Point2d CentralLine_EndPoint = oTransGeom.CreatePoint2d(TotalLenght2, 0);
                    SketchLine CentralLineForRevolveAround = default(SketchLine);
                    CentralLineForRevolveAround = oSketch.SketchLines.AddByTwoPoints(CentralLine_StartPoint, CentralLine_EndPoint);

                    // Вращение.
                    oProfile0 = oSketch.Profiles.AddForSolid();
                    RevolveFeature oRevFeature = default(RevolveFeature);
                    oRevFeature = partDoc.ComponentDefinition.Features.RevolveFeatures.AddFull(oProfile0, CentralLineForRevolveAround, PartFeatureOperationEnum.kNewBodyOperation);

                    // Добавление фасок и кромок.

                    int StartPoint_X = 0, EndPoint_X = 0;
                    double MiddlePoint_X1 = 0, MiddlePoint_X2 = 0;
                    double SizeOfTypeStart = 0, SizeOfTypeEnd = 0;
                    double AngleStart, AngleEnd, SizeOfTypeEnd1, SizeOfTypeEnd2, SizeOfTypeStart1, SizeOfTypeStart2;

                    foreach (ListViewItem eachItem in listViewShaftElements.Items)
                    {
                        Point oPointStart = default(Point);
                        oPointStart = oTransGeom.CreatePoint(StartPoint_X, Convert.ToInt32(eachItem.SubItems[1].Text));

                        MiddlePoint_X1 = StartPoint_X + Convert.ToDouble(eachItem.SubItems[2].Text) / 2 - 0.02;
                        MiddlePoint_X2 = StartPoint_X + Convert.ToDouble(eachItem.SubItems[2].Text) / 2 + 0.02;
                        StartPoint_X = StartPoint_X + Convert.ToInt32(eachItem.SubItems[2].Text);
                        Point oPointEnd = default(Point);
                        EndPoint_X = StartPoint_X;
                        oPointEnd = oTransGeom.CreatePoint(EndPoint_X, Convert.ToInt32(eachItem.SubItems[1].Text));

                        Point oPointMiddle = default(Point);
                        oPointMiddle = oTransGeom.CreatePoint(MiddlePoint_X1, Convert.ToInt32(eachItem.SubItems[1].Text));

                        Face objFaceMiddle = (Face)partDoc.ComponentDefinition.SurfaceBodies[1].LocateUsingPoint(ObjectTypeEnum.kFaceObject, oPointMiddle, 0.01);

                        Object objStart = partDoc.ComponentDefinition.SurfaceBodies[1].LocateUsingPoint(ObjectTypeEnum.kEdgeObject, oPointStart, 0.01);
                        partDoc.SelectSet.Select(objStart);

                        // Определение коллекции начальных углов.
                        EdgeCollection oEdgesStart = default(EdgeCollection);
                        oEdgesStart = ThisApplication.TransientObjects.CreateEdgeCollection();
                        oEdgesStart.Add(objStart);
                        try
                        {
                            switch (eachItem.SubItems[3].Text)
                            {
                                case "Standart":
                                    partDoc.SelectSet.Clear();
                                    break;
                                case "Fillet":
                                    SizeOfTypeStart = Convert.ToDouble(eachItem.SubItems[4].Text);
                                    FilletFeature oFilletStart = default(FilletFeature);
                                    oFilletStart = oPartCompDef.Features.FilletFeatures.AddSimple(oEdgesStart, SizeOfTypeStart);
                                    break;
                                case "Chamfer (Distance)":
                                    SizeOfTypeStart = Convert.ToDouble(eachItem.SubItems[4].Text);
                                    ChamferFeature oChamferStart_D = default(ChamferFeature);
                                    oChamferStart_D = oPartCompDef.Features.ChamferFeatures.AddUsingDistance(oEdgesStart, SizeOfTypeStart);
                                    break;
                                case "Chamfer (Distance And Angle)":
                                    SizeOfTypeStart = Convert.ToDouble(eachItem.SubItems[4].Text);
                                    AngleStart = Convert.ToDouble(eachItem.SubItems[6].Text);
                                    ChamferFeature oChamferStart_DaA = default(ChamferFeature);
                                    oChamferStart_DaA = oPartCompDef.Features.ChamferFeatures.AddUsingDistanceAndAngle(oEdgesStart, objFaceMiddle, SizeOfTypeStart, AngleStart);
                                    break;
                                case "Chamfer (Two Distances)":
                                    SizeOfTypeStart1 = Convert.ToDouble(eachItem.SubItems[4].Text);
                                    SizeOfTypeStart2 = Convert.ToDouble(eachItem.SubItems[5].Text);
                                    ChamferFeature oChamferStart_DD = default(ChamferFeature);
                                    oChamferStart_DD = oPartCompDef.Features.ChamferFeatures.AddUsingTwoDistances(oEdgesStart, objFaceMiddle, SizeOfTypeStart1, SizeOfTypeStart2);
                                    break;

                            }
                        }

                        catch
                        {
                            MessageBox.Show(eachItem.SubItems[3].Text + " " + eachItem.SubItems[4].Text + " " + eachItem.SubItems[5].Text + " " + eachItem.SubItems[6].Text);
                        }

                        Point oPointMiddle2 = default(Point);
                        oPointMiddle2 = oTransGeom.CreatePoint(MiddlePoint_X2, Convert.ToInt32(eachItem.SubItems[1].Text));
                        Face objFaceMiddle2 = (Face)partDoc.ComponentDefinition.SurfaceBodies[1].LocateUsingPoint(ObjectTypeEnum.kFaceObject, oPointMiddle2, 0.01);

                        Object objEnd = partDoc.ComponentDefinition.SurfaceBodies[1].LocateUsingPoint(ObjectTypeEnum.kEdgeObject, oPointEnd, 0.01);
                        partDoc.SelectSet.Select(objEnd);

                        // Определение коллекции конечных углов.
                        EdgeCollection oEdgesEnd = default(EdgeCollection);
                        oEdgesEnd = ThisApplication.TransientObjects.CreateEdgeCollection();
                        oEdgesEnd.Add(objEnd);

                        switch (eachItem.SubItems[7].Text)
                        {
                            case "Standart":
                                partDoc.SelectSet.Clear();
                                break;
                            case "Fillet":
                                SizeOfTypeEnd = Convert.ToDouble(eachItem.SubItems[8].Text);
                                FilletFeature oFilletEnd = default(FilletFeature);
                                oFilletEnd = oPartCompDef.Features.FilletFeatures.AddSimple(oEdgesEnd, SizeOfTypeEnd);
                                break;
                            case "Chamfer (Distance)":
                                SizeOfTypeEnd = Convert.ToDouble(eachItem.SubItems[8].Text);
                                ChamferFeature oChamferEnd_D = default(ChamferFeature);
                                oChamferEnd_D = oPartCompDef.Features.ChamferFeatures.AddUsingDistance(oEdgesEnd, SizeOfTypeEnd);
                                break;
                            case "Chamfer (Distance And Angle)":
                                SizeOfTypeEnd = Convert.ToDouble(eachItem.SubItems[8].Text);
                                AngleEnd = Convert.ToDouble(eachItem.SubItems[10].Text);
                                ChamferFeature oChamferEnd_DaA = default(ChamferFeature);
                                oChamferEnd_DaA = oPartCompDef.Features.ChamferFeatures.AddUsingDistanceAndAngle(oEdgesEnd, objFaceMiddle2, SizeOfTypeEnd, AngleEnd);
                                break;
                            case "Chamfer (Two Distances)":
                                SizeOfTypeEnd1 = Convert.ToDouble(eachItem.SubItems[8].Text);
                                SizeOfTypeEnd2 = Convert.ToDouble(eachItem.SubItems[9].Text);
                                ChamferFeature oChamferEnd_DD = default(ChamferFeature);
                                oChamferEnd_DD = oPartCompDef.Features.ChamferFeatures.AddUsingTwoDistances(oEdgesEnd, objFaceMiddle2, SizeOfTypeEnd1, SizeOfTypeEnd2);
                                break;

                        }
                    }

                    ThisApplication.ActiveView.GoHome();
                    ModelCreated = true;
                }

                else if (ModelCreated)
                {
                    MessageBox.Show("The 3d model was already created!");
                }
            }
        }
        //////////////////////////////////////////////////////////////////////////////////////////////
        // Description: Copies SurfaceBody 1 of current part and performs boolean operation
        //              to displays result as SurfaceGraphics.
        //////////////////////////////////////////////////////////////////////////////////////////////
        static public void SurfaceGraphicsDemo()
        {
            PartDocument doc =
                AdnInventorUtilities.InvApplication.ActiveDocument
                as PartDocument;

            string clientId = "{Add-in Guid}";

            ClientGraphics graphics = null;

            try
            {
                graphics = doc.ComponentDefinition.ClientGraphicsCollection[clientId];
            }
            catch
            {
                graphics = doc.ComponentDefinition.ClientGraphicsCollection.Add(clientId);
            }

            // Store utility objects
            TransientGeometry geom = AdnInventorUtilities.InvApplication.TransientGeometry;
            TransientBRep     brep = AdnInventorUtilities.InvApplication.TransientBRep;

            GraphicsNode node = graphics.AddNode(graphics.Count + 1);

            // We will work on the first surface body in our document
            SurfaceBody nativeBody = doc.ComponentDefinition.SurfaceBodies[1];

            // Create a transient copy of the native body to work on it
            SurfaceBody body = brep.Copy(nativeBody);

            // Compute bottom/top points based on body bounding box
            Point bottom = geom.CreatePoint(
                (nativeBody.RangeBox.MinPoint.X + nativeBody.RangeBox.MaxPoint.X) / 2,
                (nativeBody.RangeBox.MinPoint.Y + nativeBody.RangeBox.MaxPoint.Y) / 2,
                nativeBody.RangeBox.MinPoint.Z);

            Point top = geom.CreatePoint(
                (nativeBody.RangeBox.MinPoint.X + nativeBody.RangeBox.MaxPoint.X) / 2,
                (nativeBody.RangeBox.MinPoint.Y + nativeBody.RangeBox.MaxPoint.Y) / 2,
                nativeBody.RangeBox.MaxPoint.Z);

            // Create transient cylinder tool body
            double radius = bottom.DistanceTo(top);

            SurfaceBody tool = brep.CreateSolidCylinderCone(bottom, top, radius, radius, radius, null);

            // Do boolean operation between transient bodies to remove cylinder
            brep.DoBoolean(body, tool, BooleanTypeEnum.kBooleanTypeDifference);

            // Add SurfaceGraphics primitive
            SurfaceGraphics surfGraphPrimitive = node.AddSurfaceGraphics(body);

            // Copy render style of native body if any
            StyleSourceTypeEnum source;
            RenderStyle         style = nativeBody.GetRenderStyle(out source);

            node.RenderStyle = style;

            // Hide native body
            nativeBody.Visible = false;

            doc.Views[1].Update();
        }
        //////////////////////////////////////////////////////////////////////////////////////////////
        // Description: Displays a TextGraphics with different styles and properties.
        //
        //////////////////////////////////////////////////////////////////////////////////////////////
        static public void TextGraphicsDemo()
        {
            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);
            }

            TransientGeometry Tg = AdnInventorUtilities.InvApplication.TransientGeometry;

            GraphicsNode node = graphics.AddNode(graphics.Count + 1);

            //Create scalable text graphics
            TextGraphics scalableTxt = node.AddScalableTextGraphics();

            //Set the properties of the text
            scalableTxt.Text                = "Scalable Text";
            scalableTxt.Anchor              = Tg.CreatePoint(0, 20, 0);
            scalableTxt.Bold                = true;
            scalableTxt.Font                = "Arial";
            scalableTxt.FontSize            = 10;
            scalableTxt.HorizontalAlignment = HorizontalTextAlignmentEnum.kAlignTextLeft;
            scalableTxt.Italic              = true;
            scalableTxt.PutTextColor(119, 187, 17);
            scalableTxt.VerticalAlignment = VerticalTextAlignmentEnum.kAlignTextMiddle;


            //Create anchored text graphics
            TextGraphics anchoredTxt = node.AddTextGraphics();

            //Set the properties of the text.
            anchoredTxt.Text     = "Anchored Text";
            anchoredTxt.Bold     = true;
            anchoredTxt.FontSize = 30;
            anchoredTxt.PutTextColor(255, 170, 0);

            Point anchorPoint = Tg.CreatePoint(1, 1, 1);

            //Set the text's anchor in model space.
            anchoredTxt.Anchor = anchorPoint;

            //Anchor the text graphics in the view.
            anchoredTxt.SetViewSpaceAnchor(
                anchorPoint,
                Tg.CreatePoint2d(30, 30),
                ViewLayoutEnum.kTopLeftViewCorner);


            TextGraphics symbolTxt1 = node.AddTextGraphics();

            symbolTxt1.Text = "n ";

            Point modelAnchorPoint = Tg.CreatePoint(50, 0, 0);

            //Because this text will have pixel scaling behavior these coordinates are in pixel space.
            symbolTxt1.Anchor              = Tg.CreatePoint(0, 0, 0);
            symbolTxt1.Font                = "AIGDT";
            symbolTxt1.FontSize            = 25;
            symbolTxt1.HorizontalAlignment = HorizontalTextAlignmentEnum.kAlignTextLeft;
            symbolTxt1.PutTextColor(221, 0, 0);
            symbolTxt1.VerticalAlignment = VerticalTextAlignmentEnum.kAlignTextMiddle;
            symbolTxt1.SetTransformBehavior(
                modelAnchorPoint,
                DisplayTransformBehaviorEnum.kFrontFacingAndPixelScaling,
                1);

            Box box = symbolTxt1.RangeBox;

            //Draw the next section of the string relative to the first section.
            TextGraphics symbolTxt2 = node.AddTextGraphics();

            symbolTxt2.Text = "9.4 - 9.8";

            //The range of the previous character is used to determine where to position
            //the next string. The range is returned in pixels.
            symbolTxt2.Anchor = Tg.CreatePoint(box.MaxPoint.X, 0, 0);

            symbolTxt2.Font                = "Arial";
            symbolTxt2.FontSize            = 25;
            symbolTxt2.HorizontalAlignment = HorizontalTextAlignmentEnum.kAlignTextLeft;
            symbolTxt2.PutTextColor(221, 0, 0);
            symbolTxt2.VerticalAlignment = VerticalTextAlignmentEnum.kAlignTextMiddle;
            symbolTxt2.SetTransformBehavior(
                modelAnchorPoint,
                DisplayTransformBehaviorEnum.kFrontFacingAndPixelScaling,
                1);

            doc.Views[1].Update();
        }
Esempio n. 11
0
        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();
        }
Esempio n. 12
0
        static public void StandartTest()
        {
            // Set Inventor Application and "activate it"
            TrAddInServer.MApp = null;
            inventordoc        = null;
            // Enable error handling.


            TransientBRep oTransBRep = TrAddInServer.MApp.TransientBRep;


            SurfaceBodyDefinition oSurfaceBodyDef = oTransBRep.CreateSurfaceBodyDefinition();

            TransientGeometry oTG = TrAddInServer.MApp.TransientGeometry;


            LumpDefinition oLumpDef = oSurfaceBodyDef.LumpDefinitions.Add();


            FaceShellDefinition oShell = oLumpDef.FaceShellDefinitions.Add();



            // Define the six planes of the box.
            Plane oPosX;
            Plane oNegX;
            Plane oPosY;
            Plane oNegY;
            Plane oPosZ;
            Plane oNegZ;

            oPosX = oTG.CreatePlane(oTG.CreatePoint(1, 0, 0), oTG.CreateVector(1, 0, 0));
            oNegX = oTG.CreatePlane(oTG.CreatePoint(-1, 0, 0), oTG.CreateVector(-1, 0, 0));
            oPosY = oTG.CreatePlane(oTG.CreatePoint(0, 1, 0), oTG.CreateVector(0, 1, 0));
            oNegY = oTG.CreatePlane(oTG.CreatePoint(0, -1, 0), oTG.CreateVector(0, -1, 0));
            oPosZ = oTG.CreatePlane(oTG.CreatePoint(0, 0, 1), oTG.CreateVector(0, 0, 1));
            oNegZ = oTG.CreatePlane(oTG.CreatePoint(0, 0, -1), oTG.CreateVector(0, 0, -1));

            // Create the six faces.
            FaceDefinition oFaceDefPosX;
            FaceDefinition oFaceDefNegX;
            FaceDefinition oFaceDefPosY;
            FaceDefinition oFaceDefNegY;
            FaceDefinition oFaceDefPosZ;
            FaceDefinition oFaceDefNegZ;

            oFaceDefPosX = oShell.FaceDefinitions.Add(oPosX, false);
            oFaceDefNegX = oShell.FaceDefinitions.Add(oNegX, false);
            oFaceDefPosY = oShell.FaceDefinitions.Add(oPosY, false);
            oFaceDefNegY = oShell.FaceDefinitions.Add(oNegY, false);
            oFaceDefPosZ = oShell.FaceDefinitions.Add(oPosZ, false);
            oFaceDefNegZ = oShell.FaceDefinitions.Add(oNegZ, false);

            // Create the vertices.
            VertexDefinition oVertex1;
            VertexDefinition oVertex2;
            VertexDefinition oVertex3;
            VertexDefinition oVertex4;
            VertexDefinition oVertex5;
            VertexDefinition oVertex6;
            VertexDefinition oVertex7;
            VertexDefinition oVertex8;

            oVertex1 = oSurfaceBodyDef.VertexDefinitions.Add(oTG.CreatePoint(1, 1, 1));
            oVertex2 = oSurfaceBodyDef.VertexDefinitions.Add(oTG.CreatePoint(1, 1, -1));
            oVertex3 = oSurfaceBodyDef.VertexDefinitions.Add(oTG.CreatePoint(-1, 1, -1));
            oVertex4 = oSurfaceBodyDef.VertexDefinitions.Add(oTG.CreatePoint(-1, 1, 1));
            oVertex5 = oSurfaceBodyDef.VertexDefinitions.Add(oTG.CreatePoint(1, -1, 1));
            oVertex6 = oSurfaceBodyDef.VertexDefinitions.Add(oTG.CreatePoint(1, -1, -1));
            oVertex7 = oSurfaceBodyDef.VertexDefinitions.Add(oTG.CreatePoint(-1, -1, -1));
            oVertex8 = oSurfaceBodyDef.VertexDefinitions.Add(oTG.CreatePoint(-1, -1, 1));

            // Define the edges at intersections of the defined planes.
            EdgeDefinition oEdgeDefPosXPosY;
            EdgeDefinition oEdgeDefPosXNegZ;
            EdgeDefinition oEdgeDefPosXNegY;
            EdgeDefinition oEdgeDefPosXPosZ;
            EdgeDefinition oEdgeDefNegXPosY;
            EdgeDefinition oEdgeDefNegXNegZ;
            EdgeDefinition oEdgeDefNegXNegY;
            EdgeDefinition oEdgeDefNegXPosZ;
            EdgeDefinition oEdgeDefPosYNegZ;
            EdgeDefinition oEdgeDefPosYPosZ;
            EdgeDefinition oEdgeDefNegYNegZ;
            EdgeDefinition oEdgeDefNegYPosZ;

            oEdgeDefPosXPosY = oSurfaceBodyDef.EdgeDefinitions.Add(oVertex1, oVertex2, oTG.CreateLineSegment(oVertex1.Position, oVertex2.Position));
            oEdgeDefPosXNegZ = oSurfaceBodyDef.EdgeDefinitions.Add(oVertex2, oVertex6, oTG.CreateLineSegment(oVertex2.Position, oVertex6.Position));
            oEdgeDefPosXNegY = oSurfaceBodyDef.EdgeDefinitions.Add(oVertex6, oVertex5, oTG.CreateLineSegment(oVertex6.Position, oVertex5.Position));
            oEdgeDefPosXPosZ = oSurfaceBodyDef.EdgeDefinitions.Add(oVertex5, oVertex1, oTG.CreateLineSegment(oVertex5.Position, oVertex1.Position));
            oEdgeDefNegXPosY = oSurfaceBodyDef.EdgeDefinitions.Add(oVertex4, oVertex3, oTG.CreateLineSegment(oVertex4.Position, oVertex3.Position));
            oEdgeDefNegXNegZ = oSurfaceBodyDef.EdgeDefinitions.Add(oVertex3, oVertex7, oTG.CreateLineSegment(oVertex3.Position, oVertex7.Position));
            oEdgeDefNegXNegY = oSurfaceBodyDef.EdgeDefinitions.Add(oVertex7, oVertex8, oTG.CreateLineSegment(oVertex7.Position, oVertex8.Position));
            oEdgeDefNegXPosZ = oSurfaceBodyDef.EdgeDefinitions.Add(oVertex8, oVertex4, oTG.CreateLineSegment(oVertex8.Position, oVertex4.Position));
            oEdgeDefPosYNegZ = oSurfaceBodyDef.EdgeDefinitions.Add(oVertex2, oVertex3, oTG.CreateLineSegment(oVertex2.Position, oVertex3.Position));
            oEdgeDefPosYPosZ = oSurfaceBodyDef.EdgeDefinitions.Add(oVertex4, oVertex1, oTG.CreateLineSegment(oVertex4.Position, oVertex1.Position));
            oEdgeDefNegYNegZ = oSurfaceBodyDef.EdgeDefinitions.Add(oVertex7, oVertex6, oTG.CreateLineSegment(oVertex7.Position, oVertex6.Position));
            oEdgeDefNegYPosZ = oSurfaceBodyDef.EdgeDefinitions.Add(oVertex5, oVertex8, oTG.CreateLineSegment(oVertex5.Position, oVertex8.Position));

            // Define the loops on the faces.

            EdgeLoopDefinition oPosXLoop = oFaceDefPosX.EdgeLoopDefinitions.Add();

            oPosXLoop.EdgeUseDefinitions.Add(oEdgeDefPosXPosY, true);
            oPosXLoop.EdgeUseDefinitions.Add(oEdgeDefPosXNegZ, true);
            oPosXLoop.EdgeUseDefinitions.Add(oEdgeDefPosXNegY, true);
            oPosXLoop.EdgeUseDefinitions.Add(oEdgeDefPosXPosZ, true);


            EdgeLoopDefinition oNegXLoop = oFaceDefNegX.EdgeLoopDefinitions.Add();

            oNegXLoop.EdgeUseDefinitions.Add(oEdgeDefNegXPosY, false);
            oNegXLoop.EdgeUseDefinitions.Add(oEdgeDefNegXNegZ, false);
            oNegXLoop.EdgeUseDefinitions.Add(oEdgeDefNegXNegY, false);
            oNegXLoop.EdgeUseDefinitions.Add(oEdgeDefNegXPosZ, false);


            EdgeLoopDefinition oPosYLoop = oFaceDefPosY.EdgeLoopDefinitions.Add();

            oPosYLoop.EdgeUseDefinitions.Add(oEdgeDefPosXPosY, false);
            oPosYLoop.EdgeUseDefinitions.Add(oEdgeDefPosYNegZ, false);
            oPosYLoop.EdgeUseDefinitions.Add(oEdgeDefNegXPosY, true);
            oPosYLoop.EdgeUseDefinitions.Add(oEdgeDefPosYPosZ, false);


            EdgeLoopDefinition oNegYLoop = oFaceDefNegY.EdgeLoopDefinitions.Add();

            oNegYLoop.EdgeUseDefinitions.Add(oEdgeDefPosXNegY, false);
            oNegYLoop.EdgeUseDefinitions.Add(oEdgeDefNegYPosZ, false);
            oNegYLoop.EdgeUseDefinitions.Add(oEdgeDefNegXNegY, true);
            oNegYLoop.EdgeUseDefinitions.Add(oEdgeDefNegYNegZ, false);

            EdgeLoopDefinition oPosZLoop = oFaceDefPosZ.EdgeLoopDefinitions.Add();

            oPosZLoop.EdgeUseDefinitions.Add(oEdgeDefNegXPosZ, true);
            oPosZLoop.EdgeUseDefinitions.Add(oEdgeDefNegYPosZ, true);
            oPosZLoop.EdgeUseDefinitions.Add(oEdgeDefPosXPosZ, false);
            oPosZLoop.EdgeUseDefinitions.Add(oEdgeDefPosYPosZ, true);


            EdgeLoopDefinition oNegZLoop = oFaceDefNegZ.EdgeLoopDefinitions.Add();

            oNegZLoop.EdgeUseDefinitions.Add(oEdgeDefNegXNegZ, true);
            oNegZLoop.EdgeUseDefinitions.Add(oEdgeDefNegYNegZ, true);
            oNegZLoop.EdgeUseDefinitions.Add(oEdgeDefPosXNegZ, false);
            oNegZLoop.EdgeUseDefinitions.Add(oEdgeDefPosYNegZ, true);

            //Create a transient surface body.
            NameValueMap oErrors;

            SurfaceBody oNewBody = oSurfaceBodyDef.CreateTransientSurfaceBody(out oErrors);

            // Create client graphics to display the transient body.

            PartDocument oDoc = (PartDocument)TrAddInServer.MApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject);


            PartComponentDefinition oDef = oDoc.ComponentDefinition;


            ClientGraphics oClientGraphics = oDef.ClientGraphicsCollection.Add("Sample3DGraphicsID");

            // Create a new graphics node within the client graphics objects.
            GraphicsNode oSurfacesNode = oClientGraphics.AddNode(1);

            // Create client graphics based on the transient body
            SurfaceGraphics oSurfaceGraphics = oSurfacesNode.AddSurfaceGraphics(oNewBody);

            // Update the view.
            TrAddInServer.MApp.ActiveView.Update();
        }
Esempio n. 13
0
        //////////////////////////////////////////////////////////////////////////////////////////////
        // Draws dimension graphics
        //
        //////////////////////////////////////////////////////////////////////////////////////////////
        DimData DrawDimension(Point point1, Point point2, Point dimText, Vector normal)
        {
            // Compute extension points
            Vector xAxis = point1.VectorTo(point2);

            Vector upVector = normal.CrossProduct(xAxis);

            upVector.Normalize();

            Plane plane = _Tg.CreatePlane(point1, normal);

            Point dimTextProj = AdnInventorUtilities.ProjectOnPlane(dimText, plane);

            double dotP1 = point1.VectorTo(dimTextProj).DotProduct(upVector);
            double dotP2 = point2.VectorTo(dimTextProj).DotProduct(upVector);

            Point extP1 = _Tg.CreatePoint(
                point1.X + upVector.X * dotP1,
                point1.Y + upVector.Y * dotP1,
                point1.Z + upVector.Z * dotP1);

            Point extP2 = _Tg.CreatePoint(
                point2.X + upVector.X * dotP2,
                point2.Y + upVector.Y * dotP2,
                point2.Z + upVector.Z * dotP2);

            double dimValue = extP1.DistanceTo(extP2);


            GraphicsNode node = _clientGraphicsMng.CreateNewGraphicsNode();

            LineGraphics extLine1 = _clientGraphicsMng.DrawLine(
                AdnInventorUtilities.ToArray(point1),
                AdnInventorUtilities.ToArray(extP1),
                node);

            LineGraphics extLine2 = _clientGraphicsMng.DrawLine(
                AdnInventorUtilities.ToArray(point2),
                AdnInventorUtilities.ToArray(extP2),
                node);

            LineGraphics dimLine = _clientGraphicsMng.DrawLine(
                AdnInventorUtilities.ToArray(extP1),
                AdnInventorUtilities.ToArray(extP2),
                node);

            extLine1.LineType = LineTypeEnum.kDashedLineType;
            extLine2.LineType = LineTypeEnum.kDashedLineType;

            UnitVector v = extP1.VectorTo(extP2).AsUnitVector();

            double length = 20.0;
            double radius = 7.0;

            Point bottom1 = _Tg.CreatePoint(
                extP1.X + length * v.X,
                extP1.Y + length * v.Y,
                extP1.Z + length * v.Z);

            Point bottom2 = _Tg.CreatePoint(
                extP2.X - length * v.X,
                extP2.Y - length * v.Y,
                extP2.Z - length * v.Z);

            SurfaceBody cone1 = _TBrep.CreateSolidCylinderCone(
                bottom1, extP1,
                radius, radius, 0.0, null);

            SurfaceBody cone2 = _TBrep.CreateSolidCylinderCone(
                bottom2, extP2,
                radius, radius, 0.0, null);

            GraphicsNode dimNode = _clientGraphicsMng.CreateNewGraphicsNode();

            SurfaceGraphics arrow1 = _clientGraphicsMng.DrawSurface(cone1, dimNode);
            SurfaceGraphics arrow2 = _clientGraphicsMng.DrawSurface(cone2, dimNode);

            arrow1.SetTransformBehavior(extP1,
                                        DisplayTransformBehaviorEnum.kPixelScaling,
                                        1.0);

            arrow2.SetTransformBehavior(extP2,
                                        DisplayTransformBehaviorEnum.kPixelScaling,
                                        1.0);


            TextGraphics text = _clientGraphicsMng.DrawText(
                AdnInventorUtilities.GetStringFromAPILength(dimValue),
                false,
                dimNode);

            text.Font     = "Arial";
            text.Bold     = false;
            text.Italic   = false;
            text.FontSize = 20;
            text.PutTextColor(221, 0, 0);
            text.VerticalAlignment   = VerticalTextAlignmentEnum.kAlignTextMiddle;
            text.HorizontalAlignment = HorizontalTextAlignmentEnum.kAlignTextLeft;

            Point txtPos = _Tg.CreatePoint(
                (extP1.X + extP2.X) * 0.5,
                (extP1.Y + extP2.Y) * 0.5,
                (extP1.Z + extP2.Z) * 0.5);

            text.Anchor = txtPos;

            text.SetTransformBehavior(txtPos,
                                      DisplayTransformBehaviorEnum.kFrontFacingAndPixelScaling,
                                      1.0);

            node.Selectable    = true;
            dimNode.Selectable = true;

            return(new DimData(point1, point2, extLine1, extLine2, dimLine, dimNode));
        }
Esempio n. 14
0
        /////////////////////////////////////////////////////////////
        // Use: Creates new solid bodies affected by the future
        //      CoilFeature for Standard Thread.
        /////////////////////////////////////////////////////////////
        private static bool CreateCoilBodyStandard(PartDocument doc,
                                                   ThreadInfo threadInfo,
                                                   double minorRad,
                                                   double majorRad,
                                                   bool isInteriorFace)
        {
            try
            {
                PartComponentDefinition compDef =
                    doc.ComponentDefinition;

                Vector direction = threadInfo.ThreadDirection;

                Point basePoint =
                    threadInfo.ThreadBasePoints[1] as Point;

                Point endPoint = _Tg.CreatePoint(
                    basePoint.X + direction.X,
                    basePoint.Y + direction.Y,
                    basePoint.Z + direction.Z);

                UnitVector yAxis = direction.AsUnitVector();

                UnitVector xAxis = Toolkit.GetOrthoVector(yAxis);

                WorkPoint wpt = compDef.WorkPoints.AddFixed(basePoint,
                                                            _ConstructionWorkFeature);

                WorkPlane wpl = compDef.WorkPlanes.AddFixed(basePoint,
                                                            xAxis,
                                                            yAxis,
                                                            _ConstructionWorkFeature);

                WorkAxis xWa = compDef.WorkAxes.AddFixed(basePoint,
                                                         xAxis,
                                                         _ConstructionWorkFeature);

                WorkAxis yWa = compDef.WorkAxes.AddFixed(basePoint,
                                                         yAxis,
                                                         _ConstructionWorkFeature);

                Point sidePt = _Tg.CreatePoint(
                    basePoint.X + xAxis.X * majorRad,
                    basePoint.Y + xAxis.Y * majorRad,
                    basePoint.Z + xAxis.Z * majorRad);

                //Modif
                //double revDepth =
                //    Math.Abs(majorRad - minorRad) *
                //    (isInteriorFace ? -1.0 : 1.0);

                double revDepth = Math.Abs(majorRad - minorRad);

                Line l1 = _Tg.CreateLine(sidePt, yAxis.AsVector());

                Line l2 = _Tg.CreateLine(basePoint, xAxis.AsVector());

                Line l3 = _Tg.CreateLine(endPoint, xAxis.AsVector());

                Point p1 =
                    l1.IntersectWithCurve(l2, 0.0001)[1] as Point;

                Point p2 =
                    l1.IntersectWithCurve(l3, 0.0001)[1] as Point;

                Point p3 = _Tg.CreatePoint(
                    p2.X - xAxis.X * revDepth,
                    p2.Y - xAxis.Y * revDepth,
                    p2.Z - xAxis.Z * revDepth);

                Point p4 = _Tg.CreatePoint(
                    p1.X - xAxis.X * revDepth,
                    p1.Y - xAxis.Y * revDepth,
                    p1.Z - xAxis.Z * revDepth);


                SketchPoint skp1 = null;
                SketchPoint skp2 = null;
                SketchPoint skp3 = null;
                SketchPoint skp4 = null;

                PlanarSketch sketch  = null;
                Profile      profile = null;

                if (!isInteriorFace)
                {
                    sketch =
                        compDef.Sketches.AddWithOrientation(wpl,
                                                            xWa,
                                                            true,
                                                            true,
                                                            wpt,
                                                            false);

                    skp1 = sketch.SketchPoints.Add(
                        sketch.ModelToSketchSpace(p1), false);

                    skp2 = sketch.SketchPoints.Add(
                        sketch.ModelToSketchSpace(p2), false);

                    skp3 = sketch.SketchPoints.Add(
                        sketch.ModelToSketchSpace(p3), false);

                    skp4 = sketch.SketchPoints.Add(
                        sketch.ModelToSketchSpace(p4), false);

                    sketch.SketchLines.AddByTwoPoints(skp1, skp2);
                    sketch.SketchLines.AddByTwoPoints(skp2, skp3);
                    sketch.SketchLines.AddByTwoPoints(skp3, skp4);
                    sketch.SketchLines.AddByTwoPoints(skp4, skp1);

                    profile =
                        sketch.Profiles.AddForSolid(true, null, null);

                    RevolveFeature rev1 =
                        compDef.Features.RevolveFeatures.AddFull(
                            profile,
                            yWa,
                            PartFeatureOperationEnum.kCutOperation);
                }


                sketch = compDef.Sketches.AddWithOrientation(wpl,
                                                             xWa,
                                                             true,
                                                             true,
                                                             wpt,
                                                             false);

                skp1 = sketch.SketchPoints.Add(
                    sketch.ModelToSketchSpace(p1), false);

                skp2 = sketch.SketchPoints.Add(
                    sketch.ModelToSketchSpace(p2), false);

                skp3 = sketch.SketchPoints.Add(
                    sketch.ModelToSketchSpace(p3), false);

                skp4 = sketch.SketchPoints.Add(
                    sketch.ModelToSketchSpace(p4), false);

                sketch.SketchLines.AddByTwoPoints(skp1, skp2);
                sketch.SketchLines.AddByTwoPoints(skp2, skp3);
                sketch.SketchLines.AddByTwoPoints(skp3, skp4);
                sketch.SketchLines.AddByTwoPoints(skp4, skp1);

                profile = sketch.Profiles.AddForSolid(true,
                                                      null, null);

                RevolveFeature rev2 =
                    compDef.Features.RevolveFeatures.AddFull(
                        profile,
                        yWa,
                        PartFeatureOperationEnum.kNewBodyOperation);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Esempio n. 15
0
        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;
                }
            }
        }
        override protected void ButtonDefinition_OnExecute(NameValueMap context)
        {
            try
            {
                //MessageBox.Show("ERES UN CAPO");

                AutodeskInventorInterop AII = new AutodeskInventorInterop();

                string filename = "..\\CMUdata\\meshanid.srf";

                // Parses files into location and vertex connectivity from an SRF file
                AII.ReadFileDataToList(filename);
                //log.Info("Reading meshanid.srf");

                // Parses file for elements in riemanian metric matrix in 3D
                filename = "..\\CMUdata\\meshanid.nt3m";
                AII.ReadFileDataToList_nt3m(filename);
                // log.Info("Reading meshanid.nt3m");

                // Decomposes the Riemanian Matrix M=Q.L.Q^-1
                AII.EigenDecomp3D(AII.EigenList);
                // log.Info("EigenDecomposition");

                //  log.Info("User Coordinate System");

                Inventor.Application mApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application") as Inventor.Application;

                Inventor.PartDocument oDoc = (Inventor.PartDocument)mApp.ActiveDocument;

                PartComponentDefinition oCompDef = default(PartComponentDefinition); //Defines a part component
                oCompDef = oDoc.ComponentDefinition;

                //Used to create a Unitvector where to store MajorAxis 2D for ellipse
                TransientGeometry oTG        = mApp.TransientGeometry;
                UnitVector2d      oUniVector = oTG.CreateUnitVector2d(1, 1);

                Point2d oPoint2d = mApp.TransientGeometry.CreatePoint2d(0, 0);

                Profile oProfile = default(Profile); //Creates a profile

                //EdgeCollection oEdge = default(EdgeCollection);

                Edge[] oSideEdges = new Edge[5];

                //FilletFeature oFillet = default(FilletFeature);

                WorkPoint oWorkPoint1 = default(WorkPoint);
                WorkPoint oWorkPoint2 = default(WorkPoint);
                WorkPoint oWorkPoint3 = default(WorkPoint);

                UserCoordinateSystemDefinition oUCSDef = oCompDef.UserCoordinateSystems.CreateDefinition();

                UserCoordinateSystem oUCS = default(UserCoordinateSystem);

                EigenVectorPatternSketchPlane selectPlaneToSketch = new EigenVectorPatternSketchPlane();  //ERASE THIS NOT USEFUL

                PartComponentDefinition oDef       = oDoc.ComponentDefinition;
                PlanarSketch            oSketch    = default(PlanarSketch);
                ObjectCollection        oFitPoints = mApp.TransientObjects.CreateObjectCollection();

                Point2d             oPoint2d_a     = default(Point2d);
                SketchEllipticalArc oEllipticalArc = default(SketchEllipticalArc);
                SketchLine          oAxis          = default(SketchLine);
                RevolveFeature      oRevolve       = default(RevolveFeature);

                //  WorkPlane oWPain = default(WorkPlane);

                #region "This is my life"
                /****************************************** COMMENT ***********************************************/
                // Philippe Leefsma : [email protected]
                // Here is where all the pain happens
                // thank you for your help in advance.
                // Here is where I create a User defined coordinate system per each one of the features shown
                // I do not know if there is a way of making this faster?
                /****************************************** COMMENT ***********************************************/

                for (int i = 0; i < AII.VertexLocation.Count; i++)
                {
                    oWorkPoint1 = oCompDef.WorkPoints.AddFixed(
                        oTG.CreatePoint(
                            (double)AII.VertexLocation[i].origen.X,
                            (double)AII.VertexLocation[i].origen.Y,
                            (double)AII.VertexLocation[i].origen.Z)
                        );

                    //Change here u1/10 this is to make it closer to the mm value check if needs to be chage to in
                    oWorkPoint2 = oCompDef.WorkPoints.AddFixed(
                        oTG.CreatePoint(
                            (double)AII.EigenVectorValue[i].evc.u1 + (double)AII.VertexLocation[i].origen.X,
                            (double)AII.EigenVectorValue[i].evc.u2 + (double)AII.VertexLocation[i].origen.Y,
                            (double)AII.EigenVectorValue[i].evc.u3 + (double)AII.VertexLocation[i].origen.Z)
                        );
                    //Check here maybe this is why my rotations are screwd up, instead of v1 maybe is w1
                    //If w is use I have a cool effect with the protution coming out of the screen
                    oWorkPoint3 = oCompDef.WorkPoints.AddFixed(
                        oTG.CreatePoint(
                            (double)AII.EigenVectorValue[i].evc.v1 + (double)AII.VertexLocation[i].origen.X,
                            (double)AII.EigenVectorValue[i].evc.v2 + (double)AII.VertexLocation[i].origen.Y,
                            (double)AII.EigenVectorValue[i].evc.v3 + (double)AII.VertexLocation[i].origen.Z)
                        );


                    //User Define Coordinate

                    oUCSDef.SetByThreePoints(oWorkPoint1, oWorkPoint2, oWorkPoint3);


                    oUCS = oCompDef.UserCoordinateSystems.Add(oUCSDef);

                    oPoint2d.X = 0;
                    oPoint2d.Y = 0;

                    double l1 = AII.EigenVectorValue[i].evl.l1;
                    double l2 = AII.EigenVectorValue[i].evl.l2; //Here maybe we can reduece time by pre-working these numbers

                    double h1 = (1 / Math.Sqrt(l1));            //Check here
                    double h2 = (1 / Math.Sqrt(l2));

                    //Change here to add alfa angle
                    oUniVector.X = 1; // Math.Abs(AII.EigenVectorValue[i].evc.u1); //CHNAGE HERE 0 ,1 //if this is negative changes the direction
                    oUniVector.Y = 0; // Math.Abs(AII.EigenVectorValue[i].evc.u2);


                    oSketch = selectPlaneToSketch.SelectPlane(oDoc, oUCS);



                    //Candidates for config file
                    oWorkPoint1.Visible = false;
                    oWorkPoint2.Visible = false;
                    oWorkPoint3.Visible = false;
                    oUCS.Visible        = false;



                    double PI                = Math.Atan(1) * 4.0;
                    double duoPI             = 2 * PI;
                    double sizeBubbleInverse = 3.5; //this changes the sizes in the features contracts the bubbles "SIZING METRIC"

                    #region "Revolve and Join"
                    oPoint2d_a = mApp.TransientGeometry.CreatePoint2d(0, 0);

                    //Create Elliptical Arc
                    oEllipticalArc = oSketch.SketchEllipticalArcs.Add(oPoint2d_a, oUniVector, h1 / (sizeBubbleInverse), h2 / (sizeBubbleInverse), 0, PI);

                    oAxis = oSketch.SketchLines.AddByTwoPoints(
                        oEllipticalArc.StartSketchPoint,
                        oEllipticalArc.EndSketchPoint);

                    oProfile = oSketch.Profiles.AddForSolid();

                    oRevolve = oDoc.ComponentDefinition.Features.RevolveFeatures.AddFull
                                   (oProfile, oAxis, PartFeatureOperationEnum.kJoinOperation);
                    #endregion
                }

                #endregion
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
Esempio n. 17
0
 static public Point CP(double x = 0, double y = 0, double z = 0)
 {
     return(tg.CreatePoint(x, y, z));
 }
Esempio n. 18
0
        public static Inventor.Point ToPoint(this Autodesk.DesignScript.Geometry.Point xyz)
        {
            TransientGeometry transGeo = InventorServices.Persistence.PersistenceManager.InventorApplication.TransientGeometry;

            return(transGeo.CreatePoint(xyz.X, xyz.Y, xyz.Z));
        }