Author Topic: Get Document from Database  (Read 4568 times)

0 Members and 1 Guest are viewing this topic.

Fred Tomke

  • Newt
  • Posts: 38
  • [ Mr. Bad Guy ]
Get Document from Database
« 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
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: Get Document from Database
« Reply #1 on: April 11, 2011, 10:18:11 PM »
Look into this:
Code: [Select]
Document oDoc = Application.DocumentManager.GetDocument(oDb);

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Get Document from Database
« Reply #2 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;
        }
    }
}

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Fred Tomke

  • Newt
  • Posts: 38
  • [ Mr. Bad Guy ]
Re: Get Document from Database
« Reply #3 on: April 12, 2011, 12:34:19 AM »
Hi guys,

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

Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]