Exemple #1
0
        private void createX(_Db.BlockTableRecord btr, double radius, _Ge.Point3d ip)
        {
            _Ge.Point2d p1 = new _Ge.Point2d(ip.X - radius, ip.Y);
            _Ge.Point2d p2 = new _Ge.Point2d(ip.X + radius, ip.Y);
            _Ge.Point2d p3 = new _Ge.Point2d(ip.X, ip.Y - radius);
            _Ge.Point2d p4 = new _Ge.Point2d(ip.X, ip.Y + radius);

            using (_Db.Polyline poly = new _Db.Polyline())
            {
                poly.AddVertexAt(0, p1, 0, 0, 0);
                poly.AddVertexAt(1, p2, 0, 0, 0);
                poly.ColorIndex = 2;

                btr.AppendEntity(poly);
                _c.trans.AddNewlyCreatedDBObject(poly, true);
            }

            using (_Db.Polyline poly = new _Db.Polyline())
            {
                poly.AddVertexAt(0, p3, 0, 0, 0);
                poly.AddVertexAt(1, p4, 0, 0, 0);
                poly.ColorIndex = 2;

                btr.AppendEntity(poly);
                _c.trans.AddNewlyCreatedDBObject(poly, true);
            }
        }
Exemple #2
0
        public static void ManualInsertMText(AcDb.MText oMText)
        {
            using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
            {
                AcDb.BlockTableRecord btr = (AcDb.BlockTableRecord)tr.GetObject(db.CurrentSpaceId, AcDb.OpenMode.ForWrite);

                oMText.Normal = ed.CurrentUserCoordinateSystem.CoordinateSystem3d.Zaxis;

                btr.AppendEntity(oMText);
                tr.AddNewlyCreatedDBObject(oMText, true);

                MTextPlacementJig pj = new MTextPlacementJig(oMText);

                AcEd.PromptStatus stat = AcEd.PromptStatus.Keyword;
                while (stat == AcEd.PromptStatus.Keyword)
                {
                    AcEd.PromptResult res = ed.Drag(pj);
                    stat = res.Status;
                    if (stat != AcEd.PromptStatus.OK && stat != AcEd.PromptStatus.Keyword)
                    {
                        return;
                    }
                }
                tr.Commit();
                //return (MText)pj.Entity;
            }
        }
Exemple #3
0
        private void insertLine(_Ge.Point3d ptPos, double dir, double rotation)
        {
            _Db.BlockTableRecord btr = _c.trans.GetObject(_c.modelSpace.Id, _Db.OpenMode.ForWrite) as _Db.BlockTableRecord;

            _Ge.Point3d ptEnd = new _Ge.Point3d();

            if (rotation == 0.0)
            {
                double newX = ptPos.X - (bigCircleOffset - bigCircleRadius) * dir;
                double newY = ptPos.Y;
                ptEnd = new _Ge.Point3d(newX, newY, ptPos.Z);
            }
            else
            {
                double newX = ptPos.X;
                double newY = ptPos.Y - (bigCircleOffset - bigCircleRadius) * dir;
                ptEnd = new _Ge.Point3d(newX, newY, ptPos.Z);
            }

            using (_Db.Line line = new _Db.Line(ptPos, ptEnd))
            {
                btr.AppendEntity(line);
                _c.trans.AddNewlyCreatedDBObject(line, true);
            }
        }
