Zerotouch node - asking to convert non convertible types error

Hi everyone,

I hope this isnt a silly question but ive been banging my wall against this issue all day.

I have a very simple zerotouch node that will run another software (ETABS to be specific) and return that object for me at the end. My class only contains this only function. I have the ETABS API referenced in obviously. The function does work properly (boots up the software and opens the file with the given file path). However at the return part I am getting an error “asking to convert non convertible types error”.

I am returning an object (cSapModel) which is defined in the ETABS API (.dll) library. I think its related to this. Should this object be also defined as a class in my .sln file? Does C# feel this is an unknown object type? Here is my code (consists only of one function). I have removed most of the body for simplicity.

namespace MEStructural
{

    public class ETABSv17tools
    {

        [IsVisibleInDynamoLibrary(false)]
        private ETABSv17tools()
        {

        }

        public static cSapModel OpenETABSModel(string pathETABSVersion, [DefaultArgumentAttribute("null;")]string pathETABSModel)
        {
            //initialising variables
            int ret = -1;
            cHelper myHelper = new ETABSv17.Helper();
            cOAPI myETABSObject = myHelper.CreateObject(pathETABSVersion);
            cSapModel SapModel = myETABSObject.SapModel;
            // irrelevant code here for body`
             return SapModel;
         }
      }

}

bump - anyone?

(post withdrawn by author, will be automatically deleted in 1 hour unless flagged)

@Marcello_Sgambelluri, any suggestions?

What if you remove the default attribute tag? Also may check but from what I can see the “;” inside the tag is not needed.

No luck… Still same error. Returns null and shows this message:
image

hi @moustafa.el-sawy

I am not expert on C# but I did some coding with it. If you look at your code. I think you are returning a Type not valid in dynamo (because there is no open-close parenthesis) and not an Instance. I think it is still not possible to return a ctype in a node.

(Just suggesting possible source of error)

-biboy

Yes this is exactly what I was thinking. This type (object) is only valid in the linked dll (in the other software I am trying to interop with).

How would I go about returning an instance of that object?

Edit: Would I just return the location of the object (file path) and access it again in the next node to avoid returning an object not defined in dynamo? whats the best practice?

Dynamo should try to import a proxy class to represent that type - but it’s possible when it does, it fails to import it - check the console for error messages when your package loads.

A simple way to get around it, as you suggested is to create very simple wrapper class for that return type and return that instead.

@Michael_Kirschner2 where can I find the console? You mean in VS? There are no errors when I debug, the only warnings/errors I see are in dynamo.

Can you illustrate an example of how you implement a wrapper class so I am sure I understand you correctly? Thank you!

Edit: do you mean the part in dynamo at the top when it shows notifications when theres an error? Theres nothing there.

try view->console, there is a separate console area that can be exposed at the bottom of the Dynamo window (separate from the notification area up top)

@Michael_Kirschner2
Is the error supposed to show when I import in the package or while running it?

Just ran the dynamo graph again and nothing in the console.

Here is the full console:

Dynamo log started 2021-03-16 16:16:26Z

