<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Adding Skin Weights Using C# in 3ds Max Programming Forum</title>
    <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/adding-skin-weights-using-c/m-p/6477320#M14262</link>
    <description>&lt;P&gt;Hello&amp;nbsp;everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to use the Autodesk.Max dll to write a plugin for 3ds Max using C# and have successfully pulled skin modifier weight data from my scene into a windows form application but am having trouble with writing weight data back to the skin modifier.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Specifically, I'm trying to use the IISkinImportData.AddWeights function but can't get it to return successful (The MessageBox always shows "Operation Failed"). This is what I have tried so far:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;IInterface16 coreInterface = GlobalInterface.Instance.COREInterface16;
IINode selectedNode = coreInterface.GetSelNode(0);
IObject selObj = selectedNode.ObjectRef;
IIDerivedObject derObj = (IIDerivedObject)selObj;
IModifier skinMod = derObj.Modifiers[1];

IISkin iSkin = (IISkin)skinMod.GetInterface((InterfaceID)(0x00010000));
IISkinImportData iiSkinImportData = (IISkinImportData)skinMod.GetInterface((InterfaceID)0x00020000);
ITab&amp;lt;IINode&amp;gt; nodes = GlobalInterface.Instance.Tab.Create&amp;lt;IINode&amp;gt;();
int ret1 = nodes.Append(1, iSkin.GetBone(1).NativePointer, 0);
ITab&amp;lt;float&amp;gt; weights = GlobalInterface.Instance.Tab.Create&amp;lt;float&amp;gt;();
GCHandle floatHandle = GCHandle.Alloc(new float[] { 1f }, GCHandleType.Pinned);
try
{
    IntPtr pointer = floatHandle.AddrOfPinnedObject();
    int ret2 = weights.Append(1, pointer, 0);
    if (iiSkinImportData.AddWeights(selectedNode, 0, nodes, weights))
      MessageBox.Show("Operation Succeeded");
    else
        MessageBox.Show("Operation Failed");
}
finally
{
    if (floatHandle.IsAllocated)
    {
         floatHandle.Free();
    }
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 04 Aug 2016 03:24:17 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2016-08-04T03:24:17Z</dc:date>
    <item>
      <title>Adding Skin Weights Using C#</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/adding-skin-weights-using-c/m-p/6477320#M14262</link>
      <description>&lt;P&gt;Hello&amp;nbsp;everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to use the Autodesk.Max dll to write a plugin for 3ds Max using C# and have successfully pulled skin modifier weight data from my scene into a windows form application but am having trouble with writing weight data back to the skin modifier.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Specifically, I'm trying to use the IISkinImportData.AddWeights function but can't get it to return successful (The MessageBox always shows "Operation Failed"). This is what I have tried so far:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;IInterface16 coreInterface = GlobalInterface.Instance.COREInterface16;
IINode selectedNode = coreInterface.GetSelNode(0);
IObject selObj = selectedNode.ObjectRef;
IIDerivedObject derObj = (IIDerivedObject)selObj;
IModifier skinMod = derObj.Modifiers[1];

IISkin iSkin = (IISkin)skinMod.GetInterface((InterfaceID)(0x00010000));
IISkinImportData iiSkinImportData = (IISkinImportData)skinMod.GetInterface((InterfaceID)0x00020000);
ITab&amp;lt;IINode&amp;gt; nodes = GlobalInterface.Instance.Tab.Create&amp;lt;IINode&amp;gt;();
int ret1 = nodes.Append(1, iSkin.GetBone(1).NativePointer, 0);
ITab&amp;lt;float&amp;gt; weights = GlobalInterface.Instance.Tab.Create&amp;lt;float&amp;gt;();
GCHandle floatHandle = GCHandle.Alloc(new float[] { 1f }, GCHandleType.Pinned);
try
{
    IntPtr pointer = floatHandle.AddrOfPinnedObject();
    int ret2 = weights.Append(1, pointer, 0);
    if (iiSkinImportData.AddWeights(selectedNode, 0, nodes, weights))
      MessageBox.Show("Operation Succeeded");
    else
        MessageBox.Show("Operation Failed");
}
finally
{
    if (floatHandle.IsAllocated)
    {
         floatHandle.Free();
    }
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Aug 2016 03:24:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/adding-skin-weights-using-c/m-p/6477320#M14262</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-08-04T03:24:17Z</dc:date>
    </item>
  </channel>
</rss>

