示例#1
0
        public static bool BuildPolylineFrom2Point(Point3d pt1, Point3d pt2)
        {
            //Get document, DataBase and Editor
            Document doc = Application.DocumentManager.MdiActiveDocument;

            Database db = doc.Database;

            Editor             ed = doc.Editor;
            PromptPointOptions op = new PromptPointOptions("Pick Direction:");

            op.UseBasePoint = true;
            op.BasePoint    = pt1;
            Line line           = new Line(pt1, pt2);
            PromptPointResult r = ed.GetPoint(op);

            if (r.Status == PromptStatus.OK)
            {
                Point3dCollection pts        = new Point3dCollection();
                Point3d           pt         = line.GetClosestPointTo(r.Value, true);
                Point3d           EndPoint   = pt1 + (r.Value - pt).GetNormal() * 3;
                Point3d           StartPoint = pt2 + (r.Value - pt).GetNormal() * 3;
                Point3dCollection vertex     = new Point3dCollection();
                vertex.Add(EndPoint);
                vertex.Add(pt1);
                vertex.Add(pt2);
                vertex.Add(StartPoint);
                Polyline3d pl3d = new Polyline3d(Poly3dType.SimplePoly, vertex, false);
                ArxHelper.AppendEntity(pl3d);
                vertex.Dispose();
                return(true);
            }
            return(false);
        }
示例#2
0
        public static void WriteInDatabase(PLine pline)
        {
            Editor   ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            Database workingDatabase = HostApplicationServices.WorkingDatabase;

            using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction())
            {
                BlockTable       blockTable                = (BlockTable)transaction.GetObject(workingDatabase.BlockTableId, (OpenMode)0);
                BlockTableRecord blockTableRecord          = (BlockTableRecord)transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], (OpenMode)1);
                List <ngeometry.VectorGeometry.Point> list = pline.GetVertices().ToList();
                if (pline.IsClosed)
                {
                    list.RemoveAt(list.Count - 1);
                }
                Point3dCollection point3dCollection = Conversions.ToPoint3dCollection(list);
                Polyline3d        polyline3d        = new Polyline3d(0, point3dCollection, false);
                point3dCollection.Dispose();
                if (pline.IsClosed)
                {
                    polyline3d.Closed = (true);
                }
                bool flag = false;
                polyline3d.LayerId = (DBManager.CreateLayer(pline.CADData.Layer.Name, 7, false, ref flag));
                Autodesk.AutoCAD.Colors.Color color = null;
                short colorIndex = pline.CADData.ColorIndex;
                if (pline.CADData.Color != System.Drawing.Color.Empty)
                {
                    color = Autodesk.AutoCAD.Colors.Color.FromColor(pline.CADData.Color);
                }
                if (color == null)
                {
                    polyline3d.ColorIndex = ((int)colorIndex);
                }
                else
                {
                    polyline3d.Color = (color);
                }



                //polyline3d.StartPoint.X
                blockTableRecord.AppendEntity(polyline3d);
                transaction.AddNewlyCreatedDBObject(polyline3d, true);
                transaction.Commit();
            }
        }
