Author Topic: get dxf values of a selected object  (Read 2577 times)

0 Members and 1 Guest are viewing this topic.

BenJones

  • Guest
get dxf values of a selected object
« on: October 30, 2008, 07:58:58 PM »
Noob to .NET...migrating vba to .net (see faces cringing now)...

I see that you can create dxf selection filters, but I want to select an object and get the dxf codes. I have checked the object browser and done a couple of google searches and come up with nothing.

Anyone have a snippet that I can snag or some leads on how to get this info?

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8771
  • AKA Daniel
Re: get dxf values of a selected object
« Reply #1 on: October 30, 2008, 09:04:59 PM »
you can p/invoke entget

Code: [Select]
#region
using System;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
//using AcExtensions; mine

using AcAp = Autodesk.AutoCAD.ApplicationServices;
#endregion

[assembly: CommandClass(typeof(ExecMethod.Commands))]
//++--
namespace ExecMethod
{
  public class Commands
  {
    [CommandMethod("doit")]
    static public void doit()
    {
      Editor ed = AcAp.Application.DocumentManager.MdiActiveDocument.Editor;
      try
      {
        foreach (TypedValue tv in SafeNativeMethods.EntGet(ed.GetEntity("Get It").ObjectId))
        {
          ed.WriteMessage("\n{0}", tv);
        }
      }
      catch (System.Exception ex)
      {
        ed.WriteMessage("\n" + ex.Message);
        ed.WriteMessage("\n" + ex.StackTrace);
      }
    }
  }

  public static class SafeNativeMethods
  {
    //++-- TonyT
    //++-- http://discussion.autodesk.com/forums/thread.jspa?messageID=5656222&#5656222
    [DllImport("acdb17.dll", CallingConvention = CallingConvention.Cdecl,
        EntryPoint = "?acdbGetAdsName@@YA?AW4ErrorStatus@Acad@@AAY01JVAcDbObjectId@@@Z")]
    extern static public ErrorStatus acdbGetAdsName(out Int64 entres, ObjectId id);

    [DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl)]
    extern static IntPtr acdbEntGet(out Int64 e);
    public static ResultBuffer EntGet(ObjectId id)
    {
      Int64 e;
      if (acdbGetAdsName(out e, id) == ErrorStatus.OK)
      {
        IntPtr res = acdbEntGet(out e);
        if (res != IntPtr.Zero)
          return ResultBuffer.Create(res, true);
      }
      return null;
    }
  }
}


sinc

  • Guest
Re: get dxf values of a selected object
« Reply #2 on: October 30, 2008, 10:17:39 PM »
Why do you want to get to DXF codes?  What are you trying to do?

BenJones

  • Guest
Re: get dxf values of a selected object
« Reply #3 on: October 30, 2008, 10:40:50 PM »
Thanks Daniel. I will try this out.

I am using adt schedules and they keep the their object selection in soft pointers.

So the idea is this, select a ADT schedule object and create a selection of objects that it is associated to.

Autodesk hasn't opened schedules through the api at all, so I am looking for ways around this. Any ideas?

Thanks again!

Ben

BenJones

  • Guest
Re: get dxf values of a selected object
« Reply #4 on: October 31, 2008, 12:50:33 AM »
This worked great!

Thanks!!

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8771
  • AKA Daniel
Re: get dxf values of a selected object
« Reply #5 on: October 31, 2008, 01:18:43 AM »
My pleasure  :-)