The following XML file declares a result to be created in ANSYS Mechanical that requires C# implementation:
<extension version="1" name="CSharp">
<author>ANSYS</author>
<description>This extension demonstrates how to use CSharp to write extension.</description>
<assembly src="CSharp.dll" namespace="CSharp" />
<interface context="Mechanical">
<images>images</images>
</interface>
<simdata context="Mechanical">
<load name="CSharpLoad" caption="CSharp Load" version="1" icon="tload" unit="Temperature"
color="#0000FF" class="CSharp.Load">
<property name="Geometry" control="scoping">
<attributes>
<selection_filter>face</selection_filter>
</attributes>
</property>
</load>
<result name="CSharpResult" caption="CSharp Result" version="1" unit="Temperature" icon="tload"
location="node" type="scalar" class="CSharp.Result">
<property name="Geometry" control="scoping" />
</result>
</simdata>
</extension>For the load definition, the attribute class must be set to the name of the class to be used for the integration of the result.
A description of the class CSharp.Result follows.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ansys.ACT.Interfaces.Mechanical;
using Ansys.ACT.Interfaces.Post;
using Ansys.ACT.Interfaces.UserObject;
namespace CSharp
{
public class Result
{
internal double[] res = new double[1];
public Result(IMechanicalExtAPI extApi, IUserResult result)
{
}
public void evaluate(IUserResult entity, IStepInfo stepInfo, IResultCollector collector)
{
foreach (var id in collector.Ids)
{
res[0] = id;
collector.SetValues(id, res);
}
}
}
}As for the load definition, the implementation of a new callback simply requires you add a new method with the name of the callback.