Beispiel #1
0
        getCogoPoint(string prompt1, out ObjectId idCgPnt, ObjectId idCgPntBase, int osMode)
        {
            Object   mode      = SnapMode.getOSnap();
            string   elev      = string.Empty;
            ObjectId idCogoPnt = ObjectId.Null;

            idCgPnt = ObjectId.Null;

            Point3d pnt3dBase = Pub.pnt3dO;
            Point3d pnt3dX    = Pub.pnt3dO;

            if (idCgPntBase != ObjectId.Null)
            {
                pnt3dBase = idCgPntBase.getCogoPntCoordinates();
            }

            bool         escape;
            PromptStatus ps;

            try
            {
                if (pnt3dBase != Pub.pnt3dO)
                {
                    pnt3dX = UserInput.getPoint(prompt1, pnt3dBase, out escape, out ps, osMode);
                }
                else
                {
                    pnt3dX = UserInput.getPoint(prompt1, out ps, osMode);
                }

                if (pnt3dX == Pub.pnt3dO)
                {
                    return(elev);
                }

                ObjectIdCollection ids = new ObjectIdCollection();
                BaseObjs._db.forEachMS <CogoPoint>(cg =>
                {
                    if (cg.Location == pnt3dX)
                    {
                        idCogoPnt = cg.ObjectId;
                        ids.Add(idCogoPnt);
                    }
                });

                switch (ids.Count)
                {
                case 0:
                    break;

                case 1:
                    elev    = string.Format("{0:F2}", idCogoPnt.getCogoPntElevation());
                    idCgPnt = idCogoPnt;
                    break;

                case 2:
                    Application.ShowAlertDialog("Multiple CogoPoints at same location. Exiting...");
                    break;
                }
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " UserInput.cs: line: 384");
            }
            finally
            {
                SnapMode.setOSnap((int)mode);
            }

            return(elev);
        }
Beispiel #2
0
        addUCS(Point3d pnt3dOrigin, Point3d pnt3dXaxis, Point3d pnt3dYaxis, string nameUCS)
        {
            Matrix3d newMatrix = new Matrix3d();

            try
            {
                using (Transaction tr = BaseObjs.startTransactionDb())
                {
                    // Open the UCS table for read
                    UcsTable       ucsT = tr.GetObject(BaseObjs._db.UcsTableId, OpenMode.ForRead) as UcsTable;
                    UcsTableRecord ucstr;

                    Vector3d vector3dXaxis = new Vector3d(pnt3dXaxis.X - pnt3dOrigin.X, pnt3dXaxis.Y - pnt3dOrigin.Y, pnt3dXaxis.Z - pnt3dOrigin.Z);
                    Vector3d vector3dYaxis = new Vector3d(pnt3dYaxis.X - pnt3dOrigin.X, pnt3dYaxis.Y - pnt3dOrigin.Y, pnt3dYaxis.Z - pnt3dOrigin.Z);

                    Vector3d vector3dZ = vector3dXaxis.CrossProduct(vector3dYaxis);
                    Vector3d vector3dY = vector3dZ.CrossProduct(vector3dXaxis);

                    Vector3d vector3dPerpY = new Vector3d(vector3dY.X + pnt3dOrigin.X, vector3dY.Y + pnt3dOrigin.Y, vector3dY.Z + pnt3dOrigin.Z);

                    // Check to see if the nameUCS UCS table record exists
                    if (ucsT.Has(nameUCS) == false)
                    {
                        ucstr      = new UcsTableRecord();
                        ucstr.Name = nameUCS;

                        // Open the UCSTable for write
                        ucsT.UpgradeOpen();

                        // Add the new UCS table record
                        ucsT.Add(ucstr);
                        tr.AddNewlyCreatedDBObject(ucstr, true);
                    }
                    else
                    {
                        ucstr = (UcsTableRecord)tr.GetObject(ucsT[nameUCS], OpenMode.ForWrite);
                    }

                    ucstr.Origin = pnt3dOrigin;
                    ucstr.XAxis  = vector3dXaxis;
                    ucstr.YAxis  = vector3dPerpY;

                    // Open the active viewport
                    ViewportTableRecord vptr;
                    vptr = (ViewportTableRecord)tr.GetObject(BaseObjs._editor.ActiveViewportId, OpenMode.ForWrite);

                    // Display the UCS Icon at the origin of the current viewport
                    vptr.IconAtOrigin = true;
                    vptr.IconEnabled  = true;

                    // Set the UCS current
                    vptr.SetUcs(ucstr.ObjectId);
                    BaseObjs._editor.UpdateTiledViewportsFromDatabase();

                    newMatrix = Matrix3d.AlignCoordinateSystem(Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis,
                                                               vptr.Ucs.Origin, vptr.Ucs.Xaxis, vptr.Ucs.Yaxis, vptr.Ucs.Zaxis);
                    tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " UCsys.cs: line: 149");
            }
            return(newMatrix);
        }
