コード例 #1
0
        // Database extensions
        ///<summary>
        /// Create a piece of text of a specified size at a specified location.
        ///</summary>
        ///<param name="norm">The normal to the text object.</param>
        ///<param name="pt">The position for the text.</param>
        ///<param name="conts">The contents of the text.</param>
        ///<param name="size">The size of the text.</param>
        public static void CreateText(

            this _AcDb.Database db, _AcGe.Vector3d norm, _AcGe.Point3d pt, string conts, double size

            )
        {
            using (var tr = db.TransactionManager.StartTransaction())
            {
                var ms =
                    tr.GetObject(
                        _AcDb.SymbolUtilityServices.GetBlockModelSpaceId(db),
                        _AcDb.OpenMode.ForWrite

                        ) as _AcDb.BlockTableRecord;

                if (ms != null)
                {
                    var txt = new _AcDb.DBText();
                    txt.Normal         = norm;
                    txt.Position       = pt;
                    txt.Justify        = _AcDb.AttachmentPoint.MiddleCenter;
                    txt.AlignmentPoint = pt;
                    txt.TextString     = conts;
                    txt.Height         = size;

                    var id = ms.AppendEntity(txt);
                    tr.AddNewlyCreatedDBObject(txt, true);
                }

                tr.Commit();
            }
        }
コード例 #2
0
 public static AcGe.Point3dCollection Offset(
     AcGe.Point3dCollection collection,
     AcGe.Vector3d offset)
 {
     AcGe.Point3dCollection offsetCollection = new AcGe.Point3dCollection();
     foreach (AcGe.Point3d point in collection)
     {
         offsetCollection.Add(point.Add(offset));
     }
     return(offsetCollection);
 }
コード例 #3
0
ファイル: ArraysBlocks.cs プロジェクト: ArtemLoban/LoSa.Land
        public void DisplayArrays(int numberСolumns, int numberRows, double stepСolumns, double stepRows)
        {
            for (int i = 0; i < numberСolumns; i++)
            {
                for (int j = 0; j < numberRows; j++)
                {
                    AcGe.Vector3d offset      = new AcGe.Vector3d(j * stepRows, i * stepСolumns, 0);
                    AcGe.Point3d  insertPoint = this.BasePointArrays.Add(offset);

                    AcDb.ObjectId objId = ServiceBlockElements.InsertBlock(this.NameBlock, insertPoint, this.ScaleBlock, this.RotationBlock);
                    if (objId.IsNull)
                    {
                        return;
                    }
                }
            }
        }
コード例 #4
0
        private void CalculateBeamPoints()
        {
            //
            // Calculate the vector perpendicular to the picked points.
            // Note: we are assuming all work is done in the 'world' coordinate system, i.e. 2D
            //
            _vecLine = _beamData.BeamStartPoint.GetVectorTo(_beamData.BeamEndPoint);
            _vecPerp = _vecLine.RotateBy((Math.PI / 2), _AcGe.Vector3d.ZAxis);

            //
            // Calculate the intersection of the beam side point as a line parallel to the
            // beam line and the perp vector, this will give us the start corner.
            //
            _AcGe.Line3d sideLine = new _AcGe.Line3d(_beamData.BeamStartPoint, _beamData.BeamEndPoint);
            // move it to the side picked point:
            sideLine.TransformBy(_AcGe.Matrix3d.Displacement(_beamData.BeamStartPoint.GetVectorTo(_beamData.BeamSidePoint)));
            _AcGe.Line3d  perpline  = new _AcGe.Line3d(_beamData.BeamStartPoint, _vecPerp);
            _AcGe.Point3d perpPoint = perpline.IntersectWith(sideLine)[0];

            //
            // Now we need to get the normalised vector to the perpPoint, we then scale it to the beam width
            // and use it to calculate all other perp points.
            //
            _vecPerp = _beamData.BeamStartPoint.GetVectorTo(perpPoint).GetNormal();
            _vecPerp = _vecPerp * (_beamData.Width * _beamData.OffsetFactor);


            if (_beamData.OffsetFactor == 1.0)
            {
                _p0 = _beamData.BeamStartPoint.TransformBy(_AcGe.Matrix3d.Displacement(_vecPerp));
                _p1 = _beamData.BeamStartPoint;
                _p2 = _beamData.BeamEndPoint;
                _p3 = _beamData.BeamEndPoint.TransformBy(_AcGe.Matrix3d.Displacement(_vecPerp));
            }
            else
            {
                _p0 = _beamData.BeamStartPoint.TransformBy(_AcGe.Matrix3d.Displacement(_vecPerp));
                _p1 = _beamData.BeamStartPoint.TransformBy(_AcGe.Matrix3d.Displacement(_vecPerp.Negate()));
                _p2 = _beamData.BeamEndPoint.TransformBy(_AcGe.Matrix3d.Displacement(_vecPerp.Negate()));
                _p3 = _beamData.BeamEndPoint.TransformBy(_AcGe.Matrix3d.Displacement(_vecPerp));
            }
        }
