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;
}
}
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.
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.
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)
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.
@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;
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.
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).