Beispiel #3
0
        addBlockRef(string strName, Point3d pnt3dIns, double dblRotation, List <string> attValues)
        {
            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);
                    }
                    else
                    {
                        btrx = (BlockTableRecord)bt[strName].GetObject(OpenMode.ForRead);
                    }

                    //---> debug only
                    foreach (ObjectId idObj in btrx)
                    {
                        Entity ent             = (Entity)idObj.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: 194");
            }
            return(br);
        }
Beispiel #4
0
        getNestedEntityAndHighlight(Point3d pnt3d, BlockReference br, out FullSubentityPath path, out bool isClosed)
        {
            Entity ent = null;

            isClosed = false;
            path     = new FullSubentityPath();

            Editor ed = BaseObjs._editor;

            PromptNestedEntityOptions pneo = new PromptNestedEntityOptions("");

            pneo.NonInteractivePickPoint    = pnt3d;
            pneo.UseNonInteractivePickPoint = true;
            PromptNestedEntityResult pner = ed.GetNestedEntity(pneo);

            try
            {
                using (Transaction tr = BaseObjs.startTransactionDb())
                {
                    if (pner.Status == PromptStatus.OK)
                    {
                        ObjectId[] idsContainers = pner.GetContainers();
                        ObjectId   idSel         = pner.ObjectId;
                        int        len           = idsContainers.Length;

                        ObjectId[] idsRev = new ObjectId[len + 1];
                        //Reverse the "containers" list
                        for (int i = 0; i < len; i++)
                        {
                            ObjectId id = (ObjectId)idsContainers.GetValue(len - i - 1);
                            idsRev.SetValue(id, i);
                        }
                        //Now add the selected entity to the end of the array
                        idsRev.SetValue(idSel, len);

                        //Retrieve the sub-entity path for this entity
                        SubentityId idSubEnt = new SubentityId(SubentityType.Null, (IntPtr)0);
                        path = new FullSubentityPath(idsRev, idSubEnt);

                        ObjectId idX = (ObjectId)idsRev.GetValue(0);
                        ent = (Entity)tr.GetObject(idX, OpenMode.ForRead);

                        DBObject obj = idSel.GetObject(OpenMode.ForRead);

                        ObjectId idOwner   = ObjectId.Null;
                        DBObject objParent = null;

                        if (obj is PolylineVertex3d)
                        {
                            idOwner   = obj.OwnerId;
                            objParent = (Polyline3d)idOwner.GetObject(OpenMode.ForRead);
                            Polyline3d poly3d = (Polyline3d)obj;
                            poly3d.Highlight(path, false);
                            isClosed = poly3d.Closed;
                        }
                        else if (obj is Vertex2d)
                        {
                            idOwner   = obj.OwnerId;
                            objParent = (Polyline)idOwner.GetObject(OpenMode.ForRead);
                            Polyline poly = (Polyline)obj;
                            poly.Highlight(path, false);
                            isClosed = poly.Closed;
                        }
                        else if (obj is Polyline3d)
                        {
                            objParent = obj;
                            Polyline3d poly3d = (Polyline3d)obj;
                            poly3d.Highlight(path, false);
                            isClosed = poly3d.Closed;
                        }
                        else if (obj is Polyline)
                        {
                            objParent = obj;
                            Polyline poly = (Polyline)obj;
                            poly.Highlight(path, false);
                            isClosed = poly.Closed;
                        }
                        else if (obj is Arc)
                        {
                            objParent = obj;
                            Arc arc = (Arc)obj;
                            arc.Highlight(path, false);
                            isClosed = false;
                        }
                        else if (obj is MText || obj is DBText)
                        {
                            return(null);
                        }

                        ent = (Entity)objParent;
                    }
                    tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " xRef2.cs: line: 108");
            }
            return(ent);
        }
