Exemple #1
0
        public static MText CreateMText(Database db, Point3d pt, string text, double textHeight, double rotation, AttachmentPoint attachmentPoint, ObjectId textStyleId, ObjectId layerId)
        {
            using (CurrentDB curr = new CurrentDB(db))
            {
                MText mtext = new MText();
                mtext.SetDatabaseDefaults(db);

                mtext.Contents   = text;
                mtext.Location   = pt;
                mtext.TextHeight = textHeight;
                mtext.Rotation   = rotation;
                mtext.Attachment = attachmentPoint;

                if (!textStyleId.IsNull)
                {
                    mtext.TextStyleId = textStyleId;
                }

                if (!layerId.IsNull)
                {
                    mtext.LayerId = layerId;
                }

                return(mtext);
            }
        }
Exemple #2
0
 public static Polyline3d CreatePolyLine3d(Database db, bool closed, Point3dCollection points)
 {
     using (CurrentDB curr = new CurrentDB(db))
     {
         Polyline3d pline = new Polyline3d(Poly3dType.SimplePoly, points, closed);
         pline.SetDatabaseDefaults(db);
         return(pline);
     }
 }
Exemple #3
0
        public static Line[] CreateMLine(Database db, Point3d pt1, Point3d pt2, double thickness, ObjectId layerId)
        {
            using (CurrentDB curr = new CurrentDB(db))
            {
                Vector3d dir = (pt2 - pt1).GetPerpendicularVector().GetNormal() * thickness / 2.0;

                return(new Line[] {
                    CreateLine(db, pt1 + dir, pt2 + dir, layerId),
                    CreateLine(db, pt1 - dir, pt2 - dir, layerId)
                });
            }
        }
Exemple #4
0
        public static BlockReference CreateBlockReference(Database db, ObjectId blockId, Point3d insertionPoint, Scale3d scaleFactors, double rotation)
        {
            using (CurrentDB curr = new CurrentDB(db))
            {
                BlockReference blockRef = new BlockReference(insertionPoint, blockId);
                blockRef.SetDatabaseDefaults(db);

                blockRef.ScaleFactors = scaleFactors;
                blockRef.Rotation     = rotation;

                return(blockRef);
            }
        }
Exemple #5
0
        public static Line CreateLine(Database db, Point3d pt1, Point3d pt2, ObjectId layerId)
        {
            using (CurrentDB curr = new CurrentDB(db))
            {
                Line line = new Line();
                line.SetDatabaseDefaults(db);

                line.StartPoint = pt1;
                line.EndPoint   = pt2;

                if (!layerId.IsNull)
                {
                    line.LayerId = layerId;
                }

                return(line);
            }
        }
Exemple #6
0
        public static Polyline CreatePolyLine(Database db, bool closed, params Curve[] entities)
        {
            using (CurrentDB curr = new CurrentDB(db))
            {
                Polyline pline = new Polyline(1);
                pline.TransformBy(entities[0].Ecs);
                Point3d start = entities[0].StartPoint.TransformBy(pline.Ecs.Inverse());
                pline.AddVertexAt(0, new Point2d(start.X, start.Y), 0, 0, 0);

                pline.JoinEntities(entities);

                pline.Closed = closed;

                pline.SetDatabaseDefaults(db);
                pline.SetPropertiesFrom(entities[0]);

                return(pline);
            }
        }
Exemple #7
0
        public static Circle CreateCircle(Database db, Point3d center, double radius, Vector3d normal, ObjectId layerId)
        {
            using (CurrentDB curr = new CurrentDB(db))
            {
                Circle circle = new Circle();
                circle.SetDatabaseDefaults(db);

                circle.Center = center;
                circle.Radius = radius;
                circle.Normal = normal;

                if (!layerId.IsNull)
                {
                    circle.LayerId = layerId;
                }

                return(circle);
            }
        }
