TheSwamp

Code Red => .NET => Topic started by: sdunn on September 24, 2018, 03:47:00 PM

Title: Get COM property from a .net object
Post by: sdunn 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
Title: Re: Get COM property from a .net object
Post by: It's Alive! on September 24, 2018, 11:06:48 PM
Hmm, your code looks right, you might try AcadDocument.ObjectIdToObject or AcadDocument.HandleToObject
Title: Re: Get COM property from a .net object
Post by: It's Alive! 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");
        }
    }
Title: Re: Get COM property from a .net object
Post by: sdunn 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.