コード例 #1
0
ファイル: Commands.cs プロジェクト: presscad/Plan2ExtAcad2013
        static public void DynamicBlockProps()
        {
            _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument;
            _AcDb.Database db  = doc.Database;
            _AcEd.Editor   ed  = doc.Editor;

            _AcEd.PromptStringOptions pso = new _AcEd.PromptStringOptions("\nEnter dynamic block name or enter to select: ");
            pso.AllowSpaces = true;
            _AcEd.PromptResult pr = ed.GetString(pso);

            if (pr.Status != _AcEd.PromptStatus.OK)
            {
                return;
            }

            _AcDb.Transaction tr = db.TransactionManager.StartTransaction();
            using (tr)
            {
                _AcDb.BlockReference br = null;
                // If a null string was entered allow entity selection
                if (pr.StringResult == "")
                {
                    // Select a block reference
                    _AcEd.PromptEntityOptions peo = new _AcEd.PromptEntityOptions("\nSelect dynamic block reference: ");
                    peo.SetRejectMessage("\nEntity is not a block.");
                    peo.AddAllowedClass(typeof(_AcDb.BlockReference), false);

                    _AcEd.PromptEntityResult per = ed.GetEntity(peo);
                    if (per.Status != _AcEd.PromptStatus.OK)
                    {
                        return;
                    }

                    // Access the selected block reference
                    br = tr.GetObject(per.ObjectId, _AcDb.OpenMode.ForRead) as _AcDb.BlockReference;
                }

                else
                {
                    // Otherwise we look up the block by name
                    _AcDb.BlockTable bt = tr.GetObject(db.BlockTableId, _AcDb.OpenMode.ForRead) as _AcDb.BlockTable;
                    if (!bt.Has(pr.StringResult))
                    {
                        ed.WriteMessage("\nBlock \"" + pr.StringResult + "\" does not exist.");
                        return;
                    }

                    // Create a new block reference referring to the block
                    br = new _AcDb.BlockReference(new _AcGe.Point3d(), bt[pr.StringResult]);
                }

                _AcDb.BlockTableRecord btr = (_AcDb.BlockTableRecord)tr.GetObject(br.DynamicBlockTableRecord, _AcDb.OpenMode.ForRead);

                // Call our function to display the block properties
                DisplayDynBlockProperties(ed, br, btr.Name);

                // Committing is cheaper than aborting
                tr.Commit();
            }
        }
コード例 #2
0
        private static bool SetPlotSettings(string loName, string device, string pageSize, string styleSheet, double?scaleNumerator, double?scaleDenominator, short?plotRotation)
        {
            _AcAp.Document      doc       = _AcAp.Application.DocumentManager.MdiActiveDocument;
            _AcDb.Database      db        = doc.Database;
            _AcEd.Editor        ed        = doc.Editor;
            _AcDb.LayoutManager layoutMgr = _AcDb.LayoutManager.Current;

            var layoutId = layoutMgr.GetLayoutId(loName);

            if (!layoutId.IsValid)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Layout '{0}' existiert nicht!", loName));
            }

            using (var tr = db.TransactionManager.StartTransaction())
            {
                var layout = (_AcDb.Layout)tr.GetObject(layoutId, _AcDb.OpenMode.ForWrite);

                layout.SetPlotSettings(device, pageSize, styleSheet, scaleNumerator, scaleDenominator, plotRotation);

                tr.Commit();
            }

            return(true);
        }
コード例 #3
0
ファイル: Commands.cs プロジェクト: presscad/Plan2ExtAcad2013
        public static void Plan2ImportLayerFilters()
        {
            var filePath = GetDwgName();

            if (string.IsNullOrEmpty(filePath))
            {
                return;
            }

            if (!System.IO.File.Exists(filePath))
            {
                return;
            }

            _AcAp.Document        doc    = _AcAp.Application.DocumentManager.MdiActiveDocument;
            _AcEd.Editor          ed     = doc.Editor;
            _AcDb.Database        destDb = doc.Database;
            _AcLm.LayerFilterTree lft    = destDb.LayerFilters;
            using (_AcDb.Database srcDb = new _AcDb.Database(false, false))
            {
                srcDb.ReadDwgFile(filePath, _AcDb.FileOpenMode.OpenForReadAndAllShare, false, String.Empty);
                ImportNestedFilters(srcDb.LayerFilters.Root, lft.Root, srcDb, destDb, false, ed);
            }
            destDb.LayerFilters = lft;
        }