Exemple #8
0
        public static Hatch CreateHatch(Database db, string patternName, double patternScale, double patternAngle)
        {
            using (CurrentDB curr = new CurrentDB(db))
            {
                Matrix3d ucs2wcs = AcadGraphics.UcsToWcs;

                Hatch hatch = new Hatch();
                hatch.SetDatabaseDefaults(db);

                hatch.SetHatchPattern(HatchPatternType.PreDefined, patternName);

                hatch.Normal       = ucs2wcs.CoordinateSystem3d.Zaxis;
                hatch.Elevation    = 0.0;
                hatch.PatternScale = patternScale;
                hatch.PatternAngle = patternAngle;

                hatch.SetHatchPattern(HatchPatternType.PreDefined, patternName);

                return(hatch);
            }
        }
Exemple #9
0
        public static Arc CreateArc(Database db, Point3d center, double radius, double startAngle, double endAngle, Vector3d normal, ObjectId layerId)
        {
            using (CurrentDB curr = new CurrentDB(db))
            {
                Arc arc = new Arc(center, normal, radius, startAngle, endAngle);
                arc.SetDatabaseDefaults(db);

                arc.Center     = center;
                arc.Radius     = radius;
                arc.Normal     = normal;
                arc.StartAngle = startAngle;
                arc.EndAngle   = endAngle;

                if (!layerId.IsNull)
                {
                    arc.LayerId = layerId;
                }

                return(arc);
            }
        }
Exemple #10
0
        public static Polyline CreatePolyLine(Database db, bool closed, Point2dCollection points)
        {
            using (CurrentDB curr = new CurrentDB(db))
            {
                Matrix3d ucs2wcs = AcadGraphics.UcsToWcs;

                Polyline pline = new Polyline(1);
                pline.SetDatabaseDefaults(db);
                pline.Normal = ucs2wcs.CoordinateSystem3d.Zaxis;
                pline.AddVertexAt(0, new Point2d(0, 0), 0, 0, 0);
                Plane plinePlane = new Plane(Point3d.Origin, pline.Normal);
                pline.Reset(false, points.Count);
                foreach (Point2d pt in points)
                {
                    Point2d ecsPt = plinePlane.ParameterOf(new Point3d(pt.X, pt.Y, 0)); // Convert to ECS
                    pline.AddVertexAt(pline.NumberOfVertices, ecsPt, 0, 0, 0);
                }
                pline.Closed = closed;

                return(pline);
            }
        }
Exemple #11
0
 public static void EraseEntities(Database db, IEnumerable <ObjectId> items)
 {
     using (CurrentDB curr = new CurrentDB(db))
     {
         using (Transaction tr = db.TransactionManager.StartTransaction())
         {
             try
             {
                 foreach (ObjectId id in items)
                 {
                     DBObject item = tr.GetObject(id, OpenMode.ForWrite);
                     item.Erase();
                 }
             }
             catch
             {
                 ;
             }
             tr.Commit();
         }
     }
 }
