TheSwamp

Code Red => .NET => Topic started by: Fred Tomke on April 11, 2011, 06:44:04 PM

Title: Get Document from Database
Post by: Fred Tomke on April 11, 2011, 06:44:04 PM
Hello,

I can get the database from the document using

Code: [Select]
Document oDoc = Application.DocumentManager.MdiActiveDocument;
Database oDb = oDoc.Database

I can get the database from a database resistent entity using

Code: [Select]
Entity oEnt;
Database oDb = oEnt.Database;

But how can I get the document where the entity was created in?

In VisualLisp there was a (vla-get-document oLine);

Thanks and regards,
Fred
Title: Re: Get Document from Database
Post by: Jeff_M on April 11, 2011, 10:18:11 PM
Look into this:
Code: [Select]
Document oDoc = Application.DocumentManager.GetDocument(oDb);
Title: Re: Get Document from Database
Post by: Kerry on April 11, 2011, 11:14:30 PM

Hello Fred,

As Jeff Indicated ;

Code: [Select]

// CodeHimBelonga kdub@theSwamp 20110412
// http://www.theswamp.org/index.php?topic=37860.msg428862#msg428862
using System;
using System.IO;

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
//
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
using AcUtils = Autodesk.AutoCAD.Internal.Utils;

[assembly: CommandClass(typeof(KdubTesting.WhoIsYouDaddy))]

namespace KdubTesting
{
    public class WhoIsYouDaddy
    {
        [CommandMethod("DADDY_1")]
        public void WhoIsYouDaddy_1()
        {
            Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
            PromptEntityResult peResult = ed.GetEntity("\nSelect an entity: ");
            if( peResult.Status != PromptStatus.OK )
                return;

            Document daddyDoc = WhoIsYourDaddyO(peResult.ObjectId);
            if( daddyDoc != null ) {

                ed.WriteMessage(daddyDoc.Name.ToString());
            }
        }
        /// <summary>
        /// Determine the Document ( Owner ) of objID
        /// </summary>
        /// <param name="objID"> ObjectId </param>
        /// <returns>Document </returns>
        private static Document WhoIsYourDaddyO(ObjectId objID)
        {
            Document oDoc = Application.DocumentManager.GetDocument(objID.Database);

            return oDoc;
        }
    }
}

Title: Re: Get Document from Database
Post by: Fred Tomke on April 12, 2011, 12:34:19 AM
Hi guys,

I was sure that there is a method for this.
Thank you!

Fred