Exemple #4
0
        private _Db.Viewport layoutViewportGetter(_Db.Layout lay)
        {
            _Db.ObjectIdCollection viewIds = lay.GetViewports();
            _Db.Viewport           vp      = null;

            foreach (_Db.ObjectId id in viewIds)
            {
                _Db.Viewport vp2 = _c.trans.GetObject(id, _Db.OpenMode.ForWrite) as _Db.Viewport;
                if (vp2 != null && vp2.Number == 2)
                {
                    vp = vp2;
                    break;
                }
            }

            if (vp == null)
            {
                _Db.BlockTableRecord btr = _c.trans.GetObject(lay.BlockTableRecordId, _Db.OpenMode.ForWrite) as _Db.BlockTableRecord;

                vp = new _Db.Viewport();

                btr.AppendEntity(vp);
                _c.trans.AddNewlyCreatedDBObject(vp, true);

                vp.On     = true;
                vp.GridOn = false;
            }

            return(vp);
        }
        public static void ManualInsertbAttribute(string nameBlock)
        {
            using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
            {
                AcDb.BlockTable blockTable = (AcDb.BlockTable)tr.GetObject(db.BlockTableId, AcDb.OpenMode.ForRead);
                if (!blockTable.Has(nameBlock))
                {
                    ed.WriteMessage("\nНезнайдено блок '{0}' у таблиці блоків креслення.", nameBlock);
                    return;
                }
                AcDb.BlockTableRecord curSpace       = (AcDb.BlockTableRecord)tr.GetObject(db.CurrentSpaceId, AcDb.OpenMode.ForWrite);
                AcDb.BlockReference   blockReference = new AcDb.BlockReference(AcGe.Point3d.Origin, blockTable[nameBlock]);
                blockReference.TransformBy(ed.CurrentUserCoordinateSystem);
                curSpace.AppendEntity(blockReference);
                tr.AddNewlyCreatedDBObject(blockReference, true);

                AcDb.BlockTableRecord btr = (AcDb.BlockTableRecord)tr.GetObject(blockTable[nameBlock], AcDb.OpenMode.ForRead);
                AcDb.DBText           text;
                foreach (AcDb.ObjectId id in btr)
                {
                    if (id.ObjectClass.Name == "AcDbAttributeDefinition")
                    {
                        AcDb.AttributeDefinition attDef =
                            (AcDb.AttributeDefinition)tr.GetObject(id, AcDb.OpenMode.ForRead);

                        text = new AcDb.DBText
                        {
                            TextString = "jig_test"
                        };

                        TextPlacementJig jig = new TextPlacementJig(text);

                        //PromptResult pr = ed.Drag(jig);

                        AcEd.PromptStatus stat = AcEd.PromptStatus.Keyword;
                        while (stat == AcEd.PromptStatus.Keyword)
                        {
                            AcEd.PromptResult pr = ed.Drag(jig);
                            stat = pr.Status;
                            if (stat != AcEd.PromptStatus.OK && stat != AcEd.PromptStatus.Keyword)
                            {
                                return;
                            }
                        }

                        AcDb.AttributeReference attRef = new AcDb.AttributeReference();
                        attRef.SetAttributeFromBlock(attDef, blockReference.BlockTransform);
                        AcDb.ObjectId attId = blockReference.AttributeCollection.AppendAttribute(attRef);
                        tr.AddNewlyCreatedDBObject(attRef, true);


                        tr.Commit();
                        //if (pr.Status != PromptStatus.OK) blockReference.Erase();
                    }
                }

                //tr.Commit();
            }
        }
