Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion for DefaultArgumentAttribute should take enumerations as well as methods. #237

Open
erfajo opened this issue Mar 13, 2023 · 3 comments

Comments

@erfajo
Copy link

erfajo commented Mar 13, 2023

Instead of sending strings from dropdown nodes and as input in generel, should dynamo move towards proper types being used throughout. I will suggest that input ports requesting an enummeration value should be able to do that.

This will mean that ” DefaultArgumentAttribute” must be able to take at least two arguments if you should not revise anything else. I am aware that better solution could be made, but a simply tweak in the existing code could do it.

attribute.cs --> Autodesk.DesignScript.Runtime.DefaultArgumentAttribute

[AttributeUsage(AttributeTargets.Parameter)]
public sealed class DefaultArgumentAttribute : Attribute
{
    public dynamic ArgumentExpression { get; private set; }

    public DefaultArgumentAttribute(string defaultArgumentExpression)
    {
        ArgumentExpression = defaultArgumentExpression;
    }

    public DefaultArgumentAttribute(string enumValue, Type enumType)
    {
        ArgumentExpression = Enum.Parse(enumType, enumValue);
    }
}

Of course, with the existing method, you can create a method that returns an enumeration type, but it is somewhat clumsy to look at, rather than being able to show one's intentional default argument. This is how I handle it at the moment :-S

Next problem is that the signature cant take an enumeration as input type without those enumerations showing up as "auto-built nodes” inside dynamo!? Furthermore, if the inport signature is an enumeration type, you can't add a description! This is why I use an ”object” as the inport signature and then make a type check if the proper type is sent/used in the method code.

Red boxes mark input ports requesting an enumeration type. Red arrow is a node that gets the proper enum by input strings. The proper enum can also be requested by my dropdown nodes as shown in the example.
image

@ricardyn
Copy link

ricardyn commented Apr 19, 2023

I think that this could be solved by removing sealed restriction from Attribute. Just like occur with NodeModels Attributes, for instance InPortNamesAttribute.

So, that way we can simply customize the Attribute by inheriting from the class DefaultArgumentAttribute.

An example for what I'm saying follow in images below

Attribute Customization
image

I "customize" the Node Models Attributes to accept types instead of strings, making maintenance more easily and reliable.
image

@ricardyn
Copy link

ricardyn commented Apr 19, 2023

For the case of ZeroTouchNodes or Node Models, in order to avoid that enum appears in Dynamo Library, just set the in port type as object.

image

image

All my enums are declared like this
image

image

My Node Model Selection.ByMethodAndCategory function
image

@erfajo
Copy link
Author

erfajo commented Apr 20, 2023

I am so sorry... I did not ask for a solution, I solved that long ago, and I did also use an object as the "type" since an enum was not applicable. My solution is actually shown in the images attached in the first post, and I solved it much easier than what you show, but let that be what it is…

I DID post my issue under the wishlist deliberately to ask for a change in the dynamo core function so we DONT need to use object type but could use the enum which is the proper type.

By doing what you have done you change the focus of the post and that is unwanted…
Please keep an eye on the ball instead of spamming this post with something NOT asked for!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Triage
Development

No branches or pull requests

2 participants