Exemplo n.º 1
0
        // EllipticalArc
        public void exportEllipticalArc(SketchEllipticalArc ellipticalarc, String varname)
        {
            double centerX = ellipticalarc.CenterSketchPoint.Geometry.X;
            double centerY = ellipticalarc.CenterSketchPoint.Geometry.Y;

            double startAngle = ellipticalarc.StartAngle * (180 / Math.PI);
            double sweepAngle = ellipticalarc.SweepAngle * (180 / Math.PI);

            double startX = ellipticalarc.StartSketchPoint.Geometry.X;
            double startY = ellipticalarc.StartSketchPoint.Geometry.Y;

            double majorradius = ellipticalarc.MajorRadius;
            double minorradius = ellipticalarc.MinorRadius;

            double radius = (majorradius / 2) / Math.Cos(sweepAngle);

            using (StreamWriter outputFile = new StreamWriter(jscadPath, true))
            {
                outputFile.WriteLine("var " + varname + "= CSG.Path2D.arc({");
                outputFile.WriteLine("center: [0,0,0],");
                outputFile.WriteLine("radius: " + convertCommaToDot(radius) + ",");
                outputFile.WriteLine("startangle: " + convertCommaToDot(startAngle) + ",");
                outputFile.WriteLine("endangle: " + convertCommaToDot(sweepAngle));
                outputFile.WriteLine("}).close().innerToCAG();");
            }
        }
Exemplo n.º 2
0
        public override void CreateModule(ParameterBase Parameter)
        {
            parCylineDoor = Parameter as ParCylinderDoor;
            if (parCylineDoor == null)
            {
                return;
            }
            init();
            PartDocument            part    = InventorTool.CreatePart();
            PartComponentDefinition partDef = part.ComponentDefinition;
            PlanarSketch            osketch = partDef.Sketches.Add(partDef.WorkPlanes[3]);
            SketchEllipticalArc     Arc1    = osketch.SketchEllipticalArcs.Add(InventorTool.Origin, InventorTool.Left, parCylineDoor.DoorRadius, parCylineDoor.InRadius, 0, Math.PI / 2);
            SketchEllipticalArc     Arc2    = osketch.SketchEllipticalArcs.Add(InventorTool.Origin, InventorTool.Left, parCylineDoor.DoorRadius + parCylineDoor.Thickness, parCylineDoor.InRadius + parCylineDoor.Thickness, 0, Math.PI / 2);

            osketch.GeometricConstraints.AddConcentric((SketchEntity)Arc1, (SketchEntity)Arc2);
            SketchLine Line1 = osketch.SketchLines.AddByTwoPoints(Arc1.StartSketchPoint, Arc2.StartSketchPoint);
            SketchLine Line2 = osketch.SketchLines.AddByTwoPoints(Arc1.EndSketchPoint, Arc2.EndSketchPoint);

            osketch.GeometricConstraints.AddHorizontalAlign(Arc1.StartSketchPoint, Arc1.CenterSketchPoint);
            osketch.GeometricConstraints.AddVerticalAlign(Arc1.EndSketchPoint, Arc1.CenterSketchPoint);
            osketch.GeometricConstraints.AddHorizontal((SketchEntity)Line1);
            osketch.GeometricConstraints.AddVertical((SketchEntity)Line2);
            osketch.DimensionConstraints.AddEllipseRadius((SketchEntity)Arc1, true, InventorTool.TranGeo.CreatePoint2d(-parCylineDoor.DoorRadius / 2, 0));
            osketch.DimensionConstraints.AddEllipseRadius((SketchEntity)Arc1, false, InventorTool.TranGeo.CreatePoint2d(0, -parCylineDoor.InRadius / 2));

            Point2d p = InventorTool.TranGeo.CreatePoint2d((Line1.StartSketchPoint.Geometry.X + Line1.EndSketchPoint.Geometry.X) / 2 + 1, (Line1.StartSketchPoint.Geometry.Y + Line1.EndSketchPoint.Geometry.Y) / 2 + 1);

            osketch.DimensionConstraints.AddTwoPointDistance(Line1.StartSketchPoint, Line1.EndSketchPoint, DimensionOrientationEnum.kAlignedDim, p);
            Profile        profile = osketch.Profiles.AddForSolid();
            RevolveFeature revolve = partDef.Features.RevolveFeatures.AddFull(profile, Line1, PartFeatureOperationEnum.kNewBodyOperation);
        }