Beispiel #5
0
        addAttributesToBlock(string strName)
        {
            Database             DB   = BaseObjs._db;
            TextStyleTableRecord tstr = Base_Tools45.Txt.getTextStyleTableRecord("ANNO");

            try
            {
                using (Transaction tr = BaseObjs.startTransactionDb())
                {
                    BlockTable       BT  = (BlockTable)DB.BlockTableId.GetObject(OpenMode.ForWrite);
                    BlockTableRecord Btr = (BlockTableRecord)BT[strName].GetObject(OpenMode.ForWrite);

                    Point3d pntTop = new Point3d(0, 0.01, 0);
                    Point3d pntMid = new Point3d(0, -0.10, 0);
                    Point3d pntBot = new Point3d(0, -0.20, 0);

                    var AD = new AttributeDefinition();
                    AD.SetDatabaseDefaults();
                    AD.Tag      = "TOPTXT";
                    AD.Prompt   = "\nEnter Grade and Desc";
                    AD.Position = pntTop;

                    //AD.AlignmentPoint = pntTop;
                    AD.Justify = AttachmentPoint.BottomCenter;

                    AD.TextStyleId = tstr.ObjectId;
                    AD.Layer       = "0";

                    Btr.AppendEntity(AD);
                    tr.AddNewlyCreatedDBObject(AD, true);

                    AD = new AttributeDefinition();
                    AD.SetDatabaseDefaults();
                    AD.Tag      = "MIDTXT";
                    AD.Prompt   = "\nEnter Grade and Desc";
                    AD.Position = pntMid;

                    //AD.AlignmentPoint = pntMid;
                    AD.Justify = AttachmentPoint.TopCenter;

                    AD.TextStyleId = tstr.ObjectId;
                    AD.Layer       = "0";

                    Btr.AppendEntity(AD);
                    tr.AddNewlyCreatedDBObject(AD, true);

                    AD = new AttributeDefinition();
                    AD.SetDatabaseDefaults();
                    AD.Tag      = "BOTTXT";
                    AD.Prompt   = "\nEnter Grade and Desc";
                    AD.Position = pntBot;

                    // AD.AlignmentPoint = pntBtm;
                    AD.Justify = AttachmentPoint.TopCenter;

                    AD.TextStyleId = tstr.ObjectId;
                    AD.Layer       = "0";

                    Btr.AppendEntity(AD);
                    tr.AddNewlyCreatedDBObject(AD, true);

                    tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " Blocks.cs: line: 85");
            }
        }
Beispiel #6
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);
        }
