Beispiel #1
0
        // Zoom via COM


        private static void ZoomWin2(

            _AcEd.Editor ed, _AcGe.Point3d min, _AcGe.Point3d max

            )
        {
            _AcInt.AcadApplication app =

                (_AcInt.AcadApplication)_AcAp.Application.AcadApplication;


            double[] lower =

                new double[3] {
                min.X, min.Y, min.Z
            };

            double[] upper

                = new double[3] {
                max.X, max.Y, max.Z
                };


            app.ZoomWindow(lower, upper);
        }
Beispiel #2
0
        // Zoom by sending a command


        private static void ZoomWin3(

            _AcEd.Editor ed, _AcGe.Point3d min, _AcGe.Point3d max

            )
        {
            string lower =

                min.ToString().Substring(

                    1,

                    min.ToString().Length - 2

                    );

            string upper =

                max.ToString().Substring(

                    1,

                    max.ToString().Length - 2

                    );


            string cmd =

                "_.ZOOM _W " + lower + " " + upper + " ";


            // Call the command synchronously using COM


            _AcInt.AcadApplication app =

                (_AcInt.AcadApplication)_AcAp.Application.AcadApplication;


            app.ActiveDocument.SendCommand(cmd);


            // Could also use async command calling:

            //ed.Document.SendStringToExecute(

            //  cmd, true, false, true

            //);
        }
Beispiel #3
0
        private static void HatchPoly(_AcDb.ObjectId oid, string layer, int red, int green, int blue, _AcDb.TransactionManager tm)
        {
            string patternName    = "_SOLID";
            bool   bAssociativity = false;

            _AcIntCom.AcadEntity oPoly       = Plan2Ext.Globs.ObjectIdToAcadEntity(oid, tm);
            _AcIntCom.AcadEntity oCopiedPoly = null;
            if (oPoly is _AcIntCom.AcadPolyline)
            {
                _AcIntCom.AcadPolyline poly1 = (_AcIntCom.AcadPolyline)oPoly;
                oCopiedPoly = (_AcIntCom.AcadEntity)poly1.Copy();
                ((_AcIntCom.AcadPolyline)oCopiedPoly).Closed = true;
            }
            else if (oPoly is _AcIntCom.AcadLWPolyline)
            {
                _AcIntCom.AcadLWPolyline poly2 = (_AcIntCom.AcadLWPolyline)oPoly;
                oCopiedPoly = (_AcIntCom.AcadEntity)poly2.Copy();
                ((_AcIntCom.AcadLWPolyline)oCopiedPoly).Closed = true;
            }
            else // 3dpoly
            {
                _AcIntCom.Acad3DPolyline poly2 = (_AcIntCom.Acad3DPolyline)oPoly;
                oCopiedPoly = (_AcIntCom.AcadEntity)poly2.Copy();
                ((_AcIntCom.Acad3DPolyline)oCopiedPoly).Closed = true;
            }

            //' Create the non associative Hatch object in model space
            _AcInt.AcadApplication app = (_AcInt.AcadApplication)_AcAp.Application.AcadApplication;
            //log.Info("1..");
            //Autodesk.AutoCAD.Interop.AcadApplication abc = (Autodesk.AutoCAD.Interop.AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
            //log.Info("2..");

            _AcIntCom.AcadHatch     hatchObj = app.ActiveDocument.ModelSpace.AddHatch(AcPatternType, patternName, bAssociativity, AcHatchObject);
            _AcIntCom.AcadAcCmColor col1     = new _AcIntCom.AcadAcCmColor(); // app.GetInterfaceObject(COLOROBJECTPROGID) as AcadAcCmColor;
            //AcadAcCmColor col2 = app.GetInterfaceObject(COLOROBJECTPROGID) as AcadAcCmColor;
            col1.SetRGB(red, green, blue);
            hatchObj.TrueColor = col1;
            _AcIntCom.AcadEntity[] outerLoop = new _AcIntCom.AcadEntity[] { oCopiedPoly };
            hatchObj.AppendOuterLoop(outerLoop);
            SetLayer((_AcIntCom.AcadEntity)hatchObj, layer);
            if (oCopiedPoly != null)
            {
                oCopiedPoly.Delete();
            }
        }
Beispiel #4
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();
            }
        }