Esempio n. 1
0
 internal SceneElement(IBaseObject x) : base(x)
 {
     if (parameterBlock == null)
     {
         IIParamArray pa = _BaseObject.ParamBlock;
         if (pa != null)
         {
             parameterBlock = CreateWrapper <ParameterBlock1>(pa.ParamBlock);
         }
     }
 }
        /// <summary>
        /// Function to specifically update Case Windows with input wedth and height parameters
        /// </summary>
        /// <param name="width">The new Width to set the Window</param>
        /// <param name="height">The new Height to set the Window</param>
        /// <returns>window count</returns>
        static public int UpdateWindowNodes(float width, float height)
        {
            IGlobal      globalInterface = Autodesk.Max.GlobalInterface.Instance;
            IInterface14 coreInterface   = globalInterface.COREInterface14;

            IINode nodeRoot = coreInterface.RootNode;

            m_sceneNodes.Clear();
            GetSceneNodes(nodeRoot);

            // 3ds Max uses a class ID for all object types. This is easiest way to find specific type.
            // ClassID (1902665597L, 1593788199L) == 0x71685F7D, 0x5EFF4727 for casement window
            IClass_ID cidCasementWindow = globalInterface.Class_ID.Create(0x71685F7D, 0x5EFF4727);

            // Use LINQ to filter for windows only - in case scene has more than one,
            // but this should still give us at least one for single window scene!
            var sceneWindows = from node in m_sceneNodes
                               where ((node.ObjectRef != null) && // In some cases the ObjectRef can be null for certain node types.
                                      (node.ObjectRef.ClassID.PartA == cidCasementWindow.PartA) &&
                                      (node.ObjectRef.ClassID.PartB == cidCasementWindow.PartB))
                               select node;

            // Iterate the casement windws and update the hight and width parameters.
            foreach (IINode item in sceneWindows)
            {
                // window is using old-style ParamArray rather than newer ParamBlk2
                IIParamArray pb = item.ObjectRef.ParamBlock;
                pb.SetValue(0, coreInterface.Time, height); // window height is at index zero.
                pb.SetValue(1, coreInterface.Time, width);  // window width is at index one.
            }

            // If there are windows, save the window updates
            int status;

            if (sceneWindows.Count() > 0)
            {
                // The output file name must match what the Design Automation work item is specifying as output file.
                string full_filename = coreInterface.CurFilePath;
                string filename      = coreInterface.CurFileName;
                string new_filename  = full_filename.Replace(filename, "outputFile.max");
                status = coreInterface.SaveToFile(new_filename, true, false);
                if (status == 0) //error
                {
                    return(-1);
                }
            }

            // return how many windows were modified.
            return(sceneWindows.Count());
        }
 public override void InternalExecute()
 {
     try
     {
         IGlobal   global = Autodesk.Max.GlobalInterface.Instance; //note that global will be an instance of an abstract class.
         var       i      = global.COREInterface13;
         IClass_ID cid    = global.Class_ID.Create((uint)BuiltInClassIDA.TEAPOT_CLASS_ID, (uint)BuiltInClassIDB.TEAPOT_CLASS_ID);
         object    obj    = i.CreateInstance(SClass_ID.Geomobject, cid as IClass_ID);
         if (obj == null)
         {
             throw new Exception("Failed to create a sphere!");
         }
         IINode       n    = global.COREInterface.CreateObjectNode((IObject)obj);
         IObject      iobj = (IObject)obj;
         IIParamArray ps   = iobj.ParamBlock;
         ps.SetValue(0, global.COREInterface.Time, 20.0f);
         n.Move(global.COREInterface.Time, global.Matrix3.Create(), global.Point3.Create(20, 20, 0), true, true, 0, true);
     }
     catch (System.Exception ex)
     {
         MessageBox.Show("Creating teapot failed: " + ex.Message);
     }
 }