Beispiel #7
0
        addMText(string strCallout, Point3d pnt3d1, double dblRotation, double width, double txtSize = 0.09,
                 AttachmentPoint attachPnt  = AttachmentPoint.MiddleCenter, string nameStyle = "Annotative",
                 string nameLayer           = "TEXT", Color color = null, string justify = null,
                 AnnotativeStates annoState = AnnotativeStates.True,
                 double xFactor             = 0.8, bool bold = false,
                 bool backgroundFill        = false)
        {
            ObjectId idMtxt     = ObjectId.Null;
            ObjectId idTxtStyle = ObjectId.Null;
            Database DB         = BaseObjs._db;
            MText    mtext      = null;

            try
            {
                using (Transaction tr = BaseObjs.startTransactionDb())
                {
                    BlockTable       BT  = (BlockTable)tr.GetObject(DB.BlockTableId, OpenMode.ForRead);
                    BlockTableRecord MS  = (BlockTableRecord)tr.GetObject(BT[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                    TextStyleTable   TST = (TextStyleTable)tr.GetObject(DB.TextStyleTableId, OpenMode.ForRead);

                    if (!TST.Has(nameStyle))
                    {
                        idTxtStyle = makeTextStyle(nameStyle, annoState);
                    }
                    else
                    {
                        idTxtStyle = TST[nameStyle];
                        setTextStyleXScale(idTxtStyle, xFactor);
                    }

                    mtext = new MText();
                    mtext.SetDatabaseDefaults();

                    try
                    {
                        mtext.Layer = nameLayer;
                    }
                    catch (System.Exception ex)
                    {
                        BaseObjs.writeDebug(ex.Message + " Txt.cs: line: 61");
                    }

                    if (color == null)
                    {
                        color = new Color();
                        color = Color.FromColorIndex(ColorMethod.ByLayer, 256);
                    }

                    mtext.Color    = color;
                    mtext.Location = pnt3d1;

                    mtext.Rotation    = dblRotation;
                    mtext.Annotative  = annoState;
                    mtext.Width       = width;
                    mtext.TextStyleId = idTxtStyle;

                    mtext.TextHeight     = txtSize * Base_Tools45.Misc.getCurrAnnoScale();
                    mtext.BackgroundFill = backgroundFill;
                    if (backgroundFill)
                    {
                        mtext.BackgroundFillColor   = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByAci, 1);
                        mtext.UseBackgroundColor    = true;
                        mtext.BackgroundScaleFactor = 1.25;
                    }

                    if (justify == null)
                    {
                        justify = Pub.JUSTIFYLEFT;
                    }

                    string xScale = xFactor.ToString();

                    if (bold && xFactor != 0.8)
                    {
                        mtext.Contents = string.Format("{0}{{\\fromans.shx|b1|\\W{1};{2}}}", justify, xScale, strCallout);
                    }
                    else if (bold)
                    {
                        mtext.Contents = string.Format("{0}{{\\fromans.shx|b1|;{1}}}", justify, strCallout);
                    }
                    else
                    {
                        mtext.Contents = string.Format("{0}{{\\fromans.shx\\W{1};{2}}}", justify, xScale, strCallout);
                    }

                    mtext.Attachment = attachPnt;
                    MS.AppendEntity(mtext);
                    tr.AddNewlyCreatedDBObject(mtext, true);
                    idMtxt = mtext.ObjectId;
                    tr.Commit();
                }//end using
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " Txt.cs: line: 108");
            }
            return(idMtxt);
        }
Beispiel #8
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);
        }
Beispiel #9
0
        updateDesignCallout(Leader Ldr, string strApp)
        {
            Editor ED = BaseObjs._editor;

            ResultBuffer      RB     = null;
            Point3dCollection pnt3ds = new Point3dCollection();
            MText             mTxt   = null;

            try
            {
                using (Transaction tr = BaseObjs.startTransactionDb())
                {
                    RB = Ldr.GetXDataForApplication(strApp);
                    foreach (TypedValue TV in RB)
                    {
                        if (TV.TypeCode.ToString() == "1005")
                        {
                            string   strHandle = TV.Value.ToString();
                            ObjectId objID     = Misc.getObjectIdFromHandle(strHandle);
                            mTxt = (MText)tr.GetObject(objID, OpenMode.ForRead);
                            Events.deactivateMText("*", mTxt);
                            mTxt.UpgradeOpen();

                            double dblWidth = mTxt.ActualWidth;

                            for (int i = 0; i < Ldr.NumVertices; i++)
                            {
                                pnt3ds.Add(Ldr.VertexAt(i));
                            }

                            Point3d pnt3d1 = pnt3ds[1];
                            Point3d pnt3d2 = pnt3ds[2];
                            Point3d pnt3d3 = mTxt.Location;

                            double dblAngle = Base_Tools45.Measure.getAzRadians(pnt3d1, pnt3d2);

                            double  dblRotate   = Geom.getAngle3Points(pnt3d3, pnt3d1, pnt3d2);
                            Boolean isRightHand = Base_Tools45.Math.isRightHand(pnt3d3, pnt3d1, pnt3d2);
                            if (isRightHand != true)
                            {
                                dblRotate = -dblRotate;
                            }

                            Boolean Left_Justify = Base_Tools45.Math.left_Justify(dblAngle);

                            Point3d pnt3d = Base_Tools45.Math.traverse(pnt3ds[1], dblAngle, dblWidth / 2 + mTxt.ActualHeight * 0.1);

                            if (Left_Justify != true)
                            {
                                dblRotate = dblRotate + PI;
                            }

                            Matrix3d           curUCSMatrix = ED.CurrentUserCoordinateSystem;
                            CoordinateSystem3d curUCS       = curUCSMatrix.CoordinateSystem3d;

                            mTxt.TransformBy(Matrix3d.Rotation(dblRotate, curUCS.Zaxis, pnt3ds[1]));

                            mTxt.Location = mTxt.Location.TransformBy(Matrix3d.Displacement(mTxt.Location.GetVectorTo(pnt3d)));

                            Events.activateMText("*", mTxt);
                            pnt3d = Base_Tools45.Math.traverse(pnt3ds[1], dblAngle, dblWidth * 1.20);
                        }
                    }

                    tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " Mod.cs: line: 911");
            }
        }
