Hello,
I am trying to write a zero touch plugin that takes input parameters of a cuboid and three floating numbers (x y z), and once exported to a DLL, the library will create a new cuboid which is the result of translating the original cuboid by the direction given by the three numbers. I am aware of the Objects section in the following tutorial
but that example cannot be built.
My code begins with:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.DesignScript.Geometry;
namespace TestZeroTouchDynamo
{
public class MyCube1
{
public Autodesk.DesignScript.Geometry.Cuboid _c;
The following function is based on the above tutorial.
public static MyCube1 ByAnotherCuboid1(Autodesk.DesignScript.Geometry.Cuboid c, float x, float y, float z)
{
_c = c;
_c.Translate(x, y, z);
}
This cannot be built, and I see errors about the use of non-static fields in a static function, and the lack of a return value.
1>\MyCube1.cs(17,13,17,15): error CS0120: An object reference is required for the non-static field, method, or property ‘MyCube1._c’
1>\MyCube1.cs(18,13,18,15): error CS0120: An object reference is required for the non-static field, method, or property ‘MyCube1._c’
1>\MyCube1.cs(15,31,15,47): error CS0161: ‘MyCube1.ByAnotherCuboid1(Cuboid, float, float, float)’: not all code paths return a value
So I modified it as follows (which can be built)
public static MyCube1 ByAnotherCuboid(Autodesk.DesignScript.Geometry.Cuboid c, float x, float y, float z)
{
MyCube1 a = new MyCube1();
a._c = c;
a._c.Translate(x,y,z);
return a;
}
And use the library in Dynamo as follows (please note the MyCube1 block), but I only see the highlighted original cube.
If I add yet another function:
public Autodesk.DesignScript.Geometry.Cuboid GetCuboid()
{
return _c;
}
Calling this will crash Dynamo Studio. Maybe I need to dispose something here.
So I was wondering how I can achieve the desired result.
Thank you.
Best regards,
Nicholas
PS: Apologies for the code formatting, I am not very sure how to use the toolbar to format a code snippet.