Ejemplo n.º 1
0
        addBlockRef(string strName, string strTop, string strMid, string strBot, Point3d pnt3dIns, double dblRotation)
        {
            Database DB = BaseObjs._db;
            Editor   ED = BaseObjs._editor;

            BlockTableRecord Btrx = null;
            BlockReference   BR   = null;

            try
            {
                using (Transaction tr = BaseObjs.startTransactionDb())
                {
                    BlockTable BT = (BlockTable)DB.BlockTableId.GetObject(OpenMode.ForRead);
                    if (!BT.Has(strName))
                    {
                        Btrx = addBtr(strName);
                        Blocks.addAttributesToBlock(strName);
                    }
                    else
                    {
                        Btrx = (BlockTableRecord)BT[strName].GetObject(OpenMode.ForRead);
                    }

                    //---> debug only
                    foreach (ObjectId objID in Btrx)
                    {
                        Entity ENT             = (Entity)objID.GetObject(OpenMode.ForRead);
                        AttributeDefinition AD = ENT as AttributeDefinition;

                        if (AD != null)
                        {
                            ED.WriteMessage(string.Format("\n{0}", AD.Tag));
                        }
                    }//<--- debug only

                    //BlockTableRecord Btr = (BlockTableRecord)DB.CurrentSpaceId.GetObject(OpenMode.ForWrite);

                    Btrx.UpgradeOpen();

                    using (Btrx)
                    {
                        BR = new BlockReference(pnt3dIns, Btrx.ObjectId);
                        using (BR)
                        {
                            Matrix3d           UCSMatrix = ED.CurrentUserCoordinateSystem;
                            CoordinateSystem3d UCS       = UCSMatrix.CoordinateSystem3d;

                            Matrix3d MAT3d = new Matrix3d();
                            MAT3d = Matrix3d.Rotation(dblRotation, UCS.Zaxis, pnt3dIns);

                            BR.TransformBy(MAT3d);
                            BR.ScaleFactors = new Scale3d(1, 1, 1);
                            Btrx.AppendEntity(BR);
                            tr.AddNewlyCreatedDBObject(BR, true);

                            BlockTableRecord Btratt = (BlockTableRecord)BR.BlockTableRecord.GetObject(OpenMode.ForRead);
                            using (Btratt)
                            {
                                Autodesk.AutoCAD.DatabaseServices.AttributeCollection ATTcol = BR.AttributeCollection;

                                foreach (ObjectId subID in Btratt)
                                {
                                    Entity ENT             = (Entity)subID.GetObject(OpenMode.ForRead);
                                    AttributeDefinition AD = ENT as AttributeDefinition;

                                    if (AD != null)
                                    {
                                        AttributeReference AR = new AttributeReference();
                                        AR.SetPropertiesFrom(AD);
                                        AR.SetAttributeFromBlock(AD, BR.BlockTransform);
                                        AR.Visible = AD.Visible;

                                        AR.HorizontalMode = AD.HorizontalMode;
                                        AR.VerticalMode   = AD.VerticalMode;
                                        AR.Rotation       = AD.Rotation;
                                        AR.TextStyleId    = AD.TextStyleId;
                                        AR.Position       = AD.Position + pnt3dIns.GetAsVector();
                                        AR.Tag            = AD.Tag;
                                        AR.FieldLength    = AD.FieldLength;
                                        AR.AdjustAlignment(DB);

                                        if (AR.Tag == "TOPTXT")
                                        {
                                            AR.TextString = strTop;
                                        }

                                        if (AR.Tag == "MIDTXT")
                                        {
                                            AR.TextString = strMid;
                                        }

                                        if (AR.Tag == "BOTTXT")
                                        {
                                            AR.TextString = strBot;
                                        }

                                        AR.Position = AD.Position.TransformBy(BR.BlockTransform);

                                        ATTcol.AppendAttribute(AR);
                                        tr.AddNewlyCreatedDBObject(AR, true);
                                    }
                                }
                            }
                            BR.DowngradeOpen();
                        }

                        Btrx.DowngradeOpen();
                    }
                    tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " Blocks.cs: line: 305");
            }
            return(BR);
        }