コード例 #4
0
        private void InsertBlocks(_AcDb.Database db, List <_AcDb.ObjectId> allXrefsInMs, List <_AcDb.ObjectId> _BlockRefs)
        {
            log.Debug("InsertBlocks");
            using (_AcDb.Transaction tr = db.TransactionManager.StartTransaction())
            {
                foreach (var oid in allXrefsInMs)
                {
                    var br = tr.GetObject(oid, _AcDb.OpenMode.ForRead) as _AcDb.BlockReference;
                    if (br != null)
                    {
                        var bd = (_AcDb.BlockTableRecord)tr.GetObject(br.BlockTableRecord, _AcDb.OpenMode.ForRead);
                        if (bd.IsFromExternalReference)
                        {
                            string name    = bd.PathName;
                            var    dwgPath = _AcAp.Application.GetSystemVariable("DWGPREFIX").ToString();
                            if (System.IO.Path.IsPathRooted(bd.PathName))
                            {
                                log.DebugFormat(string.Format(CultureInfo.CurrentCulture, "Füge Block '{0}' ein. XREF-Pfad: '{1}'.", br.Name + "_AS_BLOCK", bd.PathName));
                                var blockOid = Plan2Ext.Globs.InsertDwg(bd.PathName, br.Position, br.Rotation, br.Name + "_AS_BLOCK");
                                _BlockRefs.Add(blockOid);
                            }
                            else
                            {
                                log.DebugFormat(string.Format(CultureInfo.CurrentCulture, "Füge Block '{0}' ein. XREF-Pfad: '{1}'.", br.Name + "_AS_BLOCK", System.IO.Path.GetFullPath(dwgPath + bd.PathName)));
                                var blockOid = Plan2Ext.Globs.InsertDwg(System.IO.Path.GetFullPath(dwgPath + bd.PathName), br.Position, br.Rotation, br.Name + "_AS_BLOCK");
                                _BlockRefs.Add(blockOid);
                            }
                        }
                    }
                }

                tr.Commit();
            }
        }
コード例 #5
0
ファイル: Engine.cs プロジェクト: presscad/Plan2ExtAcad2013
        private void CreateOrModifyLayer(LayerInfo layerInfo, _AcAp.Document doc, _AcDb.Database db, _AcDb.Transaction trans, _AcDb.LayerTable layTb)
        {
            if (layTb.Has(layerInfo.NewLayer))
            {
                var oid = layTb[layerInfo.NewLayer];
                _AcDb.LayerTableRecord ltr = (_AcDb.LayerTableRecord)trans.GetObject(oid, _AcDb.OpenMode.ForWrite);
                layerInfo.ModifyLayer(ltr, trans, db);
            }
            else
            {
                using (_AcDb.LayerTableRecord ltr = new _AcDb.LayerTableRecord())
                {
                    // Assign the layer a name
                    ltr.Name = layerInfo.NewLayer;

                    // Upgrade the Layer table for write
                    //layTb.UpgradeOpen();


                    // Append the new layer to the Layer table and the transaction
                    layTb.Add(ltr);
                    trans.AddNewlyCreatedDBObject(ltr, true);

                    layerInfo.ModifyLayer(ltr, trans, db);
                }
            }
        }
コード例 #6
0
        public static void Plan2SetCtbInLayouts()
        {
            _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument;
            _Db = doc.Database;
            _AcEd.Editor ed = doc.Editor;
            _CtbName = string.Empty;
            _DwgsWrongCtb.Clear();
            _NrCtbs = 0;

            try
            {
                if (!GetCtbName(ed))
                {
                    return;
                }
                if (!SetCtbInLayouts())
                {
                    string msg = string.Format(CultureInfo.CurrentCulture, "Ctb '{0}' existiert nicht!", _CtbName);
                    ed.WriteMessage("\n" + msg);
                    System.Windows.Forms.MessageBox.Show(msg, "Plan2SetCtbInLayouts");
                }
                else
                {
                    string resultMsg = string.Format(CultureInfo.CurrentCulture, "Anzahl gesetzter CTBs: {0}", _NrCtbs.ToString());
                    log.Info(resultMsg);
                    System.Windows.Forms.MessageBox.Show(resultMsg, "Plan2SetCtb");
                }
            }
            catch (System.Exception ex)
            {
                string msg = string.Format(CultureInfo.CurrentCulture, "Fehler in (Plan2SetCtbInLayouts): {0}", ex.Message);
                ed.WriteMessage("\n" + msg);
                System.Windows.Forms.MessageBox.Show(ex.Message, "Plan2SetCtbInLayouts");
            }
        }
