以下代碼可以自動定義動作,Demo僅供參考:
private void openModel()
{
string dbg = string.Empty;
TxComponent objComp = TxApplication.ActiveSelection.GetAllItems()[0] as TxComponent;
objComp.SetModelingScope();
TxApplication.RefreshDisplay();
TxKinematicLink objFixLink = objComp.CreateLink(new TxKinematicLinkCreationData("fix"));
TxKinematicLink objMoveLink = objComp.CreateLink(new TxKinematicLinkCreationData("move"));
TxJoint objJoint = objComp.CreateJoint(new TxJointCreationData("TEST_J1", TxJoint.TxJointType.Revolute, objFixLink, objMoveLink));
objJoint.Axis = new TxJointAxis(new TxVector(0, 0, 0), new TxVector(0, 0, 100));
//txFrame,TxKinematicLink,ITxGeometry,TxGroup
TxTypeFilter filter = new TxTypeFilter(typeof(ITxObject));
filter.AddExcludedType(typeof(TxFrame));
filter.AddExcludedType(typeof(TxKinematicLink));
TxObjectList objs = objComp.GetDirectDescendants(filter);
//TxObjectList objs = objComp.GetDirectDescendants(new TxTypeFilter(typeof(ITxObject)));
foreach (ITxObject obj in objs)
{
dbg = dbg + obj.Name + "|";
}
MessageBox.Show(dbg);
TxObjectList insList = new TxObjectList();
for (int i = 0; i < 10; i++)
{
insList.Add(objs[i]);
//objs[i].Delete();
}
objFixLink.Paste(insList);
foreach (ITxObject obj in insList)
{
obj.Delete();
}
//TxObjectList objs = TxApplication.ActiveSelection.GetItems();
////ITxDevice dev = TxApplication.ActiveSelection.GetAllItems()[0] as ITxDevice;
//if (objs.Count == 1)
//{
// ITxGun gun = objs[0] as ITxGun;
// if (gun != null)
// {
// dev.SetModelingScope();
// TxApplication.RefreshDisplay();
// }
//}
TxDevice newDevice = objJoint.Device as TxDevice;
ArrayList valuesV = new ArrayList();
ArrayList valuesR = new ArrayList();
valuesV.Add(System.Convert.ToDouble(0));
valuesR.Add(System.Convert.ToDouble(1));
TxObjectList modelables = objComp.GetAllDescendants(new TxTypeFilter(typeof(ITxKinematicsModellable)));
foreach (ITxKinematicsModellable modelable in modelables)
{
foreach (TxJoint poseJoint in modelable.Joints)
{
valuesV.Add(System.Convert.ToDouble(0));
ITxJointHardLimits limits = poseJoint.HardLimits;
if (!(limits is TxJointConstantHardLimits))
valuesR.Add(System.Convert.ToDouble(0));
else
{
TxJointConstantHardLimits hardLimits = limits as TxJointConstantHardLimits;
if (hardLimits.UpperLimit == 0.0D)
valuesR.Add(hardLimits.LowerLimit);
else
valuesR.Add(hardLimits.UpperLimit);
}
}
}
newDevice.CreatePose(new TxPoseCreationData("V", new TxPoseData() { JointValues = valuesV }) { CreateAtInstance = false });
newDevice.CreatePose(new TxPoseCreationData("R", new TxPoseData() { JointValues = valuesR }) { CreateAtInstance = false });
updateJointValue(newDevice);
}
private void updateJointValue(TxDevice newDevice)
{
TxPoseCreationData poseCreationData = new TxPoseCreationData("Pose", newDevice.CurrentPose);
//poseCreationData.PoseData.JointValues;
}