コード例 #5
0
        public static AcDb.Hatch CreateHatch(AcDb.ObjectIdCollection objectIds, bool removeBoundaries)
        {
            AcDb.Hatch    oHatch = new AcDb.Hatch();
            AcGe.Vector3d normal = new AcGe.Vector3d(0.0, 0.0, 1.0);
            oHatch.Normal       = normal;
            oHatch.Elevation    = 0;
            oHatch.PatternScale = 1;
            oHatch.SetHatchPattern(AcDb.HatchPatternType.UserDefined, "ANSI31");
            oHatch.ColorIndex  = 1;
            oHatch.Associative = true;
            oHatch.AppendLoop((int)AcDb.HatchLoopTypes.Default, objectIds);
            oHatch.EvaluateHatch(true);

            if (removeBoundaries)
            {
                ServiceCAD.DeleteObjects(objectIds);
            }

            return(oHatch);
        }
コード例 #6
0
        internal void DoIt(_AcAp.Document doc, string rbName, string fgLayer)
        {
            log.Debug("--------------------------");

            _FlaechenGrenzen.Clear();
            _Raumbloecke.Clear();

            var _AreaEngine = new AreaEngine();

            _AcGe.Matrix3d ucs = _AcGe.Matrix3d.Identity;
            try
            {
                ucs = doc.Editor.CurrentUserCoordinateSystem;
                doc.Editor.CurrentUserCoordinateSystem = _AcGe.Matrix3d.Identity;

                if (!string.IsNullOrEmpty(rbName))
                {
                    _RaumblockName = rbName;
                }
                if (!string.IsNullOrEmpty(fgLayer))
                {
                    _FgLayer = fgLayer;
                }

                _AreaEngine.SelectFgAndRb(_FlaechenGrenzen, _Raumbloecke, _FgLayer, _RaumblockName);

                if (_FlaechenGrenzen.Count == 0)
                {
                    return;
                }

                // todo: läuft nicht synchron - wird dzt in lisp ausgeführt
                //Globs.SetWorldUCS();

                ZoomToFlaechenGrenzen();

                // init div
                int fehlerKeinRb     = 0;
                int fehlerMehrRb     = 0;
                int fehlerWertFalsch = 0;

                _AcDb.Database           db  = doc.Database;
                _AcEd.Editor             ed  = doc.Editor;
                _AcDb.TransactionManager tm  = db.TransactionManager;
                _AcDb.Transaction        myT = tm.StartTransaction();
                try
                {
                    _AcGe.Point2d lu = new _AcGe.Point2d();
                    _AcGe.Point2d ro = new _AcGe.Point2d();

                    for (int i = 0; i < _FlaechenGrenzen.Count; i++)
                    {
                        log.Debug("--------------------------");

                        double         sumAF = 0;
                        int            rbInd = -1;
                        _AcDb.ObjectId elFG  = _FlaechenGrenzen[i];
                        log.DebugFormat("Flächengrenze {0}", elFG.Handle.ToString());

                        _AcDb.Extents3d ext    = GetExtents(tm, elFG);
                        _AcGe.Point3d   minExt = new _AcGe.Point3d(ext.MinPoint.X - ABSTANDTEXT, ext.MinPoint.Y - ABSTANDTEXT, ext.MinPoint.Z);
                        _AcGe.Point3d   maxExt = new _AcGe.Point3d(ext.MaxPoint.X + ABSTANDTEXT, ext.MaxPoint.Y + ABSTANDTEXT, ext.MaxPoint.Z);

                        List <_AcDb.ObjectId> rbsToIgnoreCol = GetFgAnz(minExt, maxExt, elFG);
                        if (rbsToIgnoreCol.Count > 0)
                        {
                            string handles = string.Join(",", rbsToIgnoreCol.Select(x => x.Handle.ToString()).ToArray());
                            log.DebugFormat("Zu ignorierende Raumblöcke: {0}", handles);
                        }

                        //    'raumbloecke holen
                        List <_AcDb.ObjectId> ssRB = selRB(minExt, maxExt);
                        if (ssRB.Count > 0)
                        {
                            string handles = string.Join(",", ssRB.Select(x => x.Handle.ToString()).ToArray());
                            log.DebugFormat("Raumblöcke: {0}", handles);
                        }


                        int rbAnz = 0;
                        //    'raumbloecke pruefen
                        for (int rbCnt = 0; rbCnt < ssRB.Count; rbCnt++)
                        {
                            _AcDb.ObjectId rbBlock2 = ssRB[rbCnt];

                            //      ' ignore rbs
                            _AcDb.ObjectId found = rbsToIgnoreCol.FirstOrDefault(x => x.Equals(rbBlock2));
                            if (found != default(_AcDb.ObjectId))
                            {
                                continue;
                            }

                            using (_AcDb.DBObject dbObj = tm.GetObject(rbBlock2, _AcDb.OpenMode.ForRead, false))
                            {
                                _AcGe.Point3d rbEp = ((_AcDb.BlockReference)dbObj).Position;

                                using (_AcDb.Entity elFGEnt = (_AcDb.Entity)tm.GetObject(elFG, _AcDb.OpenMode.ForRead, false))
                                {
                                    if (AreaEngine.InPoly(rbEp, elFGEnt))
                                    {
                                        log.DebugFormat("Raumblock {0} ist innerhalb der Flächengrenze.", rbBlock2.Handle.ToString());

                                        if (_Raumbloecke.Contains(rbBlock2))
                                        {
                                            _Raumbloecke.Remove(rbBlock2);
                                        }
                                        rbAnz++;
                                        rbInd = rbCnt;
                                    }
                                    else
                                    {
                                        log.DebugFormat("Außen liegender Raumblock {0} wird ignoriert.", rbBlock2.Handle.ToString());
                                    }
                                }
                            }
                        }


                        if (rbAnz < 1)
                        {
                            log.WarnFormat("Kein Raumblock in Flächengrenze {0}!", elFG.Handle.ToString());
                            //FehlerLineOrHatchPoly(elFG, _InvalidNrRb, 255, 0, 0, tm, Globs.GetLabelPoint(elFG));
                            fehlerKeinRb++;
                        }
                        else if (rbAnz > 1)
                        {
                            log.WarnFormat("Mehr als ein Raumblock in Flächengrenze {0}!", elFG.Handle.ToString());
                            //FehlerLineOrHatchPoly(elFG, _InvalidNrRb, 255, 0, 0, tm, Globs.GetLabelPoint(elFG));
                            fehlerMehrRb++;
                        }
                        else
                        {
                            using (var tr = doc.TransactionManager.StartTransaction())
                            {
                                var pt = Globs.GetLabelPoint(elFG);
                                if (pt.HasValue)
                                {
                                    var rblock = tr.GetObject(ssRB[rbInd], _AcDb.OpenMode.ForWrite) as _AcDb.BlockReference;

                                    var pos = rblock.GetCenter();
                                    if (!pos.HasValue)
                                    {
                                        pos = rblock.Position;
                                    }
                                    _AcGe.Vector3d acVec3d = pos.Value.GetVectorTo(pt.Value);
                                    rblock.TransformBy(_AcGe.Matrix3d.Displacement(acVec3d));
                                    ed.WriteMessage("\nCentroid is {0}", pt);
                                }
                                else
                                {
                                    var    poly = tr.GetObject(elFG, _AcDb.OpenMode.ForRead) as _AcDb.Polyline;
                                    string msg  = string.Format(CultureInfo.CurrentCulture, "\nFläche {0}. Centroid liegt außerhalb.", poly.Handle.ToString());
                                    ed.WriteMessage(msg);
                                    log.Warn(msg);
                                }

                                tr.Commit();
                            }
                        }
                    }

                    //if (_Raumbloecke.Count > 0)
                    //{
                    //    List<object> insPoints = new List<object>();
                    //    for (int i = 0; i < _Raumbloecke.Count; i++)
                    //    {
                    //        _AcIntCom.AcadBlockReference rbBlock = (_AcIntCom.AcadBlockReference)Globs.ObjectIdToAcadEntity(_Raumbloecke[i], tm);
                    //        insPoints.Add(rbBlock.InsertionPoint);
                    //    }

                    //    _AcCm.Color col = _AcCm.Color.FromRgb((byte)0, (byte)255, (byte)0);

                    //    Plan2Ext.Globs.InsertFehlerLines(insPoints, _LooseBlockLayer, 50, Math.PI * 1.25, col);

                    //}



                    if (fehlerKeinRb > 0 || fehlerMehrRb > 0 || fehlerWertFalsch > 0 || _Raumbloecke.Count > 0)
                    {
                        string msg = string.Format(CultureInfo.CurrentCulture, "Räume ohne Raumblock: {0}\nRäume mit mehr als einem Raumblock: {1}\nRäume mit falschem Wert in Raumblock: {2}\nRaumblöcke ohne entsprechende Flächengrenzen: {3}", fehlerKeinRb, fehlerMehrRb, fehlerWertFalsch, _Raumbloecke.Count);
                        log.Debug(msg);
                        _AcAp.Application.ShowAlertDialog(msg);
                    }

                    //If wucs = 0 Then
                    //    ThisDrawing.SendCommand "(command ""_.UCS"" ""_P"") "
                    //End If

                    myT.Commit();
                }
                finally
                {
                    myT.Dispose();
                }
            }
            finally
            {
                doc.Editor.CurrentUserCoordinateSystem = ucs;
            }
        }