Exemple #12
0
        public static AttributeDefinition CreateAttribute(Database db, Point3d pt, string tag, string prompt, string text, double textHeight, double rotation, double widthFactor, TextHorizontalMode horizontalMode, TextVerticalMode verticalMode, ObjectId textStyleId, ObjectId layerId)
        {
            using (CurrentDB curr = new CurrentDB(db))
            {
                AttributeDefinition attdef = new AttributeDefinition();
                attdef.SetDatabaseDefaults(db);

                attdef.Tag        = tag;
                attdef.Prompt     = prompt;
                attdef.TextString = text;
                attdef.Position   = pt;

                attdef.Height      = textHeight;
                attdef.Rotation    = rotation;
                attdef.WidthFactor = widthFactor;

                if (horizontalMode == TextHorizontalMode.TextLeft)
                {
                    if (verticalMode == TextVerticalMode.TextTop)
                    {
                        attdef.Justify = AttachmentPoint.TopLeft;
                    }
                    else if (verticalMode == TextVerticalMode.TextBase)
                    {
                        attdef.Justify = AttachmentPoint.BaseLeft;
                    }
                    else if (verticalMode == TextVerticalMode.TextBottom)
                    {
                        attdef.Justify = AttachmentPoint.BottomLeft;
                    }
                    else
                    {
                        attdef.Justify = AttachmentPoint.MiddleLeft;
                    }
                }
                else if (horizontalMode == TextHorizontalMode.TextRight)
                {
                    if (verticalMode == TextVerticalMode.TextTop)
                    {
                        attdef.Justify = AttachmentPoint.TopRight;
                    }
                    else if (verticalMode == TextVerticalMode.TextBase)
                    {
                        attdef.Justify = AttachmentPoint.BaseRight;
                    }
                    else if (verticalMode == TextVerticalMode.TextBottom)
                    {
                        attdef.Justify = AttachmentPoint.BottomRight;
                    }
                    else
                    {
                        attdef.Justify = AttachmentPoint.MiddleRight;
                    }
                }
                else if (horizontalMode == TextHorizontalMode.TextMid || horizontalMode == TextHorizontalMode.TextCenter)
                {
                    if (verticalMode == TextVerticalMode.TextTop)
                    {
                        attdef.Justify = AttachmentPoint.TopCenter;
                    }
                    else if (verticalMode == TextVerticalMode.TextBase)
                    {
                        attdef.Justify = AttachmentPoint.BaseCenter;
                    }
                    else if (verticalMode == TextVerticalMode.TextBottom)
                    {
                        attdef.Justify = AttachmentPoint.BottomCenter;
                    }
                    else
                    {
                        attdef.Justify = AttachmentPoint.MiddleCenter;
                    }
                }
                else if (horizontalMode == TextHorizontalMode.TextAlign)
                {
                    if (verticalMode == TextVerticalMode.TextTop)
                    {
                        attdef.Justify = AttachmentPoint.TopAlign;
                    }
                    else if (verticalMode == TextVerticalMode.TextBase)
                    {
                        attdef.Justify = AttachmentPoint.BaseAlign;
                    }
                    else if (verticalMode == TextVerticalMode.TextBottom)
                    {
                        attdef.Justify = AttachmentPoint.BottomAlign;
                    }
                    else
                    {
                        attdef.Justify = AttachmentPoint.MiddleAlign;
                    }
                }
                else if (horizontalMode == TextHorizontalMode.TextFit)
                {
                    if (verticalMode == TextVerticalMode.TextTop)
                    {
                        attdef.Justify = AttachmentPoint.TopFit;
                    }
                    else if (verticalMode == TextVerticalMode.TextBase)
                    {
                        attdef.Justify = AttachmentPoint.BaseFit;
                    }
                    else if (verticalMode == TextVerticalMode.TextBottom)
                    {
                        attdef.Justify = AttachmentPoint.BottomFit;
                    }
                    else
                    {
                        attdef.Justify = AttachmentPoint.MiddleFit;
                    }
                }

                if (horizontalMode != TextHorizontalMode.TextLeft || verticalMode != TextVerticalMode.TextBase)
                {
                    attdef.AlignmentPoint = pt;
                    attdef.AdjustAlignment(db);
                }

                if (!textStyleId.IsNull)
                {
                    attdef.TextStyleId = textStyleId;
                }

                if (!layerId.IsNull)
                {
                    attdef.LayerId = layerId;
                }

                return(attdef);
            }
        }
