Ejemplo n.º 1
0
        /// <summary>
        ///  Adds vertices to a polyline and adds it to a transaction.
        /// </summary>
        /// <param name="polyLine"></param>
        /// <param name="pointCollection"></param>
        public static void AddVertices(this Polyline3d polyLine, Point3dCollection pointCollection)
        {
            AutoCadHelper.AppendAndAddToTransaction(polyLine);

            foreach (Point3d point in pointCollection)
            {
                var vertex = new PolylineVertex3d(point);
                polyLine.AppendVertex(vertex);
                AutoCadHelper.AddToTransaction(vertex);
            }

            // Erase the polyline before commiting so it's not drawn.
            polyLine.Erase();
        }
Ejemplo n.º 2
0
        //convert parts to splines (works for line and arcs*Not arcs yet)
        static private Spline convertSpline(DBObject dbo)
        {
            if (dbo is Spline)
            {
                return(dbo as Spline);
            }
            if (dbo is Arc)
            {
                Arc    arcDat = dbo as Arc;
                Spline seg    = new Spline();
                //whatever that is
                return(seg);
            }
            else if (dbo is Line)
            {
                Line lDat = dbo as Line;
                Point3dCollection vertices = new Point3dCollection();
                vertices.Add(lDat.StartPoint);
                vertices.Add(lDat.EndPoint);
                Polyline3d tempPline = new Polyline3d();
                //polyine 3D has to be in btr before adding vertices
                Database db = HostApplicationServices.WorkingDatabase;
                using (Transaction trans = db.TransactionManager.StartTransaction())
                {
                    BlockTableRecord btr = (BlockTableRecord)(trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite));
                    btr.AppendEntity(tempPline);
                    foreach (Point3d pnt in vertices)
                    {
                        using (PolylineVertex3d poly3dVert = new PolylineVertex3d(pnt))
                        {
                            tempPline.AppendVertex(poly3dVert);
                        }
                    }
                    trans.Commit();
                }

                Spline seg = tempPline.Spline;
                tempPline.Erase(true);
                return(seg);
            }
            return(null);
        }
Ejemplo n.º 3
0
        public static void UpdateSurface(ObjectId objectId, dynamic xb)
        {
            Editor   ed      = acApp.DocumentManager.MdiActiveDocument.Editor;
            Document acDoc   = acApp.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;

            Point3d minPoint = new Point3d(Convert.ToDouble(xb.x1), Convert.ToDouble(xb.y1), Convert.ToDouble(xb.z1));
            Point3d maxPoint = new Point3d(Convert.ToDouble(xb.x2), Convert.ToDouble(xb.y2), Convert.ToDouble(xb.z2));

            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                // Open the Block table record for read
                BlockTable acBlkTbl;
                acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
                                             OpenMode.ForRead) as BlockTable;

                // Open the Block table record Model space for write
                BlockTableRecord acBlkTblRec;
                acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
                                                OpenMode.ForWrite) as BlockTableRecord;

                Point3d  pStart = minPoint;
                Point3d  pEnd   = new Point3d(maxPoint.X, maxPoint.Y, minPoint.Z);
                Vector3d vec    = new Vector3d(0, 0, maxPoint.Z - minPoint.Z);

                if (minPoint.Z == maxPoint.Z)
                {
                    pStart = minPoint;
                    pEnd   = new Point3d(maxPoint.X, minPoint.Y, maxPoint.Z);
                    vec    = new Vector3d(0, maxPoint.Y - minPoint.Y, 0);
                }

                // Create polyline
                Polyline3d poly = new Polyline3d();
                acBlkTblRec.AppendEntity(poly);
                acTrans.AddNewlyCreatedDBObject(poly, true);
                // Add vertex
                foreach (Point3d pnt in new List <Point3d>()
                {
                    pStart, pEnd
                })
                {
                    PolylineVertex3d vex3d = new PolylineVertex3d(pnt);
                    poly.AppendVertex(vex3d);
                    acTrans.AddNewlyCreatedDBObject(vex3d, true);
                }
                poly.Closed = false;
#if BRX_APP
                ExtrudedSurface extrSurf = (Teigha.DatabaseServices.ExtrudedSurface)acTrans.GetObject(objectId, OpenMode.ForWrite);
#elif ARX_APP
                ExtrudedSurface extrSurf = (Autodesk.AutoCAD.DatabaseServices.ExtrudedSurface)acTrans.GetObject(objectId, OpenMode.ForWrite);
#endif
                extrSurf.SetDatabaseDefaults();
                SweepOptions sweepOpts = new SweepOptions();
                extrSurf.CreateExtrudedSurface(poly, vec, sweepOpts);
                extrSurf.UIsoLineDensity = 0;
                extrSurf.VIsoLineDensity = 0;
                extrSurf.Draw();
                poly.Erase();
                acTrans.Commit();
                ed.UpdateScreen();
            }
        }