コード例 #7
0
        public static void CreateLayout(string name)
        {
            _AcAp.Document acDoc   = _AcAp.Application.DocumentManager.MdiActiveDocument;
            _AcDb.Database acCurDb = acDoc.Database;

            using (_AcDb.Transaction trans = acCurDb.TransactionManager.StartTransaction())
            {
                // Reference the Layout Manager
                _AcDb.LayoutManager acLayoutMgr = _AcDb.LayoutManager.Current;

                // Create the new layout with default settings
                _AcDb.ObjectId objID = acLayoutMgr.CreateLayout(name);

                // Open the layout
                _AcDb.Layout layout = trans.GetObject(objID, _AcDb.OpenMode.ForRead) as _AcDb.Layout;

                // Set the layout current if it is not already
                if (layout.TabSelected == false)
                {
                    acLayoutMgr.CurrentLayout = layout.LayoutName;
                }

                // Output some information related to the layout object
                acDoc.Editor.WriteMessage("\nTab Order: " + layout.TabOrder +
                                          "\nTab Selected: " + layout.TabSelected +
                                          "\nBlock Table Record ID: " +
                                          layout.BlockTableRecordId.ToString());

                // Save the changes made
                trans.Commit();
            }
        }
コード例 #8
0
        public static void DetachRasterImage(LandRasterImage landRastr)
        {
            AcDb.Database curDb = AcApp.DocumentManager.MdiActiveDocument.Database;
            using (AcDb.Transaction tr = curDb.TransactionManager.StartTransaction())
            {
                AcDb.RasterImageDef rasterDef;
                //bool bRasterDefCreated = false;
                AcDb.ObjectId imgDefId;

                AcDb.ObjectId imgDctID = AcDb.RasterImageDef.GetImageDictionary(curDb);
                if (imgDctID.IsNull)
                {
                    imgDctID = AcDb.RasterImageDef.CreateImageDictionary(curDb);
                }

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

                if (imgDict.Contains(landRastr.ImageName))
                {
                    imgDefId  = imgDict.GetAt(landRastr.ImageName);
                    rasterDef = tr.GetObject(imgDefId, AcDb.OpenMode.ForWrite) as AcDb.RasterImageDef;
                    if (rasterDef.IsLoaded)
                    {
                        rasterDef.Unload(true);
                        imgDict.Remove(landRastr.ImageName);
                    }
                }
                tr.Commit();
            }
        }
コード例 #9
0
        private void GetAllMsXrefs(_AcDb.Database db, List <_AcDb.ObjectId> allXrefsInMs)
        {
            log.Debug("GetAllMsXrefs");
            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.ForRead);

                foreach (var oid in btr)
                {
                    var br = tr.GetObject(oid, _AcDb.OpenMode.ForRead) as _AcDb.BlockReference;
                    if (br != null)
                    {
                        var bd = (_AcDb.BlockTableRecord)tr.GetObject(br.BlockTableRecord, _AcDb.OpenMode.ForRead);
                        if (bd.IsFromExternalReference)
                        {
                            allXrefsInMs.Add(br.ObjectId);
                        }
                    }
                }

                tr.Commit();
            }
        }
コード例 #10
0
ファイル: Layer.cs プロジェクト: 15831944/bricsCAS2_v18
        //Konstruktor (damit kein Default Konstruktor generiert wird!)
        protected MyLayer()
        {
            //Datenbank
            try {
                _AcDb.Database    db  = _AcDb.HostApplicationServices.WorkingDatabase;
                _AcDb.Transaction myT = db.TransactionManager.StartTransaction();

                using (DocumentLock dl = _AcAp.Application.DocumentManager.MdiActiveDocument.LockDocument())
                {
                    _AcDb.LayerTable layT = (_AcDb.LayerTable)myT.GetObject(db.LayerTableId, OpenMode.ForRead);

                    //Layernamen in Liste schreiben
                    foreach (ObjectId id in layT)
                    {
                        LayerTableRecord ltr = (LayerTableRecord)(myT.GetObject(id, OpenMode.ForRead));

                        m_lsLayerTableRecord.Add(ltr);
                    }
                }

                myT.Commit();
                myT.Dispose();
            }
            catch { }
        }
コード例 #11
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();
            }
        }
コード例 #12
0
        public static AcDb.ObjectId CreateLayer(String layerName)
        {
            AcDb.ObjectId layerId;
            AcDb.Database db = CurrentCAD.Database;

            using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
            {
                AcDb.LayerTable layerTable = (AcDb.LayerTable)tr.GetObject(db.LayerTableId, AcDb.OpenMode.ForWrite);

                if (layerTable.Has(layerName))
                {
                    layerId = layerTable[layerName];
                }
                else
                {
                    AcDb.LayerTableRecord layerTableRecord = new AcDb.LayerTableRecord
                    {
                        Name = layerName
                    };
                    layerId = layerTable.Add(layerTableRecord);
                    tr.AddNewlyCreatedDBObject(layerTableRecord, true);
                }
                tr.Commit();
            }
            return(layerId);
        }