Exemple #6
0
 private void createCircle(_Db.BlockTableRecord btr, double radius, _Ge.Point3d ip)
 {
     using (_Db.Circle circle = new _Db.Circle())
     {
         circle.Center     = ip;
         circle.Radius     = radius;
         circle.ColorIndex = 2;
         btr.AppendEntity(circle);
         _c.trans.AddNewlyCreatedDBObject(circle, true);
     }
 }
        public void TestTrans()
        {
            try
            {
                //System.Windows.Forms.MessageBox.Show(string.Format(CultureInfo.InvariantCulture, "_test = {0}", _test));
                //_test = 0;



                _AcDb.Database           db      = _AcAp.Application.DocumentManager.MdiActiveDocument.Database;
                _AcDb.TransactionManager dbTrans = db.TransactionManager;
                using (_AcDb.Transaction trans = dbTrans.StartTransaction())
                {
                    // create a line
                    _AcDb.Line       ln = new _AcDb.Line(new _AcGe.Point3d(0.0, 0.0, 0.0), new _AcGe.Point3d(1.0, 1.0, 0.0));
                    _AcDb.BlockTable bt = dbTrans.GetObject(db.BlockTableId, _AcDb.OpenMode.ForRead, false) as _AcDb.BlockTable;
                    if (bt == null)
                    {
                        return;
                    }
                    //ObjectId id = bt[BlockTableRecord.ModelSpace];
                    _AcDb.BlockTableRecord btr = dbTrans.GetObject(bt[_AcDb.BlockTableRecord.ModelSpace], _AcDb.OpenMode.ForWrite, false) as _AcDb.BlockTableRecord;
                    if (btr == null)
                    {
                        return;
                    }
                    //Add it to the model space block table record.
                    btr.AppendEntity(ln);
                    //Make sure that the transaction knows about this new object.    tm.AddNewlyCreatedDBObject(line, True)
                    dbTrans.AddNewlyCreatedDBObject(ln, true);


                    //'Add some hyperlinks.    Dim hyper As New HyperLink()    hyper.Name = "www.autodesk.com"    line.Hyperlinks.Add(hyper)
                    _AcDb.HyperLink hyper = new _AcDb.HyperLink();
                    hyper.Name = "www.facebook.com";
                    ln.Hyperlinks.Add(hyper);
                    if (ln.Hyperlinks.Contains(hyper))
                    {
                        hyper.Name = "www.gotdotnet.com";
                    }
                    ln.Hyperlinks.Add(hyper);
                    foreach (var hl in ln.Hyperlinks)
                    {
                        System.Diagnostics.Debug.WriteLine(hl.ToString());
                    }
                    trans.Commit();
                }
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
        }
Exemple #8
0
        private void insertCircle(_Ge.Point3d center, double radius)
        {
            _Db.BlockTableRecord btr = _c.trans.GetObject(_c.modelSpace.Id, _Db.OpenMode.ForWrite) as _Db.BlockTableRecord;

            using (_Db.Circle circle = new _Db.Circle())
            {
                circle.Center = center;
                circle.Radius = radius;
                btr.AppendEntity(circle);
                _c.trans.AddNewlyCreatedDBObject(circle, true);
            }
        }
Exemple #9
0
 public static AcDb.ObjectId InsertObject(AcDb.Entity entityObject)
 {
     AcDb.ObjectId objectId;
     using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
     {
         AcDb.BlockTableRecord btr = (AcDb.BlockTableRecord)tr.GetObject(db.CurrentSpaceId, AcDb.OpenMode.ForWrite);
         btr.AppendEntity(entityObject);
         tr.AddNewlyCreatedDBObject(entityObject, true);
         objectId = entityObject.ObjectId;
         btr.Dispose();
         tr.Commit();
     }
     return(objectId);
 }
Exemple #10
0
        private void createCircle(double radius, int index, _Ge.Point3d ip)
        {
            _Db.BlockTableRecord btr = _c.trans.GetObject(_c.modelSpace.Id, _Db.OpenMode.ForWrite) as _Db.BlockTableRecord;

            using (_Db.Circle circle = new _Db.Circle())
            {
                circle.Center     = ip;
                circle.Radius     = radius;
                circle.ColorIndex = index;
                circle.Layer      = kontrollLayer;
                btr.AppendEntity(circle);
                _c.trans.AddNewlyCreatedDBObject(circle, true);
            }
        }
Exemple #11
0
        private void ExplodeBlocks(_AcDb.Database db, List <_AcDb.ObjectId> allXrefsInMs, List <_AcDb.ObjectId> newlyCreatedObjects, bool deleteRef, bool deleteBtr)
        {
            log.Debug("ExplodeXRefs");
            using (_AcDb.Transaction tr = _TransMan.StartTransaction())
            {
                _AcDb.BlockTable bt = (_AcDb.BlockTable)tr.GetObject(db.BlockTableId, _AcDb.OpenMode.ForRead);

                _AcDb.BlockTableRecord btr = (_AcDb.BlockTableRecord)tr.GetObject(_AcDb.SymbolUtilityServices.GetBlockModelSpaceId(db), _AcDb.OpenMode.ForWrite);


                foreach (var oid in allXrefsInMs)
                {
                    _AcDb.DBObjectCollection objs  = new _AcDb.DBObjectCollection();
                    _AcDb.BlockReference     block = (_AcDb.BlockReference)tr.GetObject(oid, _AcDb.OpenMode.ForRead);
                    log.DebugFormat(CultureInfo.CurrentCulture, "Explode von Block '{0}'.", block.Name);
                    block.Explode(objs);
                    log.DebugFormat(CultureInfo.CurrentCulture, "Block enthält {0} Entities.", objs.Count);
                    _AcDb.ObjectId blockRefTableId = block.BlockTableRecord;


                    foreach (_AcDb.DBObject obj in objs)
                    {
                        _AcDb.Entity ent = (_AcDb.Entity)obj;
                        btr.AppendEntity(ent);
                        tr.AddNewlyCreatedDBObject(ent, true);

                        newlyCreatedObjects.Add(ent.ObjectId);
                    }

                    if (deleteRef)
                    {
                        log.DebugFormat(CultureInfo.CurrentCulture, "Lösche Block '{0}'.", block.Name);
                        block.UpgradeOpen();
                        block.Erase();
                    }

                    if (deleteBtr)
                    {
                        log.DebugFormat("DeleteBtr");
                        // funkt nicht -> xref würde gelöscht
                        var bd = (_AcDb.BlockTableRecord)tr.GetObject(blockRefTableId, _AcDb.OpenMode.ForWrite);
                        bd.Erase();
                        log.DebugFormat("Endof DeleteBtr");
                    }
                }
                tr.Commit();
            }
        }
Exemple #12
0
        private void insertText(_Ge.Point3d ptInsert, _Db.AttachmentPoint a, string txt, double rotation)
        {
            _Db.BlockTableRecord btr = _c.trans.GetObject(_c.modelSpace.Id, _Db.OpenMode.ForWrite) as _Db.BlockTableRecord;

            using (_Db.MText acMText = new _Db.MText())
            {
                acMText.Attachment = a;
                acMText.Location   = ptInsert;
                acMText.Contents   = txt;
                acMText.TextHeight = textHeight;
                acMText.Rotation   = rotation;

                btr.AppendEntity(acMText);
                _c.trans.AddNewlyCreatedDBObject(acMText, true);
            }
        }
Exemple #13
0
        private void insertDimLine(_Ge.Point3d ptStart, _Ge.Point3d ptEnd, _Ge.Point3d ptPos, double rotation)
        {
            _Db.BlockTableRecord btr = _c.trans.GetObject(_c.modelSpace.Id, _Db.OpenMode.ForWrite) as _Db.BlockTableRecord;

            using (_Db.RotatedDimension rotDim = new _Db.RotatedDimension())
            {
                rotDim.XLine1Point    = ptStart;
                rotDim.XLine2Point    = ptEnd;
                rotDim.Rotation       = rotation;
                rotDim.DimLinePoint   = ptPos;
                rotDim.DimensionStyle = _c.db.Dimstyle;

                btr.AppendEntity(rotDim);
                _c.trans.AddNewlyCreatedDBObject(rotDim, true);
            }
        }
Exemple #14
0
        private void insertText(string value, _Ge.Point3d position, string layer)
        {
            _Db.BlockTableRecord btr = _c.trans.GetObject(_c.modelSpace.Id, _Db.OpenMode.ForWrite) as _Db.BlockTableRecord;

            using (_Db.DBText acText = new _Db.DBText())
            {
                acText.Layer = layer;

                acText.Position   = position;
                acText.Height     = 120;
                acText.TextString = value;

                btr.AppendEntity(acText);
                _c.trans.AddNewlyCreatedDBObject(acText, true);
            }
        }
        public static void BuildingOrthogonalPolylines()
        {
            try
            {
                AcDb.Database db = CurrentCAD.Database;
                jigger = new OrthogonalPolylinesJig();
                AcEd.PromptResult jigRes;
                do
                {
                    jigRes = CurrentCAD.Editor.Drag(jigger);
                    if (jigRes.Status == AcEd.PromptStatus.OK)
                    {
                        jigger.allVertexes.Add(jigger.lastVertex);
                    }
                } while (jigRes.Status == AcEd.PromptStatus.OK);

                using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
                {
                    AcDb.BlockTableRecord btr = (AcDb.BlockTableRecord)tr.GetObject(db.CurrentSpaceId, AcDb.OpenMode.ForWrite);

                    Teigha.DatabaseServices.Polyline ent = new Teigha.DatabaseServices.Polyline();
                    ent.SetDatabaseDefaults();
                    for (int i = 0; i < jigger.allVertexes.Count; i++)
                    {
                        AcGe.Point3d pt3d = jigger.allVertexes[i];
                        AcGe.Point2d pt2d = new AcGe.Point2d(pt3d.X, pt3d.Y);
                        ent.AddVertexAt(i, pt2d, 0, db.Plinewid, db.Plinewid);
                    }
                    ent.TransformBy(jigger.UCS);
                    btr.AppendEntity(ent);
                    tr.AddNewlyCreatedDBObject(ent, true);

                    tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                CurrentCAD.Editor.WriteMessage(ex.ToString());
            }
        }
        public static string CreateBlock(
            AcDb.DBObjectCollection blockElements,
            string nameBlock)
        {
            using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
            {
                AcDb.BlockTable blockTable   = tr.GetObject(db.BlockTableId, AcDb.OpenMode.ForRead) as AcDb.BlockTable;
                string          oldNameBlock = nameBlock;
                int             iNameBlock   = 0;
mark_reNameBlock:
                if (blockTable.Has(nameBlock))
                {
                    iNameBlock++;
                    nameBlock = oldNameBlock + iNameBlock.ToString("_000");
                    goto mark_reNameBlock;
                }


                AcDb.BlockTableRecord blockTableRecord = new AcDb.BlockTableRecord
                {
                    Name = nameBlock
                };
                blockTable.UpgradeOpen();
                AcDb.ObjectId btrId = blockTable.Add(blockTableRecord);
                tr.AddNewlyCreatedDBObject(blockTableRecord, true);

                foreach (AcDb.Entity ent in blockElements)
                {
                    blockTableRecord.AppendEntity(ent);
                    tr.AddNewlyCreatedDBObject(ent, true);
                }

                tr.Commit();
            }

            return(nameBlock);
        }
        public static AcDb.ObjectId ManualInsertBlock(string nameBlock,
                                                      double scaleBlock,
                                                      Dictionary <string, string> tags)
        {
            AcDb.ObjectId idBlock = AcDb.ObjectId.Null;
            using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
            {
                AcDb.BlockTable blockTable = (AcDb.BlockTable)tr.GetObject(db.BlockTableId, AcDb.OpenMode.ForRead);
                if (!blockTable.Has(nameBlock))
                {
                    ed.WriteMessage("\nНезнайдено блок '{0}' у таблиці блоків креслення.", nameBlock);
                    return(idBlock);
                }
                AcDb.BlockTableRecord curSpace       = (AcDb.BlockTableRecord)tr.GetObject(db.CurrentSpaceId, AcDb.OpenMode.ForWrite);
                AcDb.BlockReference   blockReference = new AcDb.BlockReference(AcGe.Point3d.Origin, blockTable[nameBlock])
                {
                    ScaleFactors = new AcGe.Scale3d(scaleBlock, scaleBlock, scaleBlock)
                };
                blockReference.TransformBy(ed.CurrentUserCoordinateSystem);
                curSpace.AppendEntity(blockReference);

                tr.AddNewlyCreatedDBObject(blockReference, true);

                AcDb.BlockTableRecord btr = (AcDb.BlockTableRecord)tr.GetObject(blockTable[nameBlock], AcDb.OpenMode.ForRead);
                BlockPlacementJig     jig = new BlockPlacementJig(blockReference, tags);
                AcEd.PromptResult     pr  = ed.Drag(jig);

                if (pr.Status != AcEd.PromptStatus.OK)
                {
                    blockReference.Erase();
                }

                tr.Commit();
            }

            return(idBlock);
        }
        public static AcDb.ObjectId InsertBlock(
            string nameBlock,
            AcGe.Point3d insertionPoint,
            double scale,
            double rotation,
            AcDb.ObjectId layerId,
            Dictionary <string, string> tags)
        {
            AcDb.ObjectId idBlock = AcDb.ObjectId.Null;
            using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
            {
                AcDb.BlockTable blockTable = (AcDb.BlockTable)tr.GetObject(db.BlockTableId, AcDb.OpenMode.ForRead);
                if (!blockTable.Has(nameBlock))
                {
                    ed.WriteMessage("\nНезнайдено блок '{0}' у таблиці блоків креслення.", nameBlock);
                    return(idBlock);
                }
                AcDb.BlockTableRecord curSpace       = (AcDb.BlockTableRecord)tr.GetObject(db.CurrentSpaceId, AcDb.OpenMode.ForWrite);
                AcDb.BlockReference   blockReference = new AcDb.BlockReference(insertionPoint, blockTable[nameBlock])
                {
                    LayerId      = layerId,
                    ScaleFactors = new AcGe.Scale3d(scale, scale, scale),
                    Rotation     = rotation
                };
                blockReference.TransformBy(ed.CurrentUserCoordinateSystem);
                curSpace.AppendEntity(blockReference);
                tr.AddNewlyCreatedDBObject(blockReference, true);
                if (tags != null)
                {
                    ReplaceAttributeBlock(blockReference, tags, true);
                }
                idBlock = blockReference.ObjectId;

                tr.Commit();
            }
            return(idBlock);
        }
Exemple #19
0
        private void SubVarianLoadRaster()
        {
            String PIC_NAME = "C:\\_Temp_\\5525.TIF";

            AcDb.Database CurDb = AcAp.Application.DocumentManager.MdiActiveDocument.Database;


            using (AcDb.Transaction acTrans = CurDb.TransactionManager.StartTransaction())
            {
                try
                {
                    AcDb.ObjectId dictId = AcDb.RasterImageDef.GetImageDictionary(CurDb);
                    if (dictId == null)
                    {
                        dictId = AcDb.RasterImageDef.CreateImageDictionary(CurDb);
                    }

                    AcDb.DBDictionary   dict    = acTrans.GetObject(dictId, AcDb.OpenMode.ForRead) as AcDb.DBDictionary;
                    String              recName = "5525";
                    AcDb.RasterImageDef rid     = new AcDb.RasterImageDef
                    {
                        SourceFileName = PIC_NAME
                    };
                    dict.UpgradeOpen();
                    AcDb.ObjectId defId = dict.SetAt(recName, rid);

                    rid.Load();

                    acTrans.AddNewlyCreatedDBObject(rid, true);
                    AcDb.RasterImage ri = new AcDb.RasterImage
                    {
                        ImageDefId  = defId,
                        ShowImage   = true,
                        Orientation = new AcGe.CoordinateSystem3d(new AcGe.Point3d(200, 300, 0), new AcGe.Vector3d(1, 0, 0), new AcGe.Vector3d(0, 1, 0))
                    };
                    AcDb.BlockTable       bt  = acTrans.GetObject(CurDb.BlockTableId, AcDb.OpenMode.ForRead, false) as AcDb.BlockTable;
                    AcDb.BlockTableRecord btr = acTrans.GetObject(bt[AcDb.BlockTableRecord.ModelSpace], AcDb.OpenMode.ForWrite, false) as AcDb.BlockTableRecord;
                    btr.AppendEntity(ri);
                    acTrans.AddNewlyCreatedDBObject(ri, true);
                    ri.AssociateRasterDef(rid);
                    ri.TransformBy(AcGe.Matrix3d.Scaling(1000, new AcGe.Point3d(200, 300, 0)));
                }
                catch
                {
                    return;
                }
            }

            /*
             *     Try
             *              Dim PIC_NAME As String = original_picture_name
             *              Dim dictId As ObjectId = RasterImageDef.GetImageDictionary(Db)
             *              If dictId = Nothing Then
             *                  dictId = RasterImageDef.CreateImageDictionary(Db)
             *              End If
             *              Dim dict As DBDictionary = CType(acTrans.GetObject(dictId, OpenMode.ForRead), DBDictionary)
             *              Dim recName As String = Picture_name_in_drawing
             *              Dim rid As RasterImageDef = New RasterImageDef
             *              rid.SourceFileName = PIC_NAME
             *              dict.UpgradeOpen()
             *              Dim defId As ObjectId = dict.SetAt(recName, rid)
             *              rid.Load()
             *              acTrans.AddNewlyCreatedDBObject(rid, True)
             *              Dim ri As RasterImage = New RasterImage
             *              ri.ImageDefId = defId
             *              ri.ShowImage = True
             *              ri.Orientation = New CoordinateSystem3d(New Point3d(x1, y1, 0), New Vector3d(1, 0, 0), New Vector3d(0, 1, 0))
             *              Dim bt As BlockTable
             *              Dim btr As BlockTableRecord
             *              bt = acTrans.GetObject(Db.BlockTableId, OpenMode.ForRead, False)
             *              btr = acTrans.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite, False)
             *              btr.AppendEntity(ri)
             *              acTrans.AddNewlyCreatedDBObject(ri, True)
             *              ri.AssociateRasterDef(rid)
             *              ri.TransformBy(Matrix3d.Scaling(picture_scale, New Point3d(x1, y1, 0)))
             *       Catch
             *
             *              Exit Sub
             *       End Try
             *
             */
        }
Exemple #20
0
        public static void AttachRasterImage(LandRasterImage landRastr)
        {
            AcEd.Editor ed = AcApp.DocumentManager.MdiActiveDocument.Editor;

            //bool bRasterDefCreated = false;

            AcDb.Database curDb = AcApp.DocumentManager.MdiActiveDocument.Database;

            using (AcDb.Transaction tr = curDb.TransactionManager.StartTransaction())
            {
                AcDb.RasterImageDef rasterDef;
                AcDb.ObjectId       imgDefId;
                AcDb.ObjectId       imgDctID = AcDb.RasterImageDef.GetImageDictionary(curDb);
                if (imgDctID.IsNull)
                {
                    imgDctID = AcDb.RasterImageDef.CreateImageDictionary(curDb);
                }

                AcDb.DBDictionary imgDict = (AcDb.DBDictionary)tr.GetObject(imgDctID, AcDb.OpenMode.ForRead);

                if (imgDict.Contains(landRastr.ImageName))
                {
                    imgDefId  = imgDict.GetAt(landRastr.ImageName);
                    rasterDef = (AcDb.RasterImageDef)tr.GetObject(imgDefId, AcDb.OpenMode.ForWrite);
                    if (rasterDef.IsLoaded)
                    {
                        //return;
                    }
                }
                else
                {
                    AcPApp.AcadApplication app    = AcApp.AcadApplication as AcPApp.AcadApplication;
                    AcPApp.AcadDocument    doc    = app.ActiveDocument;
                    AcPDb.AcadModelSpace   mSpace = doc.ModelSpace;
                    AcPDb.AcadRasterImage  ri     = mSpace.AddRaster(landRastr.FileName, landRastr.InsertPoint.ToArray(), 1000, 0);
                    ri.Name         = landRastr.ImageName;
                    ri.Transparency = true;
                    ServiceCAD.CreateLayer(landRastr.Layer);
                    ri.Layer       = landRastr.Layer;
                    ri.ImageHeight = 1000;
                    ri.ImageWidth  = 1000;

                    tr.Commit();
                    return;
                }

                AcDb.BlockTable blkTbl =
                    (AcDb.BlockTable)tr.GetObject(curDb.BlockTableId, AcDb.OpenMode.ForRead);

                AcDb.BlockTableRecord acBlkTblRec =
                    (AcDb.BlockTableRecord)tr.GetObject(blkTbl[AcDb.BlockTableRecord.ModelSpace], AcDb.OpenMode.ForWrite);

                using (AcDb.RasterImage rasterImage = new AcDb.RasterImage())
                {
                    rasterImage.ImageDefId = imgDefId;

                    AcGe.Vector3d width;
                    AcGe.Vector3d height;

                    AcGe.Matrix3d ucs  = ed.CurrentUserCoordinateSystem;
                    double        size = 1000;

                    width  = new AcGe.Vector3d(size, 0, 0);
                    height = new AcGe.Vector3d(0, size, 0);


                    AcGe.Point3d            insPt            = landRastr.InsertPoint;
                    AcGe.CoordinateSystem3d coordinateSystem = new AcGe.CoordinateSystem3d(insPt.TransformBy(ucs), width.TransformBy(ucs), height.TransformBy(ucs));
                    rasterImage.Orientation = coordinateSystem;
                    rasterImage.Rotation    = 0;
                    rasterImage.ShowImage   = true;

                    acBlkTblRec.AppendEntity(rasterImage);
                    tr.AddNewlyCreatedDBObject(rasterImage, true);

                    rasterImage.AssociateRasterDef(rasterDef);
                }
                tr.Commit();
            }
        }
Exemple #21
0
        public static void BuildingRectangle()
        {
            try
            {
                AcDb.Database db = CurrentCAD.Database;
                AcEd.Editor   ed = CurrentCAD.Editor;

                AcEd.PromptKeywordOptions pko;
                AcEd.PromptPointOptions   ppt;
                AcEd.PromptPointResult    ppr;
                AcGe.Point3d basePoint;
                AcGe.Point3d diractionPoint;

                pko = new AcEd.PromptKeywordOptions("\nПобудова прямокутника");

                pko.Keywords.Add("по Діагоналі");
                pko.Keywords.Add("по Напрямку та діагоналі");
                pko.Keywords.Add("по Ширині та висота");
                pko.Keywords.Default = "по Ширині та висота";
                pko.AllowNone        = false;

                AcEd.PromptResult pkr = ed.GetKeywords(pko);

                if (pkr.Status != AcEd.PromptStatus.OK)
                {
                    return;
                }

                MethodConstructingRectangle methodConstructing;

                if (pkr.StringResult == "Діагоналі")
                {
                    methodConstructing = MethodConstructingRectangle.Diagonal;
                }
                else if (pkr.StringResult == "Напрямку")
                {
                    methodConstructing = MethodConstructingRectangle.DirectionAndDiagonal;
                }
                else
                {
                    methodConstructing = MethodConstructingRectangle.HeightAndWidth;
                }

                ppt = new AcEd.PromptPointOptions("\nВкажіть першу точку прямокутника:");
                ppr = ed.GetPoint(ppt);
                if (ppr.Status != AcEd.PromptStatus.OK)
                {
                    return;
                }

                basePoint = ppr.Value;

                if (methodConstructing == MethodConstructingRectangle.Diagonal)
                {
                    diractionPoint = basePoint.Add(AcGe.Vector3d.XAxis);
                }
                else
                {
                    ppt = new AcEd.PromptPointOptions("\n");
                    if (methodConstructing == MethodConstructingRectangle.DirectionAndDiagonal)
                    {
                        ppt.Message = "\nВкажіть точку напрямку прямокутника:";
                    }
                    else if (methodConstructing == MethodConstructingRectangle.DirectionAndDiagonal)
                    {
                        ppt.Message = "\nВкажіть ширину прямокутника:";
                    }
                    ppt.UseBasePoint = true;
                    ppt.BasePoint    = basePoint;
                    ppr = ed.GetPoint(ppt);
                    if (ppr.Status != AcEd.PromptStatus.OK)
                    {
                        return;
                    }

                    diractionPoint = ppr.Value;
                }
                jigger = new RectangleJig(methodConstructing, basePoint, diractionPoint);
                ed.Drag(jigger);

                using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
                {
                    AcDb.BlockTableRecord btr = (AcDb.BlockTableRecord)tr.GetObject(db.CurrentSpaceId, AcDb.OpenMode.ForWrite);

                    Teigha.DatabaseServices.Polyline ent = new Teigha.DatabaseServices.Polyline();
                    ent.SetDatabaseDefaults();
                    for (int i = 0; i < jigger.Corners.Count; i++)
                    {
                        AcGe.Point3d pt3d = jigger.Corners[i];
                        AcGe.Point2d pt2d = new AcGe.Point2d(pt3d.X, pt3d.Y);
                        ent.AddVertexAt(i, pt2d, 0, db.Plinewid, db.Plinewid);
                    }
                    ent.Closed = true;
                    ent.TransformBy(jigger.UCS);
                    btr.AppendEntity(ent);
                    tr.AddNewlyCreatedDBObject(ent, true);

                    tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                CurrentCAD.Editor.WriteMessage(ex.ToString());
            }
        }