示例#3
0
        public void DevelopmentCommand()
        {
            Database arg_05_0 = HostApplicationServices.WorkingDatabase;
            Editor   editor   = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            try
            {
                //LicenseManager.CheckValid("FULL");
                PromptEntityOptions promptEntityOptions = new PromptEntityOptions("Select polyline");
                promptEntityOptions.SetRejectMessage("\nNo polyline selected");
                promptEntityOptions.AddAllowedClass(typeof(Polyline3d), true);
                promptEntityOptions.AddAllowedClass(typeof(Polyline2d), true);
                promptEntityOptions.AddAllowedClass(typeof(Polyline), true);
                promptEntityOptions.AllowNone = (false);
                PromptEntityResult entity = editor.GetEntity(promptEntityOptions);
                if (entity.Status == (PromptStatus)(-5002))
                {
                    CommandLineQuerries.OnCancelled();
                }
                if (entity.Status != (PromptStatus)5100)
                {
                    CommandLineQuerries.OnNotOK();
                }
                CMD_Development.string_2 = CommandLineQuerries.KeywordYesNo("Reverse polyline", CMD_Development.string_2, false, false);
                CMD_Development.string_3 = CommandLineQuerries.KeywordYesNo("Specify range", CMD_Development.string_3, false, false);
                if (CMD_Development.string_3 == "Y")
                {
                    CMD_Development.double_0 = CommandLineQuerries.SpecifyDouble("Specify start arc length", CMD_Development.double_0, false, false, false, true);
                    CMD_Development.double_1 = CommandLineQuerries.SpecifyDouble("Specify end arc length", CMD_Development.double_1, false, false, false, true);
                }
                CMD_Development.double_2 = CommandLineQuerries.SpecifyDouble("Specify z-scaling", CMD_Development.double_2, false, false, false, false);
                CMD_Development.string_5 = CommandLineQuerries.KeywordYesNo("Include first derivative (slope)", CMD_Development.string_5, false, false);
                if (CMD_Development.string_5 == "Y")
                {
                    CMD_Development.double_3 = CommandLineQuerries.SpecifyDouble("Specify z-scaling for derivative", CMD_Development.double_3, false, false, false, false);
                }
                CMD_Development.string_4 = CommandLineQuerries.SpecifyOutfileType(CMD_Development.string_4);
                CommandLineQuerries.SpecifyFileNameForWrite(ref CMD_Development.string_0, ref CMD_Development.string_1, CMD_Development.string_4);
                bool   reverse  = CMD_Development.string_2 == "Y";
                double startBGL = 0.0;
                double endBGL   = 1.7976931348623157E+308;
                if (CMD_Development.string_3 == "Y")
                {
                    startBGL = CMD_Development.double_0;
                    endBGL   = CMD_Development.double_1;
                }
                List <Point> list   = this.DevelopPolyline(entity.ObjectId, reverse, startBGL, endBGL);
                List <Point> points = new List <Point>();
                if (CMD_Development.string_5 == "Y")
                {
                    points = this.Derivative(list);
                }
                CMD_Development.Result result = new CMD_Development.Result(list, startBGL);
                editor.WriteMessage("\n" + result.ToString());
                Database database = new Database(true, true);
                using (Transaction transaction = database.TransactionManager.StartTransaction())
                {
                    BlockTable        blockTable        = (BlockTable)transaction.GetObject(database.BlockTableId, (OpenMode)1);
                    BlockTableRecord  blockTableRecord  = (BlockTableRecord)transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], (OpenMode)1);
                    bool              flag              = false;
                    ObjectId          layerId           = DBManager.CreateLayer("profile", 7, false, ref flag, database);
                    Point3dCollection point3dCollection = Conversions.ToPoint3dCollection(list);
                    Polyline3d        polyline3d        = new Polyline3d(0, point3dCollection, false);
                    point3dCollection.Dispose();
                    polyline3d.LayerId = (layerId);
                    blockTableRecord.AppendEntity(polyline3d);
                    transaction.AddNewlyCreatedDBObject(polyline3d, true);
                    if (CMD_Development.string_5 == "Y")
                    {
                        bool              flag2              = false;
                        ObjectId          layerId2           = DBManager.CreateLayer("slope", 4, false, ref flag2, database);
                        Point3dCollection point3dCollection2 = Conversions.ToPoint3dCollection(points);
                        Polyline3d        polyline3d2        = new Polyline3d(0, point3dCollection2, false);
                        point3dCollection2.Dispose();
                        polyline3d2.LayerId = (layerId2);
                        blockTableRecord.AppendEntity(polyline3d2);
                        transaction.AddNewlyCreatedDBObject(polyline3d2, true);
                    }
                    transaction.Commit();
                    polyline3d.Dispose();
                }
                DBManager.SaveDrawing(database, CMD_Development.string_0, CMD_Development.string_4, (DwgVersion)29);
            }
            catch (System.Exception ex)
            {
                editor.WriteMessage(Environment.NewLine + ex.Message + Environment.NewLine);
            }
        }