コード例 #13
0
ファイル: _CONNECTION.cs プロジェクト: 15831944/habile
        public _CONNECTION()
        {
            _doc   = _Ap.Application.DocumentManager.MdiActiveDocument;
            _db    = _doc.Database;
            _ed    = _doc.Editor;
            _trans = _db.TransactionManager.StartTransaction();

            _blockTable = _trans.GetObject(_db.BlockTableId, _Db.OpenMode.ForWrite) as _Db.BlockTable;
            _modelSpace = _trans.GetObject(_Db.SymbolUtilityServices.GetBlockModelSpaceId(_db), _Db.OpenMode.ForWrite) as _Db.BlockTableRecord;
        }
コード例 #14
0
ファイル: Commands.cs プロジェクト: presscad/Plan2ExtAcad2013
        private _AcDb.ObjectId CreateNewLayer(_AcAp.Document doc, _AcDb.Database db)
        {
            using (_AcDb.Transaction trans = doc.TransactionManager.StartTransaction())
            {
                try
                {
                    string           layerName = "MyTest";
                    _AcDb.LayerTable layTb     = trans.GetObject(db.LayerTableId, _AcDb.OpenMode.ForRead) as _AcDb.LayerTable;
                    using (_AcDb.LayerTableRecord acLyrTblRec = new _AcDb.LayerTableRecord())
                    {
                        // Assign the layer a name
                        acLyrTblRec.Name = layerName;

                        // Upgrade the Layer table for write
                        layTb.UpgradeOpen();


                        // Append the new layer to the Layer table and the transaction
                        layTb.Add(acLyrTblRec);
                        trans.AddNewlyCreatedDBObject(acLyrTblRec, true);


                        int transparenz = 10;

                        Byte alpha            = TransparenzToAlpha(transparenz);
                        _AcCm.Transparency tr = new _AcCm.Transparency(alpha);
                        acLyrTblRec.Transparency = tr;

                        _AcCm.Color col = _AcCm.Color.FromColorIndex(_AcCm.ColorMethod.ByColor, 2);
                        //_AcCm.Color col = _AcCm.Color.FromRgb(10, 20, 30);
                        acLyrTblRec.Color = col;

                        _AcDb.ObjectId ltOid = GetLinetypeFromName("Continuous", trans, db);
                        if (!ltOid.IsNull)
                        {
                            acLyrTblRec.LinetypeObjectId = ltOid;
                        }

                        _AcDb.LineWeight lw = _AcDb.LineWeight.LineWeight030;
                        acLyrTblRec.LineWeight = lw;

                        // ???
                        //acLyrTblRec.PlotStyleName = "hugo";

                        acLyrTblRec.Description = "My new Layer";

                        return(acLyrTblRec.ObjectId);
                    }
                }
                finally
                {
                    trans.Commit();
                }
            }
        }
コード例 #15
0
        public _AcDb.ResultBuffer LayoutListSelected(_AcDb.ResultBuffer args)
        {
            if (args != null)
            {
                throw new TooFewArgsException();
            }

            _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument;
            _AcDb.Database db  = doc.Database;
            //Editor ed = doc.Editor;
            //LayoutManager layoutMgr = LayoutManager.Current;
            List <string> layouts = new List <string>();

            _AcDb.ResultBuffer res = new _AcDb.ResultBuffer();

            using (_AcDb.Transaction tr = db.TransactionManager.StartTransaction())
            {
                _AcDb.DBDictionary layoutDic =
                    (_AcDb.DBDictionary)tr.GetObject(db.LayoutDictionaryId, _AcDb.OpenMode.ForRead, openErased: false);

                foreach (_AcDb.DBDictionaryEntry entry in layoutDic)
                {
                    _AcDb.Layout layout =
                        (_AcDb.Layout)tr.GetObject(entry.Value, _AcDb.OpenMode.ForRead);

                    string layoutName = layout.LayoutName;

                    if (layout.TabSelected)
                    {
                        layouts.Add(layoutName);
                    }
                }

                tr.Commit();
            }

            layouts.Remove("Model");

            if (0 < layouts.Count)
            {
                layouts.Sort();

                foreach (string layoutName in layouts)
                {
                    res.Add(new _AcDb.TypedValue((int)(_AcBrx.LispDataType.Text), layoutName));
                }

                return(res);
            }

            else
            {
                return(null);
            }
        }
コード例 #16
0
ファイル: Commands.cs プロジェクト: presscad/Plan2ExtAcad2013
        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);
            }
        }