Beispiel #10
0
        updateDesignCallout(CogoPoint cogoPnt, string strApp)
        {
            ResultBuffer RB = null;

            MText mText = null;

            string[] strLines;
            string[] strFieldsTop;
            string[] strFieldsBot;
            string   strCalloutX = "";

            string strElev = cogoPnt.Location.Z.ToString("#,###.00");

            try
            {
                using (Transaction tr = BaseObjs.startTransactionDb())
                {
                    RB = cogoPnt.GetXDataForApplication(strApp);

                    string strCallout0 = "";
                    foreach (TypedValue TV in RB)
                    {
                        if (TV.TypeCode.ToString() == "1005")
                        {
                            string   strHandle = TV.Value.ToString();
                            ObjectId objID     = Misc.getObjectIdFromHandle(strHandle);

                            Autodesk.AutoCAD.DatabaseServices.DBObject dbObj = tr.GetObject(objID, OpenMode.ForRead);

                            mText       = (MText)dbObj;
                            strCallout0 = mText.Contents;
                            if (strApp == "FL")
                            {
                                strLines    = Txt.splitLines(strCallout0);
                                strCalloutX = string.Format("{0}\\P{1}", strElev, strLines[1]);
                            }
                            if (strApp == "FF")
                            {
                                strLines     = Txt.splitLines(strCallout0);
                                strFieldsTop = Txt.splitFields(strLines[0], ' ');
                                strFieldsBot = Txt.splitFields(strLines[1], ' ');
                            }

                            if (strApp == "G")
                            {
                                strLines     = Txt.splitLines(strCallout0);
                                strFieldsTop = Txt.splitFields(strLines[0], ' ');
                                strFieldsBot = Txt.splitFields(strLines[1], ' ');
                            }

                            Events.deactivateMText("*", mText);
                            mText.UpgradeOpen();
                            mText.Contents = strCalloutX;
                            mText.DowngradeOpen();
                            Events.activateMText("*", mText);
                        }
                    }

                    RB = mText.GetXDataForApplication(strApp);
                    foreach (TypedValue TV in RB)
                    {
                        if (TV.TypeCode.ToString() == "1005")
                        {
                            string   strHandle = TV.Value.ToString();
                            ObjectId objID     = Misc.getObjectIdFromHandle(strHandle);

                            Autodesk.AutoCAD.DatabaseServices.DBObject dbObj = tr.GetObject(objID, OpenMode.ForRead);

                            Leader LDR = (Leader)dbObj;
                            Events.deactivateLdr("*", LDR);
                            LDR.UpgradeOpen();
                            LDR.SetVertexAt(0, new Point3d(cogoPnt.Location.X, cogoPnt.Location.Y, 0.0));
                            LDR.DowngradeOpen();
                            Events.activateLdr("*", LDR);
                        }
                    }

                    tr.Commit();
                }                //end using tr
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " Mod.cs: line: 1004");
            }
        }        //end updateDesignCallout
