C# interface with dynamo 2

I wrote a code but I can’t figure out why there’s a warning.

image

Basically, I thought I already have the parameter type it asked for but it still tells me that I the right parameter type.

        public static Autodesk.Revit.DB.View3D[] Create(Autodesk.Revit.DB.Document Doc, Autodesk.Revit.DB.FamilyInstance[] familyInstance, int offset, bool proceed)
        {

            List<Autodesk.Revit.DB.View3D> result = new List<Autodesk.Revit.DB.View3D>();

            if (proceed)
            {
                foreach (Autodesk.Revit.DB.FamilyInstance fi in familyInstance)
                {
                    Autodesk.Revit.DB.BoundingBoxXYZ boundingBoxXYZ = fi.get_BoundingBox(null);

                    result.Add(Create3DView(Doc, boundingBoxXYZ));
                }


            }

            return result.ToArray() ;
        }

your method is expecting a document of the internal Revit class Autodesk.Revit.DB.Document and you are feeding a document in with the Dynamo object of Revit.Application.Document

Try changing your code as follows:

 public static Autodesk.Revit.DB.View3D[] Create(Autodesk.Revit.DB.FamilyInstance[] familyInstance, int offset, bool proceed)
        {
            //this obtains the active document
            var Doc = DocumentManager.Instance.CurrentDBDocument;

            List<Autodesk.Revit.DB.View3D> result = new List<Autodesk.Revit.DB.View3D>();

            if (proceed)
            {
                foreach (Autodesk.Revit.DB.FamilyInstance fi in familyInstance)
                {
                    //cast the dynamo family instance to the internal Revit one.
                    var internalFi = (Autodesk.Revit.DB.FamilyInstance)fi.InternalElement();
                    Autodesk.Revit.DB.BoundingBoxXYZ boundingBoxXYZ = internalFi.get_BoundingBox(null);

                    result.Add(Create3DView(Doc, boundingBoxXYZ));
                }


            }

            return result.ToArray() ;
        }

20210804 - edited per comment from @SeanP

1 Like

Looks to be the same thing for the family instance as well. Dynamo vs Revit elements.

1 Like

I didn’t realize I need to be using Dynamo library instead of Revit API.

Casting objects from one type to another is definitely a big topic and something you will find yourself doing a lot.

Marcello’s zero touch videos have some great info on this.

4 Likes