Requesting version update info…
Dynamo – Build 2.0.4.12684
Duplicate migration type registered for SunPathDirection
Dynamo will use the package manager server at : https://www.dynamopackages.com
The folder ‘C:\Users\moustafa.el-sawy\AppData\Roaming\Dynamo\Dynamo Revit\2.0\packages\MEStructural\dyf’ does not exist
DynamoPackageManager (id: FCABC211-D56B-4109-AF18-F434DFE48139) extension is added
Backup files timer is started with an interval of 60000 milliseconds
SYSTEM:Environment Path:C:\Program Files\Autodesk\Revit 2018\en-US;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Common Files\Intel\Shared Files\fortran\bin\ia32;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\Program Files\Intel\WiFi\bin;C:\Program Files\Common Files\Intel\WirelessCommon;C:\Program Files (x86)\Plantronics\PlantronicsURE;C:\Program Files\Common Files\Autodesk Shared;C:\Program Files\Microsoft SQL Server\120\Tools\Binn;C:\Program Files (x86)\Webex\Webex\Applications;C:\WINDOWS\System32\OpenSSH;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\Intel® Management Engine Components\DAL;C:\Program Files\Intel\Intel® Management Engine Components\DAL;C:\Program Files\SafeNet\Authentication\SAC\x64;C:\Program Files\SafeNet\Authentication\SAC\x32;C:\Program Files (x86)\Sennheiser\SoftphoneSDK;C:\Program Files\dotnet;C:\WINDOWS\system32\config\systemprofile\AppData\Local\Microsoft\WindowsApps;C:\Program Files (x86)\Adaptiva\AdaptivaClient\bin\x32;C:\Program Files (x86)\Adaptiva\AdaptivaClient\bin\x64;C:\Users\moustafa.el-sawy\AppData\Local\Programs\Python\Python37-32\Scripts;C:\Users\moustafa.el-sawy\AppData\Local\Programs\Python\Python37-32;C:\Users\moustafa.el-sawy\AppData\Local\Microsoft\WindowsApps;C:\Users\moustafa.el-sawy\AppData\Roaming\pyRevit-Master\bin;C:\Program Files\Autodesk\Revit 2018;C:\Program Files\Autodesk\Revit 2018;C:\Program Files\Autodesk\Revit 2018\AddIns\SteelConnections;C:\Program Files\Dynamo\Dynamo Core\2;C:\Program Files\Dynamo\Dynamo Core\2
RENDER : Rendering Tier: 2
RENDER : Pixel Shader 3 Supported: True
RENDER : Pixel Shader 4 Supported: False
RENDER : Software Effect Rendering Supported: True
RENDER : Maximum hardware texture size: 16384,16384
RENDER : Rendering Tier: 2
RENDER : Pixel Shader 3 Supported: True
RENDER : Pixel Shader 4 Supported: False
RENDER : Software Effect Rendering Supported: True
RENDER : Maximum hardware texture size: 16384,16384
DynamoManipulationExtension (id: 58B0496A-E3F8-43D9-86D2-94823D1D0F98) view extension is added
LibraryUI (id: 85941358-5525-4FF4-8D61-6CA831F122AB) view extension is added
NotificationsExtension (id: ef6cd025-514f-44cd-b6b1-69d9f5cce004) view extension is added
PackageManagerViewExtension (id: 100f5ec3-fde7-4205-80a7-c968b3a5a27b) view extension is added
Welcome to Dynamo!
00:00:00.3813940 elapsed for loading Dynamo main window.
WPF Render Mode: SoftwareOnly
Dynamo is up to date.
ERR_ABORTED
Active view is now DV-SAVE - DO NOT DELETE

hi @moustafa.el-sawy

the best practice is to do all the necessary calculations and process inside the node instead of returning an invalid object. all the dynamo’s built-in function and revit API are available in c# so I think its better to never go out of the node.

if you cannot do anything inside a single node, its better to do 2 scripts, one is to save the data in excel and one is to manipulate the data.

-biboy

I see. I didnt know about this limitation. I will have to change the logic I was going after but thats ok. Good to know!

hi @moustafa.el-sawy

Did you try outputting an instance of SapModel?
I remember that some people were able to output a MSQL Connection instance.

Just saying maybe an actual instance of SapModel will also work on you.

-biboy

hi @blsalvio

I am really not sure how to output an instance. I will need to read about it more.

Are there any examples/docs that you recommend I can look into?

hi @moustafa.el-sawy

I cannot help you with this one. Please read the API documentation of SapModel inorder to learn how to make instances of it.

-biboy

@blsalvio I have read the documentation. I am having a hard time understanding how to return an instance of ANY object. I was under the impression that I am doing this already.

        //initialising variables
        int ret = -1;
        cHelper myHelper = new ETABSv17.Helper();
        cOAPI myETABSObject = myHelper.CreateObject(pathETABSVersion);
        cSapModel SapModel = myETABSObject.SapModel;
        // irrelevant code here for body`
         return SapModel;

My object/class is cSapModel and an instance of that object is SapModel. Am I misunderstanding anything? asp.net - How to create an instance of an object in c# - Stack Overflow

hi @moustafa.el-sawy

I think this is my last comment. This forum I think is not a tutorial on how to understand types and instances of C# programming.

check the picture below from the link you posted.

5

The Class ABC is the type (I think classes and types in C# are mostly interchangeable). And a1 is the instance. Please check how from class/type to instance was done.

Since I have no idea about the SapModel API. I think SapModel is another class inside a class (ETABSv17.Helper).

-biboy

1 Like

@blsalvio
Thanks for your help.