コード例 #17
0
ファイル: _SETUP.cs プロジェクト: 15831944/habile
        private bool getBlockFromMaster(ref List <string> missingBlocks)
        {
            _Db.Database sourceDb       = new _Db.Database(false, true);
            string       sourceFileName = @"C:\Brics_pealeehitus\master.dwg";

            if (!File.Exists(sourceFileName))
            {
                sourceFileName = @"C:\Users\aleksandr.ess\Dropbox\DMT\Brics_testimine\master.dwg";
                if (!File.Exists(sourceFileName))
                {
                    sourceFileName = @"C:\Users\Alex\Dropbox\DMT\Brics_testimine\master.dwg";
                }
            }

            sourceDb.ReadDwgFile(sourceFileName, System.IO.FileShare.Read, true, "");
            _Db.ObjectIdCollection blockIds = new _Db.ObjectIdCollection();


            using (_Db.Transaction sourceTrans = sourceDb.TransactionManager.StartTransaction())
            {
                _Db.BlockTable sourceBlockTable = sourceTrans.GetObject(sourceDb.BlockTableId, _Db.OpenMode.ForRead, false) as _Db.BlockTable;

                foreach (_Db.ObjectId sourceObject in sourceBlockTable)
                {
                    _Db.BlockTableRecord btr = sourceTrans.GetObject(sourceObject, _Db.OpenMode.ForRead, false) as _Db.BlockTableRecord;

                    if (!btr.IsAnonymous && !btr.IsLayout)
                    {
                        if (missingBlocks.Contains(btr.Name))
                        {
                            blockIds.Add(sourceObject);
                            missingBlocks.Remove(btr.Name);
                            write("[SETUP] " + btr.Name); // TODO REMOVE
                        }
                    }

                    btr.Dispose();
                }
            }

            if (missingBlocks.Count > 0)
            {
                return(false);
            }

            _Db.IdMapping mapping = new _Db.IdMapping();
            sourceDb.WblockCloneObjects(blockIds, _c.blockTable.Id, mapping, _Db.DuplicateRecordCloning.Replace, false);
            sourceDb.Dispose();

            write("[SETUP] Kõik puuduvad blockid on lisatud 'master' failist");
            return(true);
        }
コード例 #18
0
            public void SetLineType(string lt, _AcDb.Transaction trans, _AcDb.Database db)
            {
                _LineType = lt;
                var lto = GetLinetypeFromName(_LineType, trans, db);

                if (lto == default(_AcDb.ObjectId))
                {
                    _Errors = _Errors + string.Format(CultureInfo.CurrentCulture, "\nUngültiger Linientyp '{0}' für Layer '{1}'", _LineType, OldLayer);
                    return;
                }

                _LineTypeO = lto;
            }
コード例 #19
0
        private List <_AcDb.ObjectId> GetFgAnz(_AcGe.Point3d minExt, _AcGe.Point3d maxExt, _AcDb.ObjectId elFG)
        {
            List <_AcDb.ObjectId> Ret = new List <_AcDb.ObjectId>();

            _AcEd.Editor          ed     = _AcAp.Application.DocumentManager.MdiActiveDocument.Editor;
            _AcEd.SelectionFilter filter = new _AcEd.SelectionFilter(new _AcDb.TypedValue[] {
                new _AcDb.TypedValue((int)_AcDb.DxfCode.Start, "*POLYLINE"),
                new _AcDb.TypedValue((int)_AcDb.DxfCode.LayerName, _FgLayer)
            });
            _AcEd.PromptSelectionResult res = null;
            res = ed.SelectCrossingWindow(minExt, maxExt, filter);
            //res = ed.SelectAll(filter);
            if (res.Status != _AcEd.PromptStatus.OK)
            {
                // todo: logging: lot4net?
                return(Ret);
            }

#if BRX_APP
            _AcEd.SelectionSet ss = res.Value;
#else
            using (_AcEd.SelectionSet ss = res.Value)
#endif
            {
                _AcDb.ObjectId[]         idArray = ss.GetObjectIds();
                _AcDb.Database           db      = _AcAp.Application.DocumentManager.MdiActiveDocument.Database;
                _AcDb.TransactionManager tm      = db.TransactionManager;
                _AcDb.Transaction        myT     = tm.StartTransaction();
                try
                {
                    for (int i = 0; i < idArray.Length; i++)
                    {
                        _AcDb.ObjectId oid = idArray[i];
                        if (!oid.Equals(elFG))
                        {
                            if (PolyInPoly(tm, oid, elFG))
                            {
                                AddRbToRetCol(Ret, tm, oid);
                            }
                        }
                    }
                    myT.Commit();
                }
                finally
                {
                    myT.Dispose();
                }
            }

            return(Ret);
        }
