Author Topic: Get COM property from a .net object  (Read 1934 times)

0 Members and 1 Guest are viewing this topic.

sdunn

  • Newt
  • Posts: 90
Get COM property from a .net object
« on: September 24, 2018, 03:47:00 PM »
I am working with Civil 3D survey figures and I need to access a property that is not available in the .net api.  The property is available through COM.  Are there any methods available to get a COM version of a .Net object?  So far the only information I have found is to get the .AcadObject from the entity I am working with.

Code: [Select]
                                        Dim survFig as Autodesk.Civil.DatabaseServices.SurveyFigure
                                        survFig = TryCast(trans.GetObject(Oid, OpenMode.ForWrite), SurveyFigure)

                                        Dim oSurvFig As Autodesk.AECC.Interop.Survey.AeccSurveyFigure
                                        oSurvFig = TryCast(survFig.AcadObject, AeccSurveyFigure)

The problem I am having is the .AcadObject of survFig is Aeccfeatureline and not AeccSurveyFigure.  Is there a step I am missing or another method to get the COM version of the same object or perhaps make the COM properties available to the .net object?

Thank you,
Stacy

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8661
  • AKA Daniel
Re: Get COM property from a .net object
« Reply #1 on: September 24, 2018, 11:06:48 PM »
Hmm, your code looks right, you might try AcadDocument.ObjectIdToObject or AcadDocument.HandleToObject

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8661
  • AKA Daniel
Re: Get COM property from a .net object
« Reply #2 on: September 25, 2018, 09:50:35 PM »
something like
Code: [Select]
public class Commands
    {
        static object getComDbObj(ObjectId id, Document doc)
        {
            AcadDocument acadDocument = doc.GetAcadDocument() as AcadDocument;
            if (acadDocument == null)
                throw new System.Exception("AcadDocument is null");
            return acadDocument.ObjectIdToObject(id.OldId);
        }

        [CommandMethod("doit")]
        public static void doit()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            AcadModelSpace ms = getComDbObj(doc.Database.CurrentSpaceId, doc) as AcadModelSpace; //assume
            doc.Editor.WriteMessage(ms == null ? "null" : "eOk");
        }
    }

sdunn

  • Newt
  • Posts: 90
Re: Get COM property from a .net object
« Reply #3 on: September 28, 2018, 11:23:50 AM »
Thank you for the suggestions.  I still get the featureline object and subsequent cast error when using id.OldIdptr to get the COM ObjectID from the .net object.  I would rather not re-write the routine to work with only the COM version, but that looks like the route I am headed down.