Beispiel #11
0
        editExistCalloutsByDatumAdj(SelectionSet SS, double dblAdj)
        {
            BlockReference BR = null;

            string strElev = string.Empty;
            double dblElev = 0.0;

            try
            {
                using (Transaction tr = BaseObjs.startTransactionDb())
                {
                    ObjectId[] objIDs = SS.GetObjectIds();
                    foreach (ObjectId objID in objIDs)
                    {
                        BR = (BlockReference)tr.GetObject(objID, OpenMode.ForWrite);

                        if (BR != null)
                        {
                            AttributeCollection AC = BR.AttributeCollection;
                            foreach (ObjectId arID in AC)
                            {
                                AttributeReference AR        = (AttributeReference)tr.GetObject(arID, OpenMode.ForWrite);
                                string             strAttVal = AR.TextString.ToString();
                                if (strAttVal != string.Empty)
                                {
                                    if (strAttVal.StartsWith("("))
                                    {
                                        if (strAttVal.Contains(" ") == true)
                                        {
                                            string[] strFields = Txt.splitFields(strAttVal, ' ');
                                            if (strFields[0] != string.Empty)
                                            {
                                                string strVal = strFields[0];

                                                strElev = strVal.Substring(1, strVal.Length - 1);

                                                Boolean boolDbl = double.TryParse(strElev, out dblElev);
                                                if (boolDbl == true)
                                                {
                                                    dblElev       = dblElev + dblAdj;
                                                    strElev       = dblElev.ToString();
                                                    strAttVal     = string.Format("({0} {1}", strElev, strFields[1]);
                                                    AR.TextString = strAttVal;
                                                    BR.Color      = Autodesk.AutoCAD.Colors.Color.FromRgb(255, 200, 200);
                                                }
                                            }
                                        }
                                        else
                                        {
                                            strElev = strAttVal.Substring(1, strAttVal.Length - 2);
                                            Boolean boolDbl = double.TryParse(strElev, out dblElev);
                                            if (boolDbl == true)
                                            {
                                                dblElev       = dblElev + dblAdj;
                                                strElev       = dblElev.ToString();
                                                strAttVal     = string.Format("({0})", strElev);
                                                AR.TextString = strAttVal;
                                                BR.Color      = Autodesk.AutoCAD.Colors.Color.FromRgb(255, 200, 200);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    tr.Commit();
                }                //end using tr
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " Mod.cs: line: 337");
            }
        }
Beispiel #12
0
        copyTextContentsToTextEnt(SelectionSet SS0, SelectionSet SSX)
        {
            string strContents = string.Empty;

            try
            {
                using (Transaction tr = BaseObjs.startTransactionDb())
                {
                    ObjectId[] objIDs = null;
                    ObjectId   objID0 = ObjectId.Null;
                    ObjectId   objIDX = ObjectId.Null;

                    objIDs = SS0.GetObjectIds();
                    if (objIDs.Length == 1)
                    {
                        objID0 = objIDs[0];
                        Autodesk.AutoCAD.DatabaseServices.DBObject dbObj0 = tr.GetObject(objID0, OpenMode.ForRead);
                        try
                        {
                            DBText TXT = (DBText)dbObj0;
                            if (TXT != null)
                            {
                                strContents = TXT.TextString.ToString();
                            }
                            else
                            {
                                MText mTXT = (MText)dbObj0;
                                if (mTXT != null)
                                {
                                    strContents = mTXT.Text.ToString();
                                }
                            }
                        }
                        catch (System.Exception ex)
                        {
                            BaseObjs.writeDebug(ex.Message + " Mod.cs: line: 192");
                        }
                    }

                    objIDs = SSX.GetObjectIds();
                    if (objIDs.Length == 1)
                    {
                        objIDX = objIDs[0];
                        Autodesk.AutoCAD.DatabaseServices.DBObject dbObjX = tr.GetObject(objIDX, OpenMode.ForWrite);
                        try
                        {
                            DBText TXT = (DBText)dbObjX;
                            if (TXT != null)
                            {
                                TXT.TextString = strContents;
                            }
                            else
                            {
                                MText mTXT = (MText)dbObjX;
                                if (mTXT != null)
                                {
                                    mTXT.Contents = strContents;
                                }
                            }
                        }
                        catch (System.Exception ex)
                        {
                            BaseObjs.writeDebug(ex.Message + " Mod.cs: line: 219");
                        }
                    }
                    else if (objIDs.Length > 1)
                    {
                        foreach (ObjectId objID in objIDs)
                        {
                            Autodesk.AutoCAD.DatabaseServices.DBObject dbObjX = tr.GetObject(objID, OpenMode.ForWrite);
                            try
                            {
                                DBText TXT = (DBText)dbObjX;
                                if (TXT != null)
                                {
                                    TXT.TextString = strContents;
                                }
                                else
                                {
                                    MText mTXT = (MText)dbObjX;
                                    if (mTXT != null)
                                    {
                                        mTXT.Contents = strContents;
                                    }
                                }
                            }
                            catch (System.Exception ex)
                            {
                                BaseObjs.writeDebug(ex.Message + " Mod.cs: line: 245");
                            }
                        }
                    }

                    tr.Commit();
                }                //end using
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " Mod.cs: line: 255");
            }
        }
Beispiel #13
0
        updateExistCallouts(SelectionSet SS)
        {
            ResultBuffer RB = null;

            BlockReference BR      = null;
            CogoPoint      cogoPnt = null;

            string strAppName = string.Empty;
            string strElev    = string.Empty;

            try
            {
                using (Transaction tr = BaseObjs.startTransactionDb())
                {
                    ObjectId[] objIDs = SS.GetObjectIds();
                    foreach (ObjectId objID in objIDs)
                    {
                        cogoPnt = (CogoPoint)tr.GetObject(objID, OpenMode.ForRead);
                        strElev = cogoPnt.Location.Z.ToString("#,###.00");

                        RB = cogoPnt.GetXDataForApplication("lblPnts");
                        if (RB != null)
                        {
                            strAppName = "lblPnts";
                        }
                        else
                        {
                            RB         = cogoPnt.GetXDataForApplication("lblPntsPT");
                            strAppName = "lblPntsPT";
                        }
                        if (RB != null)
                        {
                            try
                            {
                                foreach (TypedValue TV in RB)
                                {
                                    if (TV.TypeCode.ToString() == "1005")
                                    {
                                        try
                                        {
                                            string   strHandle = TV.Value.ToString();
                                            ObjectId brID      = Misc.getObjectIdFromHandle(strHandle);

                                            Autodesk.AutoCAD.DatabaseServices.DBObject dbObj = tr.GetObject(brID, OpenMode.ForRead);

                                            BR = (BlockReference)dbObj;
                                            if (BR != null)
                                            {
                                                AttributeCollection AC = BR.AttributeCollection;
                                                foreach (ObjectId arID in AC)
                                                {
                                                    AttributeReference AR        = (AttributeReference)tr.GetObject(arID, OpenMode.ForWrite);
                                                    string             strAttVal = AR.TextString.ToString();
                                                    if (strAttVal != string.Empty)
                                                    {
                                                        string[] strFields = Txt.splitFields(strAttVal, ' ');
                                                        if (strFields[0] != string.Empty)
                                                        {
                                                            string strVal = strFields[0];
                                                            if (strVal.StartsWith("("))
                                                            {
                                                                string  strChr = strVal[1].ToString();
                                                                int     num;
                                                                Boolean isNum = strChr.isInteger(out num);
                                                                if (isNum == true)
                                                                {
                                                                    strAttVal     = string.Format("({0} {1}", strElev, strFields[1]);
                                                                    AR.TextString = strAttVal;
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        catch (System.Exception ex)
                                        {
                                            BaseObjs.writeDebug(ex.Message + " Mod.cs: line: 1091");
                                        }
                                    }
                                }
                            }
                            catch (System.Exception ex)
                            {
                                BaseObjs.writeDebug(ex.Message + " Mod.cs: line: 1098");
                            }
                        }
                    }

                    tr.Commit();
                }                //end using tr
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " Mod.cs: line: 1108");
            }
        }        //end updateDesignCallout
Beispiel #14
0
        manageLayers(string strLayerName, short color = 256)
        {
            ObjectId idLayer = ObjectId.Null;
            Document doc     = Application.DocumentManager.MdiActiveDocument;
            Database DB      = doc.Database;
            bool     thawed;

            try
            {
                using (doc.LockDocument())
                {
                    using (Transaction tr = BaseObjs.startTransactionDb())
                    {
                        LayerTable       LT = (LayerTable)tr.GetObject(DB.LayerTableId, OpenMode.ForRead);
                        LayerTableRecord Ltr;
                        if (LT.Has(strLayerName) == false)
                        {
                            Ltr      = new LayerTableRecord();
                            Ltr.Name = strLayerName;
                            if (color != 0)
                            {
                                Ltr.Color = Color.FromColorIndex(ColorMethod.ByLayer, color);
                            }
                            LT.UpgradeOpen();
                            LT.Add(Ltr);
                            tr.AddNewlyCreatedDBObject(Ltr, true);
                            tr.Commit();
                            idLayer = Ltr.ObjectId;
                        }
                        else
                        {
                            Ltr       = tr.GetObject(LT[strLayerName], OpenMode.ForWrite) as LayerTableRecord;
                            Ltr.Color = Color.FromColorIndex(ColorMethod.ByLayer, color);
                            idLayer   = Ltr.ObjectId;

                            if (Ltr.IsFrozen)
                            {
                                LT.UpgradeOpen();
                                Ltr.IsFrozen = false;
                                thawed       = true;
                            }
                            else
                            {
                                thawed = false;
                            }
                            if (Ltr.IsOff)
                            {
                                if (thawed == false)
                                {
                                    LT.UpgradeOpen();
                                }
                                Ltr.IsOff = false;
                            }
                            tr.Commit();
                        }
                    } //end using
                }     //end using
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " Layer.cs: line: 307");
            }
            return(idLayer);
        }
Beispiel #15
0
        checkPointXData2Nodes(ObjectId idCogoPnt, ResultBuffer RBpnt, string nameApp)
        {
            try
            {
                List <Handle> handlesP3d = RBpnt.rb_handles();

                int i = 0;
                //Working with a list of unique non-zero handles
                foreach (Handle hP3d in handlesP3d)
                {
                    //GET BREAKLINE PER STORED HANDLES
                    Polyline3d poly3d = (Polyline3d)Db.handleToObject(hP3d.ToString());

                    if ((poly3d != null))
                    {
                        if (poly3d.Length != 0)
                        {
                            ResultBuffer  RBp3d       = poly3d.ObjectId.getXData(nameApp);
                            List <Handle> handlesPnts = RBp3d.rb_handles();
                            Handle        hPnt        = idCogoPnt.getHandle();
                            // if pnt handle is in poly3d handle list then check coordinates otherwise
                            Point3dCollection pnts3d       = poly3d.getCoordinates3d();
                            Point3d           pnt3dCogoPnt = hPnt.getCogoPntCoordinates();

                            if (System.Math.Round(pnts3d[0].X, 3) == System.Math.Round(pnt3dCogoPnt.X, 3) &&
                                System.Math.Round(pnts3d[0].Y, 3) == System.Math.Round(pnt3dCogoPnt.Y, 3))
                            {
                                if (pnts3d[0].Z != pnt3dCogoPnt.Z)
                                {
                                    poly3d.setBegPnt(pnt3dCogoPnt);
                                }
                                if (!handlesPnts.Contains(hPnt))
                                {
                                    handlesPnts.Add(hPnt);
                                    poly3d.ObjectId.setXData(handlesPnts, nameApp);
                                }
                            }
                            else if (System.Math.Round(pnts3d[1].X, 3) == System.Math.Round(pnt3dCogoPnt.X, 3) &&
                                     System.Math.Round(pnts3d[1].Y, 3) == System.Math.Round(pnt3dCogoPnt.Y, 3))
                            {
                                if (pnts3d[1].Z != pnt3dCogoPnt.Z)
                                {
                                    poly3d.setEndPnt(pnt3dCogoPnt);
                                }
                                if (!handlesPnts.Contains(hPnt))
                                {
                                    handlesPnts.Add(hPnt);
                                    poly3d.ObjectId.setXData(handlesPnts, nameApp);
                                }
                            }
                            else
                            {
                                poly3d.ObjectId.delete();
                                handlesP3d.RemoveAt(i);
                                RBpnt = handlesP3d.handles_RB(nameApp);
                                idCogoPnt.setXData(handlesP3d, nameApp);
                            }
                        }
                        else
                        {
                            poly3d.ObjectId.delete();
                            handlesP3d.RemoveAt(i);
                            RBpnt = handlesP3d.handles_RB(nameApp);
                            idCogoPnt.setXData(handlesP3d, nameApp);
                        }
                    }
                    else
                    {
                        //remove bad handle from list
                        handlesP3d.RemoveAt(i);
                        RBpnt = handlesP3d.handles_RB(nameApp);
                        idCogoPnt.setXData(handlesP3d, nameApp);
                    }
                    i++;
                }
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " xData.cs: line: 145");
            }
            return(RBpnt);
        }