コード例 #20
0
ファイル: Engine.cs プロジェクト: presscad/Plan2ExtAcad2013
        /// <summary>
        /// Bulk-Befehl
        /// </summary>
        /// <param name="dwgFiles"></param>
        /// <returns></returns>
        private List <LayerInfo> GetLayerInfos(List <string> dwgFiles)
        {
            var layDict = new Dictionary <string, LayerInfo>();

            foreach (var fileName in dwgFiles)
            {
                int layerCount      = 0;
                int layerAddedCount = 0;
                var db = new _AcDb.Database(false, true);
                using (db)
                {
                    try
                    {
                        db.ReadDwgFile(fileName, System.IO.FileShare.Read, allowCPConversion: false, password: "");
                    }
                    catch (Exception ex)
                    {
                        log.WarnFormat("Fehler beim Öffnen der Zeichnung '{0}'!{1}", fileName, ex.Message);
                        continue;
                    }
                    using (_AcDb.Transaction trans = db.TransactionManager.StartTransaction())
                    {
                        try
                        {
                            _AcDb.LayerTable layTb = trans.GetObject(db.LayerTableId, _AcDb.OpenMode.ForRead) as _AcDb.LayerTable;
                            foreach (var ltrOid in layTb)
                            {
                                _AcDb.LayerTableRecord ltr = (_AcDb.LayerTableRecord)trans.GetObject(ltrOid, _AcDb.OpenMode.ForRead);
                                string layNameUC           = ltr.Name.ToUpperInvariant();
                                layerCount++;
                                if (!layDict.ContainsKey(layNameUC))
                                {
                                    layDict.Add(layNameUC, new LayerInfo(ltr, trans));
                                    layerAddedCount++;
                                }
                            }
                        }
                        finally
                        {
                            trans.Commit();
                        }
                    }
                }
                log.InfoFormat("{0}: {1} von {2} Layer hinzugefügt.", fileName, layerAddedCount, layerCount);
            }

            var linfos = layDict.Values.ToList();

            return(linfos);
        }
コード例 #21
0
ファイル: Commands.cs プロジェクト: presscad/Plan2ExtAcad2013
        public static bool Plan2RemoveHyperLinks(_AcDb.ResultBuffer rb)
        {
            var doc = _AcAp.Application.DocumentManager.MdiActiveDocument;

            _AcDb.Database           db      = _AcAp.Application.DocumentManager.MdiActiveDocument.Database;
            _AcDb.TransactionManager dbTrans = db.TransactionManager;
            _AcEd.Editor             ed      = doc.Editor;

            try
            {
                if (rb == null)
                {
                    ed.WriteMessage("Aufruf: (Plan2RemoveHyperLinks el)");
                    return(false);
                }

                var typedValues = rb.AsArray();
                if (typedValues == null || typedValues.Length != 1)
                {
                    ed.WriteMessage("Aufruf: (Plan2RemoveHyperLinks el)");
                    return(false);
                }

                if (typedValues[0].TypeCode != (short)_AcBrx.LispDataType.ObjectId)
                {
                    ed.WriteMessage("Aufruf: (Plan2RemoveHyperLinks el)");
                    return(false);
                }

                using (_AcDb.Transaction trans = dbTrans.StartTransaction())
                {
                    _AcDb.Entity ent = trans.GetObject((_AcDb.ObjectId)typedValues[0].Value, _AcDb.OpenMode.ForWrite) as _AcDb.Entity;
                    if (ent != null)
                    {
                        //ent.Hyperlinks.Clear(); // -> crashes
                        while (ent.Hyperlinks.Count > 0)
                        {
                            ent.Hyperlinks.RemoveAt(0);
                        }
                    }
                    trans.Commit();
                }
                return(true);
            }
            catch (Exception ex)
            {
                ed.WriteMessage("Aufruf: (Plan2RemoveHyperLinks el)");
            }
            return(false);
        }
