void attachpointComboBox_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (!isExportedToMax)
     {
         return;
     }
     if (attachpointComboBox.SelectedItem != null && file != null && file.Mesh.Count > 0)
     {
         Maxscript.Command("selectDummy = getNodeByName \"{0}\"", ((BrgAttachpoint)attachpointComboBox.SelectedItem).GetMaxName());
         if (Maxscript.QueryBoolean("selectDummy != undefined"))
         {
             Maxscript.Command("select selectDummy");
         }
         else
         {
             DialogResult dlgR = MessageBox.Show("Could not find \"" + ((BrgAttachpoint)attachpointComboBox.SelectedItem).GetMaxName() + "\"! Would you like to delete it?", "ABE",
                                                 MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
             if (dlgR == DialogResult.Yes)
             {
                 file.Mesh[0].Attachpoint.Remove(((BrgAttachpoint)attachpointComboBox.SelectedItem).Index);
                 loadUIAttachpoint();
             }
         }
     }
 }
        private void exportToMaxToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (file == null)
            {
                return;
            }

            try
            {
                DialogResult dlgR = MessageBox.Show("Do you want to clear the scene?", "ABE", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button3);
                if (dlgR == DialogResult.Yes)
                {
                    Maxscript.Command("resetMaxFile #noprompt");
                    //Maxscript.Command("if checkForSave() do resetMaxFile #noprompt");
                }
                else if (dlgR == DialogResult.Cancel)
                {
                    return;
                }

                file.ExportToMax();
                //debug();
                isExportedToMax = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to export model!" + Environment.NewLine + Environment.NewLine + ex.Message, "ABE", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void importFromMaxToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (file == null)
            {
                return;
            }

            try
            {
                bool objectSelected = Maxscript.QueryBoolean("classOf selection[1] == Editable_mesh");
                if (!objectSelected)
                {
                    throw new Exception("No object selected!");
                }
                file.ImportFromMax(true);
                loadUI();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to import model!" + Environment.NewLine + Environment.NewLine + ex.Message, "ABE", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        void attachpointListBox_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (!isExportedToMax)
            {
                return;
            }
            int index = attachpointListBox.IndexFromPoint(e.Location);

            if (index != System.Windows.Forms.ListBox.NoMatches && file != null)
            {
                if (file.Mesh.Count == 0)
                {
                    file.Mesh.Add(new BrgMesh(file));
                }
                BrgAttachpoint att = new BrgAttachpoint();
                att.NameId = BrgAttachpoint.GetIdByName((string)attachpointListBox.Items[index]);
                file.Mesh[0].Attachpoint.Add(att);
                //MessageBox.Show(file.Mesh[0].attachpoints.Count.ToString());
                Maxscript.NewDummy("newDummy", att.GetMaxName(), att.GetMaxTransform(), att.GetMaxPosition(), att.GetMaxBoxSize(), att.GetMaxScale());
                loadUIAttachpoint();
                attachpointComboBox.SelectedIndex = attachpointComboBox.Items.Count - 1;
            }
        }