public static Dictionary <string, List <object> > getParticles(string name, bool unitizeVelocity = false) { MDoubleArray pPos = new MDoubleArray(); MGlobal.executeCommand("getParticleAttr -at position -at velocity -array true " + name, pPos); List <object> particlePos = new List <object>(); List <object> particleVec = new List <object>(); int numPart = 0; var posAttr = DMInterop.getPlug(name, "position"); if (posAttr.isArray) { numPart = (int)posAttr.numElements; particlePos = new List <object>(numPart); particleVec = new List <object>(numPart); for (uint i = 0; i < numPart; i += 3) { particlePos.Add(Point.ByCoordinates(posAttr[i].asDouble(), posAttr[i + 1].asDouble(), posAttr[i + 2].asDouble())); } } return(new Dictionary <string, List <object> > { { "Particles", particlePos }, { "Velocity", particleVec } }); }
public static void SetRobotJointsRotations(double[] rotationVals, string[] jointNames = null) { string[] jName; if (jointNames != null && jointNames.Length == 6) { jName = jointNames; } else { jName = new string[6] { "J1", "J2", "J3", "J4", "J5", "J6" }; } if (rotationVals.Length != 6) { new WarningException("The roation values must contain exactly 6 values, one for each axis"); } /* * string melCmd = * string.Format( * "setAttr J1.rx {0}; setAttr J2.rz {1}; setAttr J3.rz {2}; setAttr J4.rx {3}; setAttr J5.rz {4}; setAttr J6.rx {5}; ", * rotationVals[0], -rotationVals[1], -rotationVals[2], rotationVals[3], rotationVals[4], rotationVals[5]+90); * * MGlobal.executeCommand(melCmd); */ try { MPlug j1Plug = DMInterop.getPlug(jName[0], "rx"); j1Plug.setDouble(rotationVals[0] * 0.0174533); MPlug j2Plug = DMInterop.getPlug(jName[1], "rz"); j2Plug.setDouble(-rotationVals[1] * 0.0174533); MPlug j3Plug = DMInterop.getPlug(jName[2], "rz"); j3Plug.setDouble(-rotationVals[2] * 0.0174533); MPlug j4Plug = DMInterop.getPlug(jName[3], "rx"); j4Plug.setDouble(rotationVals[3] * 0.0174533); MPlug j5Plug = DMInterop.getPlug(jName[4], "rz"); j5Plug.setDouble(-rotationVals[4] * 0.0174533); MPlug j6Plug = DMInterop.getPlug(jName[5], "rx"); j6Plug.setDouble(rotationVals[5] * 0.0174533); } catch (Exception e) { MGlobal.displayWarning(e.Message); } }
public static void SetPlugValue(string objectName, string plugName, object plugValue) { MPlug plug; try { plug = DMInterop.getPlug(objectName, plugName); } catch (Exception e) { MGlobal.displayWarning($"plug not found: {e.Message}"); return; } if (plugValue is double) { plug.setDouble(Convert.ToDouble(plugValue)); } else if (plugValue is int) { plug.setInt(Convert.ToInt32(plugValue)); } else if (plugValue is Vector) { Vector vec = (Vector)plugValue; var mVector = new MVector(); if (MGlobal.isYAxisUp) { mVector.x = vec.X; mVector.y = vec.Z; mVector.z = -vec.Y; } else { mVector.x = vec.X; mVector.y = vec.Y; mVector.z = vec.Z; } } }