コード例 #22
0
ファイル: Commands.cs プロジェクト: presscad/Plan2ExtAcad2013
        /// <summary>
        /// Öffnen einer Dwg ohne Editor
        /// </summary>
        //[_AcTrx.CommandMethod("Plan2TestSideDb")]
        static public void Plan2TestSideDb()
        {
            _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument;
            _AcEd.Editor   ed  = doc.Editor;
            // Ask the user to select a file
            _AcEd.PromptResult res = ed.GetString("\nEnter the path of a DWG or DXF file: ");
            if (res.Status == _AcEd.PromptStatus.OK)
            {
                // Create a database and try to load the file
                _AcDb.Database db = new _AcDb.Database(false, true);
                using (db)
                {
                    try
                    {
                        db.ReadDwgFile(res.StringResult, System.IO.FileShare.Read, false, "");
                    }
                    catch (System.Exception)
                    {
                        ed.WriteMessage("\nUnable to read drawing file.");
                        return;
                    }

                    _AcDb.Transaction tr = db.TransactionManager.StartTransaction();
                    using (tr)
                    {
                        // Open the blocktable, get the modelspace
                        _AcDb.BlockTable       bt  = (_AcDb.BlockTable)tr.GetObject(db.BlockTableId, _AcDb.OpenMode.ForRead);
                        _AcDb.BlockTableRecord btr = (_AcDb.BlockTableRecord)tr.GetObject(bt[_AcDb.BlockTableRecord.ModelSpace], _AcDb.OpenMode.ForRead);

                        // Iterate through it, dumping objects
                        foreach (_AcDb.ObjectId objId in btr)
                        {
                            _AcDb.Entity ent = (_AcDb.Entity)tr.GetObject(objId, _AcDb.OpenMode.ForRead);

                            // Let's get rid of the standard namespace
                            const string prefix     = "Autodesk.AutoCAD.DatabaseServices.";
                            string       typeString = ent.GetType().ToString();
                            if (typeString.Contains(prefix))
                            {
                                typeString = typeString.Substring(prefix.Length);
                            }
                            ed.WriteMessage("\nEntity " + ent.ObjectId.ToString() + " of type " + typeString + " found on layer " +
                                            ent.Layer + " with colour " + ent.Color.ToString());
                        }
                    }
                }
            }
        }
コード例 #23
0
        public static void Plan2ReplaceInLayoutNames()
        {
            _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument;
            _Db = doc.Database;
            _AcEd.Editor ed = doc.Editor;

            _OldText = string.Empty;
            _NewText = string.Empty;

            try
            {
                var layoutNames = Plan2Ext.Layouts.GetLayoutNames();
                layoutNames = layoutNames.Where(x => string.Compare(x, "Model", StringComparison.OrdinalIgnoreCase) != 0).ToList();

                if (!GetOldText(ed))
                {
                    return;
                }
                if (!GetNewText(ed))
                {
                    return;
                }

                _Tr = _Db.TransactionManager.StartTransaction();
                using (_Tr)
                {
                    _AcDb.LayoutManager layoutMgr = _AcDb.LayoutManager.Current;

                    foreach (var name in layoutNames)
                    {
                        bool changed;
                        var  newT = ReplaceTexts(name, out changed);
                        if (changed)
                        {
                            layoutMgr.RenameLayout(name, newT);
                        }
                    }

                    _Tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                string msg = string.Format(CultureInfo.CurrentCulture, "Fehler in (Plan2ReplaceInLayoutNames): {0}", ex.Message);
                ed.WriteMessage("\n" + msg);
                System.Windows.Forms.MessageBox.Show(ex.Message, "Plan2ReplaceInLayoutNames");
            }
        }
コード例 #24
0
        private static bool SetAttValues(_AcDb.Database db)
        {
            bool ok = true;

            try
            {
                using (_AcDb.Transaction tr = db.TransactionManager.StartTransaction())
                {
                    _AcDb.BlockTable bt = (_AcDb.BlockTable)tr.GetObject(db.BlockTableId, _AcDb.OpenMode.ForRead);
                    foreach (var id in bt)
                    {
                        _AcDb.BlockTableRecord btr = (_AcDb.BlockTableRecord)tr.GetObject(id, _AcDb.OpenMode.ForRead);
                        if (btr.IsLayout)
                        {
                            foreach (var oid in btr)
                            {
                                var ent = tr.GetObject(oid, _AcDb.OpenMode.ForRead);
                                _AcDb.BlockReference bref = ent as _AcDb.BlockReference;
                                if (bref != null)
                                {
                                    bool sameName = false;
                                    try
                                    {
                                        sameName = (bref.Name == _BlockName);
                                    }
                                    catch (Exception)
                                    {
                                        log.WarnFormat("Invalid block with handle {0}!", bref.Handle);
                                    }
                                    if (sameName)
                                    {
                                        SetAttValues(bref, tr);
                                    }
                                }
                            }
                        }
                    }

                    tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                log.Error(string.Format(CultureInfo.CurrentCulture, "Fehler beim Ändern der Attribute: {0}", ex.Message), ex);
                ok = false;
            }
            return(ok);
        }
コード例 #25
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();
            }
        }