Ejemplo n.º 2
0
        addSymbolAndWipeout(Point3d pnt3d, double angleView, out ObjectId idWO, double radius, int numSides, bool addWipeOut = false)
        {
            ObjectId idSYM = ObjectId.Null;

            double            pi         = System.Math.PI;
            double            pi2        = pi * 2.0;
            double            angleBase  = 0;
            double            length     = 0;
            double            delta      = 0;
            double            scale      = Misc.getCurrAnnoScale();
            double            deltaBegin = 0;
            Point2d           pnt2dBase  = Point2d.Origin;
            Point2dCollection pnts2d     = new Point2dCollection();
            Point2d           pnt2dCen   = new Point2d(pnt3d.X, pnt3d.Y);

            delta = 2 * pi / numSides;
            idWO  = ObjectId.Null;

            switch (numSides)
            {
            case 3:
                length    = 1.33 * scale * 2 * radius;
                pnt2dBase = pnt2dCen.traverse(angleView - pi / 2, length / 4);
                pnt2dBase = pnt2dBase.traverse(angleView, length / 2);
                pnts2d.Add(pnt2dBase);
                deltaBegin = delta + angleView;
                break;

            case 4:
                angleBase = angleView + 7.0 / 8.0 * pi2;
                length    = 0.5 * 1.68 * scale * radius * System.Math.Sqrt(2);
                pnt2dBase = pnt2dCen.traverse(angleBase, length);
                pnts2d.Add(pnt2dBase);
                length     = scale * 1.68 * radius;
                deltaBegin = delta + angleView;
                break;

            case 6:
                angleBase = angleView + 10.0 / 12.0 * pi2;
                //angleBase = angleView;
                length    = 1.03 * scale * radius / System.Math.Cos(delta / 3);
                pnt2dBase = pnt2dCen.traverse(angleBase, length);
                pnts2d.Add(pnt2dBase);     //pnt0
                deltaBegin = angleBase + 2 * delta;
                break;

            case 1024:
                //angleBase = angleView + 3.0 / 2.0 * pi;
                angleBase = angleView;
                length    = scale * 2.0 * radius * System.Math.Sin(delta / 2);
                pnt2dBase = pnt2dCen.traverse(angleBase, scale * radius);
                pnts2d.Add(pnt2dBase);
                deltaBegin = angleBase + delta + pi / 2;
                break;

            default:
                break;
            }

            //adjust first segment to account for viewtwist
            pnt2dBase = pnt2dBase.traverse(deltaBegin, length);
            pnts2d.Add(pnt2dBase); //pnt1
            //pnt2dBase.addPointNode(34, 0.01);

            double deltaTotal = deltaBegin;

            //from then on it is
            for (int i = 1; i < numSides; i++)
            {
                deltaTotal = deltaTotal + delta;
                pnt2dBase  = pnt2dBase.traverse(deltaTotal, length);
                pnts2d.Add(pnt2dBase); //pnts 2-6
                //pnt2dBase.addPointNode(34, 0.01);
            }

            if (numSides < 1024)
            {
                idSYM = addPoly(pnts2d, "BUBBLE", 5);
            }
            else
            {
                idSYM = Draw.addCircle(pnt3d, scale * radius, "BUBBLE", 5);
            }

            if (addWipeOut)
            {
                Wipeout wo = new Wipeout();
                try
                {
                    using (Transaction tr = BaseObjs.startTransactionDb())
                    {
                        BlockTableRecord ms = Blocks.getBlockTableRecordMS();
                        wo.SetFrom(pnts2d, Vector3d.ZAxis);
                        wo.Layer = "BUBBLE";
                        wo.Color = Color.FromColorIndex(ColorMethod.ByBlock, 8);
                        ms.AppendEntity(wo);
                        tr.AddNewlyCreatedDBObject(wo, true);
                        idWO = wo.ObjectId;
                        tr.Commit();
                    }
                }
                catch (System.Exception ex)
                {
                    BaseObjs.writeDebug(ex.Message + " Draw.cs: line: 804");
                }
            }

            return(idSYM);
        }