Exemplo n.º 3
0
        // EllipticalArc (todo)
        public static string ExportEllipticalArc(SketchEllipticalArc ellipticalarc, string entityName)
        {
            double centerX = Math.Round(ellipticalarc.CenterSketchPoint.Geometry.X, 4) * factor;
            double centerY = Math.Round(ellipticalarc.CenterSketchPoint.Geometry.Y, 4) * factor;

            double startAngle = ellipticalarc.StartAngle * (180 / Math.PI);
            double sweepAngle = ellipticalarc.SweepAngle * (180 / Math.PI);

            double majorradius = Math.Round(ellipticalarc.MajorRadius, 4) * factor;
            double minorradius = Math.Round(ellipticalarc.MinorRadius, 4) * factor;

            double radius = (majorradius / 2) / Math.Cos(sweepAngle);

            string nameRadius     = entityName + "_Radius";
            string nameStartAngle = entityName + "_StartAngle";
            string nameSweepAngle = entityName + "_SweepAngle";
            string nameCenterX    = entityName + "_CenterX";
            string nameCenterY    = entityName + "_CenterY";

            Parameter param1 = new Parameter(nameRadius, "Radius of " + entityName, "float",
                                             radius, 0.1);
            Parameter param2 = new Parameter(nameStartAngle, "Start angle of " + entityName, "float",
                                             startAngle, 0.1);
            Parameter param3 = new Parameter(nameSweepAngle, "Sweep angle of " + entityName, "float",
                                             sweepAngle, 0.1);
            Parameter param4 = new Parameter(nameCenterX, "Center X of " + entityName, "float",
                                             centerX, 0.1);
            Parameter param5 = new Parameter(nameCenterY, "Center Y of " + entityName, "float",
                                             centerY, 0.1);

            Shakespeare.ListOfParameter.Add(param1);
            Shakespeare.ListOfParameter.Add(param2);
            Shakespeare.ListOfParameter.Add(param3);
            Shakespeare.ListOfParameter.Add(param4);
            Shakespeare.ListOfParameter.Add(param5);

            // das hier funktioniert nicht in jscad :/
            // https://joostn.github.io/OpenJsCad/
            //var ellipsearc = CSG.Path2D.arc({
            //    center: [0, 0, 0],
            // xradius: 5,
            // yradius: 20,
            // xaxisrotation: 100,
            // clockwise: true,
            //    large: false,
            //    resolution: 48,
            //    startangle: 0,
            // endangle: 60
            //}).close().innerToCAG();

            string javaScriptVariable = "var " + entityName + "= CSG.Path2D.arc({center: [0,0,0]," +
                                        "radius: params." + nameRadius + ", startangle: params." +
                                        nameStartAngle + ", endangle: params." + nameSweepAngle + "}).close().innerToCAG();";

            return("\t" + javaScriptVariable);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 创建椭圆线段和直线段
        /// </summary>
        /// <param name="osketch"></param>
        /// <param name="oEllipticalArc"></param>
        /// <param name="oLine"></param>
        /// <param name="RadiusX"></param>
        /// <param name="RadiusY"></param>
        /// <param name="Length"></param>
        private void CreateLines(PlanarSketch osketch, out SketchEllipticalArc oEllipticalArc, out SketchLine oLine, double RadiusX, double RadiusY, double Length)
        {
            oEllipticalArc = osketch.SketchEllipticalArcs.Add(InventorTool.Origin, InventorTool.Left, RadiusX, RadiusY, 0, Math.PI / 2);
            oLine          = osketch.SketchLines.AddByTwoPoints(oEllipticalArc.EndSketchPoint.Geometry, InventorTool.TranGeo.CreatePoint2d(Length, oEllipticalArc.EndSketchPoint.Geometry.Y));
            osketch.GeometricConstraints.AddHorizontal((SketchEntity)oLine);
            osketch.GeometricConstraints.AddCoincident((SketchEntity)oEllipticalArc, (SketchEntity)oLine.StartSketchPoint);
            osketch.GeometricConstraints.AddCoincident((SketchEntity)oEllipticalArc.EndSketchPoint, (SketchEntity)oLine);
            osketch.GeometricConstraints.AddTangent((SketchEntity)oEllipticalArc, (SketchEntity)oLine);

            //osketch.DimensionConstraints.AddArcLength((SketchEntity)oEllipticalArc, InventorTool.Origin);
        }
        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());
            }
        }