示例#4
0
 public void Dispose()
 {
     _weldingArcs.Dispose();
     _weldingVertices.Dispose();
 }
示例#5
0
        /// <summary>
        /// Scan the solid from bottom, identify points and create
        /// a surface
        /// </summary>
        /// <param name="solidId">Solid to scan</param>
        /// <param name="tinSurfaceToCutId">Referecen surface</param>
        /// <param name="solidSurfaceName">Name of the new
        /// surface that will be created</param>
        /// <param name="densityOfPoints">Number of points per
        /// AutoCAD unit used on scan</param>
        /// <param name="simplifySurface">Whether o not simplify
        /// the surface at the end (using Civil 3D
        /// built-in operation)</param>
        private static void GenerateSurfaceByScan(
            ObjectId solidId,
            ObjectId tinSurfaceToCutId,
            string solidSurfaceName,
            int densityOfPoints,
            bool simplifySurface)
        {
            _db = Application.DocumentManager.MdiActiveDocument.Database;
            using (_trans = _db.TransactionManager.StartTransaction())
            {
                try
                {
                    // open entities
                    _solid = _trans.GetObject(solidId, OpenMode.ForRead)
                             as Solid3d;
                    if (!tinSurfaceToCutId.IsNull)
                    {
                        _surface =
                            _trans.GetObject(tinSurfaceToCutId, OpenMode.ForRead)
                            as TinSurface;
                    }

                    // extract the Brep of the solid
                    _brepSolid = new Brep(_solid);
                    _newPoints = new Point3dCollection();

                    // get the extend of the solid
                    Extents3d extends = _solid.GeometricExtents;
                    // and expand by 20% to increase accuracy
                    // on the solid edges/borders
                    extends.TransformBy(Matrix3d.Scaling(1.2,
                                                         _solid.MassProperties.Centroid));

                    // geometric line at the bottom (virtual datum)
                    // this line is the scan line
                    //
                    //  x--------------------------x
                    //  |  pt2        ^            pt3
                    //  |             direction
                    //  |             of scan progress
                    //  |
                    //  | <-scan line
                    //  |
                    //  x  pt1
                    //
                    Point3d scanLinePt1 = extends.MinPoint;
                    Point3d scanLinePt2 = new Point3d(
                        scanLinePt1.X, extends.MaxPoint.Y, scanLinePt1.Z);
                    LineSegment3d scanLine = new LineSegment3d(
                        scanLinePt1, scanLinePt2);
                    Point3d scanLinePt3 = new Point3d(
                        extends.MaxPoint.X, extends.MaxPoint.Y, scanLinePt1.Z);
                    _upperLimit = extends.MaxPoint.Z; // scan upper limit

                    int numberOfScanLines = ((int)
                                             Math.Round(scanLinePt2.DistanceTo(scanLinePt3),
                                                        MidpointRounding.ToEven)) * densityOfPoints;

                    ProgressMeter progressBar = new ProgressMeter();
                    progressBar.SetLimit(numberOfScanLines);
                    progressBar.Start("Scanning solid...");

                    for (int i = 0; i < numberOfScanLines; i++)
                    {
                        ProcessScanLine(scanLine, densityOfPoints, true);

                        // move the scan line over the scane direction
                        // get direction vector
                        Vector3d scanLineDisplacementDirection =
                            scanLinePt2.GetVectorTo(scanLinePt3);
                        // make unit vector
                        scanLineDisplacementDirection /=
                            scanLineDisplacementDirection.Length;
                        // adjust size
                        scanLineDisplacementDirection *=
                            (1.0 / densityOfPoints);
                        scanLine.TransformBy(Matrix3d.Displacement(
                                                 scanLineDisplacementDirection));

                        progressBar.MeterProgress();
                        Util.AvoidNotResponding();
                    }
                    progressBar.Stop();
                    scanLine.Dispose();

                    #region For testing only
#if DEBUG
                    BlockTableRecord mSpace = _trans.GetObject(_db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
                    foreach (Point3d pt in _newPoints)
                    {
                        DBPoint p = new DBPoint(pt);
                        mSpace.AppendEntity(p);
                        _trans.AddNewlyCreatedDBObject(p, true);
                    }
#endif
                    #endregion

                    CreateSolidSurface(solidSurfaceName, simplifySurface);

                    _trans.Commit();
                }
                catch (System.Exception ex)
                {
                    Application.DocumentManager.MdiActiveDocument.
                    Editor.WriteMessage("Error: Operation aborted ({0})",
                                        ex.Message);
                    _trans.Abort();
                }
                finally
                {
                    // final cleanup
                    if (!_brepSolid.IsDisposed)
                    {
                        _brepSolid.Dispose();
                    }
                    if (!_newPoints.IsDisposed)
                    {
                        _newPoints.Dispose();
                    }
                    _solid     = null;
                    _surface   = null;
                    _brepSolid = null;
                    _newPoints = null;
                }
            }
        }
示例#6
0
        private ObjectId TrimPickUP(int nodeNumer, int TriangleNumer, double X, double angle)
        {
            //UtilityClasses.ConstantsAndSettings.DoubleGlass_h1
            //UtilityClasses.ConstantsAndSettings.DoubleGlass_h2
            //UtilityClasses.ConstantsAndSettings.Thickness_of_the_Glass
            #region basedata
            Database db = HostApplicationServices.WorkingDatabase;
            Editor   ed = Application.DocumentManager.MdiActiveDocument.Editor;

            ed.WriteMessage("\n");
            ed.WriteMessage(angle.ToString());

            var        node     = container.Nodes[nodeNumer];
            Triangle   TR       = container.Triangles[TriangleNumer];
            quaternion trNormal = TR.Normal.Second - TR.Normal.First;
            trNormal /= trNormal.abs();
            plane trPlane = new plane(TR.Nodes.First, TR.Nodes.Second, TR.Nodes.Third);


            Point3dCollection pColl = new Point3dCollection();
            IntegerCollection iCol1 = new IntegerCollection();
            IntegerCollection iCol2 = new IntegerCollection();



            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                if ((TR.upSolidHandle.First >= 0) && (TR.upSolidHandle.Second != null))
                {
                    try
                    {
                        Solid3d upSolid = tr.GetObject(GlobalFunctions.GetObjectId(TR.upSolidHandle.Second), OpenMode.ForWrite) as Solid3d;
                        upSolid.GetGripPoints(pColl, iCol1, iCol2);
                    }
                    catch { }
                }
            }


            Bend bend1 = container.Bends[TR.GetFirstBendNumer()];
            Bend bend2 = container.Bends[TR.GetSecondBendNumer()];
            Bend bend3 = container.Bends[TR.GetThirdBendNumer()];
            #endregion

            List <Bend> bends = new List <Bend>();
            if ((bend1.StartNodeNumer == nodeNumer) || (bend1.EndNodeNumer == nodeNumer))
            {
                bends.Add(bend1);
            }
            if ((bend2.StartNodeNumer == nodeNumer) || (bend2.EndNodeNumer == nodeNumer))
            {
                bends.Add(bend2);
            }
            if ((bend3.StartNodeNumer == nodeNumer) || (bend3.EndNodeNumer == nodeNumer))
            {
                bends.Add(bend3);
            }

            if (bends.Count != 2)
            {
                MessageBox.Show("Only two Bends are connected at one point !", "E R R O R");
                return(ObjectId.Null);
            }

            if (bends[0].IsFictive() || bends[1].IsFictive())
            {
                return(ObjectId.Null);
            }

            quaternion Q0 = node.Position;
            quaternion Q1 = (bends[0].Start + bends[0].End) / 2.0;
            quaternion Q2 = (bends[1].Start + bends[1].End) / 2.0;

            // coorinat systems for plane points calculate
            Q1 = Q1 - Q0; Q1 /= Q1.abs(); Q1 *= X; Q1 = Q0 + Q1;
            Q2 = Q2 - Q0; Q2 /= Q2.abs(); Q2 *= X; Q2 = Q0 + Q2;

            UCS ucs = new UCS(Q0, (Q1 + Q2) / 2.0, Q2);
            ucs = new UCS(Q0, ucs.ToACS(new quaternion(0, 0, 100, 0)), ucs.ToACS(new quaternion(0, 100, 0, 0)));

            #region UP glass

            double     dist = (node.Position - (quaternion)pColl[0]).abs();
            quaternion pick = new quaternion();

            foreach (Point3d p in pColl)
            {
                quaternion q = (quaternion)p;
                double     z = (node.Position - q).abs();

                if (z < dist)
                {
                    dist = z;
                    pick = new quaternion(0, p.X, p.Y, p.Z);
                }
            }
            pColl.Clear(); pColl.Dispose();
            iCol1.Clear();
            iCol1.Clear();
            #endregion


            ucs.o = pick;
            Q1    = pick + Q1 - Q0;
            Q2    = pick + Q2 - Q0;
            Q0    = pick;

            // UtilityClasses.GlobalFunctions.DrawLine((Point3d)Q0, new Point3d(), 1);

            quaternion t1 = (Q2 - Q1) * 2.0;
            quaternion t2 = (Q1 - Q2) * 2.0;
            Q1 = Q1 + t2;
            Q2 = Q2 + t1;

            Matrix3d mat = new Matrix3d(ucs.GetAutoCAD_Matrix3d());
            Q1 = ucs.FromACS(Q1);
            Q2 = ucs.FromACS(Q2);
            quaternion   Q3  = new quaternion(0, Q1.GetX(), -Q1.GetY(), Q1.GetZ());
            quaternion   Q4  = new quaternion(0, Q2.GetX(), -Q2.GetY(), Q2.GetZ());
            quaternion[] arr = { Q1, Q2, Q4, Q3, Q1 };
            ObjectId     obj = ObjectId.Null;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable       acBlkTbl    = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord acBlkTblRec = tr.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                Polyline pol = GlobalFunctions.GetPoly(ref arr);
                //pol.TransformBy(Matrix3d.Displacement(new Point3d().GetVectorTo(new Point3d(0, 0, -100))));
                //pol.TransformBy(mat);

                //acBlkTblRec.AppendEntity(pol);
                //tr.AddNewlyCreatedDBObject(pol, true);

                try
                {
                    Solid3d sol = new Solid3d();
                    sol.CreateExtrudedSolid(pol, new Point3d(0, 0, 0).GetVectorTo(new Point3d(0, 0, 100)), new SweepOptions());
                    sol.TransformBy(Matrix3d.Displacement(new Point3d().GetVectorTo(new Point3d(0, 0, -50))));
                    sol.TransformBy(mat);
                    acBlkTblRec.AppendEntity(sol);
                    tr.AddNewlyCreatedDBObject(sol, true);
                    obj = sol.ObjectId;
                }
                catch { }

                tr.Commit();
            }

            /*
             * if (obj != ObjectId.Null)
             * {
             *  using (Transaction tr = db.TransactionManager.StartTransaction())
             *  {
             *
             *      Solid3d sol = tr.GetObject(obj, OpenMode.ForWrite) as Solid3d;
             *      Solid3d ent = tr.GetObject(UtilityClasses.GlobalFunctions.GetObjectId(TR.lowSolidHandle.Second), OpenMode.ForWrite) as Solid3d;
             *      ent.BooleanOperation(BooleanOperationType.BoolSubtract, sol);
             *
             *      tr.Commit();
             *  }
             * }*/



            // ed.WriteMessage("\n");
            // ed.WriteMessage(ucs.FromACS(Q0).ToString());
            // ed.WriteMessage("\n-----------------------------\n");

            return(obj);
        }