コード例 #7
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();
            }
        }
コード例 #8
0
        public void AttachRasterImage()
        {
            // Get the current database and start a transaction
            AcDb.Database acCurDb;
            acCurDb = AcAp.Application.DocumentManager.MdiActiveDocument.Database;

            using (AcDb.Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                // Define the name and image to use
                string strImgName  = "5525";
                string strFileName = "C:\\_Temp_\\5525.TIF";

                AcDb.RasterImageDef acRasterDef;
                bool          bRasterDefCreated = false;
                AcDb.ObjectId acImgDefId;

                // Get the image dictionary
                AcDb.ObjectId acImgDctID = AcDb.RasterImageDef.GetImageDictionary(acCurDb);

                // Check to see if the dictionary does not exist, it not then create it
                if (acImgDctID.IsNull)
                {
                    acImgDctID = AcDb.RasterImageDef.CreateImageDictionary(acCurDb);
                }

                // Open the image dictionary
                AcDb.DBDictionary acImgDict = acTrans.GetObject(acImgDctID, AcDb.OpenMode.ForRead) as AcDb.DBDictionary;

                // Check to see if the image definition already exists
                if (acImgDict.Contains(strImgName))
                {
                    acImgDefId = acImgDict.GetAt(strImgName);

                    acRasterDef = acTrans.GetObject(acImgDefId, AcDb.OpenMode.ForWrite) as AcDb.RasterImageDef;
                }
                else
                {
                    // Create a raster image definition
                    AcDb.RasterImageDef acRasterDefNew = new AcDb.RasterImageDef
                    {
                        // Set the source for the image file
                        SourceFileName = strFileName
                    };

                    acImgDict.UpgradeOpen();
                    acImgDefId = acImgDict.SetAt(strImgName, acRasterDefNew);

                    // Load the image into memory
                    acRasterDefNew.Load();


                    // Add the image definition to the dictionary
                    ////acImgDict.UpgradeOpen();
                    ////acImgDefId = acImgDict.SetAt(strImgName, acRasterDefNew);

                    acTrans.AddNewlyCreatedDBObject(acRasterDefNew, true);

                    /***/

                    acRasterDef = acRasterDefNew;

                    bRasterDefCreated = true;
                }

                // Open the Block table for read
                AcDb.BlockTable acBlkTbl;
                acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, AcDb.OpenMode.ForRead) as AcDb.BlockTable;

                // Open the Block table record Model space for write
                AcDb.BlockTableRecord acBlkTblRec;
                acBlkTblRec = acTrans.GetObject(acBlkTbl[AcDb.BlockTableRecord.ModelSpace],
                                                AcDb.OpenMode.ForWrite) as AcDb.BlockTableRecord;


                // Create the new image and assign it the image definition
                using (AcDb.RasterImage acRaster = new AcDb.RasterImage())
                {
                    acRaster.ImageDefId = acImgDefId;

                    // Use ImageWidth and ImageHeight to get the size of the image in pixels (1024 x 768).
                    // Use ResolutionMMPerPixel to determine the number of millimeters in a pixel so you
                    // can convert the size of the drawing into other units or millimeters based on the
                    // drawing units used in the current drawing.

                    // Define the width and height of the image
                    AcGe.Vector3d width;
                    AcGe.Vector3d height;

                    // Check to see if the measurement is set to English (Imperial) or Metric units
                    if (acCurDb.Measurement == AcDb.MeasurementValue.English)
                    {
                        width  = new AcGe.Vector3d((acRasterDef.ResolutionMMPerPixel.X * acRaster.ImageWidth) / 25.4, 0, 0);
                        height = new AcGe.Vector3d(0, (acRasterDef.ResolutionMMPerPixel.Y * acRaster.ImageHeight) / 25.4, 0);
                    }
                    else
                    {
                        width  = new AcGe.Vector3d(acRasterDef.ResolutionMMPerPixel.X * acRaster.ImageWidth, 0, 0);
                        height = new AcGe.Vector3d(0, acRasterDef.ResolutionMMPerPixel.Y * acRaster.ImageHeight, 0);
                    }

                    // Define the position for the image
                    AcGe.Point3d insPt = new AcGe.Point3d(52000.0, 56000.0, 100.0);

                    // Define and assign a coordinate system for the image's orientation
                    AcGe.CoordinateSystem3d coordinateSystem = new AcGe.CoordinateSystem3d(insPt, width * 2, height * 2);
                    acRaster.Orientation = coordinateSystem;

                    // Set the rotation angle for the image
                    acRaster.Rotation = 0;

                    // Add the new object to the block table record and the transaction
                    acBlkTblRec.AppendEntity(acRaster);
                    acTrans.AddNewlyCreatedDBObject(acRaster, true);

                    // Connect the raster definition and image together so the definition
                    // does not appear as "unreferenced" in the External References palette.
                    /*AcDb.RasterImage.EnableReactors(true);*/
                    acRaster.AssociateRasterDef(acRasterDef);
                    acRaster.ShowImage         = true;
                    acRaster.ColorIndex        = 200;
                    acRaster.ImageTransparency = true;
                    acRaster.Orientation       = new AcGe.CoordinateSystem3d(insPt, new AcGe.Vector3d(1000, 0, 0), new AcGe.Vector3d(0, 2000, 0));

                    if (bRasterDefCreated)
                    {
                        acRasterDef.Dispose();
                    }
                }

                // Save the new object to the database
                acTrans.Commit();

                // Dispose of the transaction
            }
        }
コード例 #9
0
 static public Vector3d ToRhino(this _OdGe.Vector3d p)
 {
     return(new Vector3d(p.X, p.Y, p.Z));
 }