コード例 #26
0
        public static bool ImportBlock(String fileBlock)
        {
            try
            {
                AcDb.Database refDb = new AcDb.Database(false, true);
                refDb.ReadDwgFile(fileBlock, System.IO.FileShare.Read, true, "");
                string        nameBlock = Path.GetFileNameWithoutExtension(fileBlock);
                AcDb.ObjectId idBTR     = db.Insert(AcDb.BlockTableRecord.ModelSpace, nameBlock, refDb, false);

                if (!idBTR.IsNull)
                {
                    return(true);
                }
            }
            catch { }

            return(false);
        }
コード例 #27
0
        static public void Plan2SetAttValues()
        {
            try
            {
                log.Info("----------------------------------------------------------------------------------");
                log.Info("Plan2SetAttValues");

                string dirName = string.Empty;
                _UsedXrefs.Clear();
                _ErrorWithDwgs.Clear();
                _NrOfChangedAttributes = 0;
                _BlockName             = string.Empty;
                _AttributeName         = string.Empty;
                _AttributeValue        = string.Empty;

                var            doc = Application.DocumentManager.MdiActiveDocument;
                _AcEd.Editor   ed  = Application.DocumentManager.MdiActiveDocument.Editor;
                _AcDb.Database db  = doc.Database;

                if (!GetAttributeInfos(ed, doc))
                {
                    return;
                }

                log.Info("----------------------------------------------------------------------------------");
                log.Info(string.Format(CultureInfo.CurrentCulture, "Zeichnung {0}", doc.Name));

                Plan2Ext.Globs.UnlockAllLayers();

                // main part
                bool ok = SetAttValues(db);

                string resultMsg = string.Format(CultureInfo.CurrentCulture, "Anzahl geänderter Attribute: {0}", _NrOfChangedAttributes.ToString());
                log.Info(resultMsg);
                System.Windows.Forms.MessageBox.Show(resultMsg, "Plan2SetAttValues");
            }
            catch (System.Exception ex)
            {
                string msg = string.Format(CultureInfo.CurrentCulture, "{0}", ex.Message);
                log.Error(msg, ex);
                System.Windows.Forms.MessageBox.Show(msg, "Plan2SetAttValues");
            }
        }
コード例 #28
0
        //Plan2Ext.Layouts.ImportLayout("02.OG B-Bau", @"D:\Plan2\Data\Plan2RenameBlocks\work\02_OGa.dwg");
        //Plan2Ext.Layouts.CreateLayout("alx");
        //var layoutNames = Plan2Ext.Layouts.GetLayoutNames();

        public static List <string> GetLayoutNames()
        {
            var layoutNames = new List <string>();

            _AcAp.Document acDoc   = _AcAp.Application.DocumentManager.MdiActiveDocument;
            _AcDb.Database acCurDb = acDoc.Database;

            using (_AcDb.Transaction trans = acCurDb.TransactionManager.StartTransaction())
            {
                _AcDb.DBDictionary lays = trans.GetObject(acCurDb.LayoutDictionaryId, _AcDb.OpenMode.ForRead) as _AcDb.DBDictionary;

                foreach (_AcDb.DBDictionaryEntry item in lays)
                {
                    layoutNames.Add(item.Key);
                }
                trans.Commit();
            }
            return(layoutNames);
        }
コード例 #29
0
        private static List <_AcGe.Point2d> GetLwPoints(_AcDb.ObjectId objectId)
        {
            var pts = new List <_AcGe.Point2d>();

            _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument;
            _AcDb.Database db  = doc.Database;
            using (var trans = doc.TransactionManager.StartTransaction())
            {
                var lwp = (_AcDb.Polyline)trans.GetObject(objectId, _AcDb.OpenMode.ForRead);
                int vn  = lwp.NumberOfVertices;
                for (int i = 0; i < vn; i++)
                {
                    _AcGe.Point2d pt = lwp.GetPoint2dAt(i);
                    pts.Add(pt);
                }

                trans.Commit();
            }
            return(pts);
        }
コード例 #30
0
ファイル: Globs.cs プロジェクト: alx1808/Parifizierung
        public static Dictionary <string, string> GetAttributesUcKey(_AcDb.BlockReference blockRef)
        {
            Dictionary <string, string> valuePerTag = new Dictionary <string, string>();

            _AcAp.Document doc = Application.DocumentManager.MdiActiveDocument;
            _AcDb.Database db  = doc.Database;
            using (var trans = db.TransactionManager.StartTransaction())
            {
                foreach (_AcDb.ObjectId attId in blockRef.AttributeCollection)
                {
                    var anyAttRef = trans.GetObject(attId, _AcDb.OpenMode.ForRead) as _AcDb.AttributeReference;
                    if (anyAttRef != null)
                    {
                        valuePerTag[anyAttRef.Tag.ToUpperInvariant()] = anyAttRef.TextString;
                    }
                }
                trans.Commit();
            }
            return(valuePerTag);
        }