Exemple #13
0
        public static DBText CreateText(Database db, Point3d pt, string text, double textHeight, double rotation, double widthFactor, TextHorizontalMode horizontalMode, TextVerticalMode verticalMode, ObjectId textStyleId, ObjectId layerId)
        {
            using (CurrentDB curr = new CurrentDB(db))
            {
                DBText dbtext = new DBText();
                dbtext.SetDatabaseDefaults(db);

                dbtext.TextString = text;
                dbtext.Position   = pt;

                dbtext.Height      = textHeight;
                dbtext.Rotation    = rotation;
                dbtext.WidthFactor = widthFactor;

                if (horizontalMode == TextHorizontalMode.TextLeft)
                {
                    if (verticalMode == TextVerticalMode.TextTop)
                    {
                        dbtext.Justify = AttachmentPoint.TopLeft;
                    }
                    else if (verticalMode == TextVerticalMode.TextBase)
                    {
                        dbtext.Justify = AttachmentPoint.BaseLeft;
                    }
                    else if (verticalMode == TextVerticalMode.TextBottom)
                    {
                        dbtext.Justify = AttachmentPoint.BottomLeft;
                    }
                    else
                    {
                        dbtext.Justify = AttachmentPoint.MiddleLeft;
                    }
                }
                else if (horizontalMode == TextHorizontalMode.TextRight)
                {
                    if (verticalMode == TextVerticalMode.TextTop)
                    {
                        dbtext.Justify = AttachmentPoint.TopRight;
                    }
                    else if (verticalMode == TextVerticalMode.TextBase)
                    {
                        dbtext.Justify = AttachmentPoint.BaseRight;
                    }
                    else if (verticalMode == TextVerticalMode.TextBottom)
                    {
                        dbtext.Justify = AttachmentPoint.BottomRight;
                    }
                    else
                    {
                        dbtext.Justify = AttachmentPoint.MiddleRight;
                    }
                }
                else if (horizontalMode == TextHorizontalMode.TextMid || horizontalMode == TextHorizontalMode.TextCenter)
                {
                    if (verticalMode == TextVerticalMode.TextTop)
                    {
                        dbtext.Justify = AttachmentPoint.TopCenter;
                    }
                    else if (verticalMode == TextVerticalMode.TextBase)
                    {
                        dbtext.Justify = AttachmentPoint.BaseCenter;
                    }
                    else if (verticalMode == TextVerticalMode.TextBottom)
                    {
                        dbtext.Justify = AttachmentPoint.BottomCenter;
                    }
                    else
                    {
                        dbtext.Justify = AttachmentPoint.MiddleCenter;
                    }
                }
                else if (horizontalMode == TextHorizontalMode.TextAlign)
                {
                    if (verticalMode == TextVerticalMode.TextTop)
                    {
                        dbtext.Justify = AttachmentPoint.TopAlign;
                    }
                    else if (verticalMode == TextVerticalMode.TextBase)
                    {
                        dbtext.Justify = AttachmentPoint.BaseAlign;
                    }
                    else if (verticalMode == TextVerticalMode.TextBottom)
                    {
                        dbtext.Justify = AttachmentPoint.BottomAlign;
                    }
                    else
                    {
                        dbtext.Justify = AttachmentPoint.MiddleAlign;
                    }
                }
                else if (horizontalMode == TextHorizontalMode.TextFit)
                {
                    if (verticalMode == TextVerticalMode.TextTop)
                    {
                        dbtext.Justify = AttachmentPoint.TopFit;
                    }
                    else if (verticalMode == TextVerticalMode.TextBase)
                    {
                        dbtext.Justify = AttachmentPoint.BaseFit;
                    }
                    else if (verticalMode == TextVerticalMode.TextBottom)
                    {
                        dbtext.Justify = AttachmentPoint.BottomFit;
                    }
                    else
                    {
                        dbtext.Justify = AttachmentPoint.MiddleFit;
                    }
                }

                if (horizontalMode != TextHorizontalMode.TextLeft || verticalMode != TextVerticalMode.TextBase)
                {
                    dbtext.AlignmentPoint = pt;
                    dbtext.AdjustAlignment(db);
                }

                if (!textStyleId.IsNull)
                {
                    dbtext.TextStyleId = textStyleId;
                }

                if (!layerId.IsNull)
                {
                    dbtext.LayerId = layerId;
                }

                return(dbtext);
            }
        }