I'm trying to select a motor from my motion study in a macro to change it's properties, but I'm having some trouble understanding the API help (no examples!). Can anyone point me in the right direction in either C# or VB?
I've made some progress, but not a lot.
I think I've been able to create a new motor using the following code:
motorDef = swMotionStudy1.CreateDefinition((int)swFeatureNameID_e.swFmAEMRotationalMotor) as SimulationMotorFeatureData; motorFeat = swMotionStudy1.CreateFeature(motorDef) as Feature; However, the motor does not appear in the Motion Feature Tree. What do I need to do to add the motor to the model?
motorFeat = swMotionStudy1.CreateFeature(motorDef) as Feature;
However, the motor does not appear in the Motion Feature Tree.
What do I need to do to add the motor to the model?
You probably have to add more information about the motor to the feature data. Here's a sample example.
Hope it helps,
You are right I needed to add more details to the motor data before creating the motor.
The remaining trouble that I am having is being able to change the properties of an already exiting motor. I couldn't see an equivalent method to CreateFeature for modifying a feature.
thanks for your help!
I've still not had an answer to this question. Can anyone help?
Here's some sample code that does what you want:
swDoc = ((ModelDoc2)(swApp.ActiveDoc)); studyMan = (IMotionStudyManager)swDoc.Extension.GetMotionStudyManager(); study = studyMan.GetMotionStudy("MotionStudy 1"); if (study.IsActive == false) study.Activate();
motionFeat = (object)study.GetMotionFeatures(); string featurename = ((IFeature)motionFeat).Name;
motorFeat = (ISimulationMotorFeatureData)((IFeature)motionFeat).GetDefinition(); motorFeat.MotionType = (int)swSimulationMotorMotionType_e.swSimulationMotorMotion_Spline; motorFeat.DriveType = (int)swSimulationMotorDriveType_e.swSimulationMotorDrive_Velocity; motorFeat.InterpolationScheme = (int)swInterpolationType_e.swAkimaInterpolation;
Component2 comp = ((Entity)motionFeat).IGetComponent2(); ((IFeature)motionFeat).IModifyDefinition2(motorFeat, swDoc, comp);
Don't forget to call IModifyDefinition2() after you change any feature data to apply the changes to the model.
Do you have the equivalent VB code for the above?
Retrieving data ...