AnsweredAssumed Answered

Motion Study Event Handling

Question asked by t c on Jun 30, 2010
Latest reply on Jul 3, 2010 by t c

Hi All,

 

I'm trying to write a macro that will execute code when a collision is detected.

 

So far I have

  1. built a model that has a rotating part that collides with another part once each revolution
  2. recorded a macro
  3. modified the macro to register for the PartCollideNotify Event.

 

However when I run the animation and the parts collide, the event is apparently not fired, or I am not picking it up and I have no idea why. Any help would be great.

 

Please see the code below:

 

 

 

swMotionStudy1 = swMotionMgr.GetMotionStudy("Motion Study 1");

 

swMotionStudy1.Activate();

swMotionStudy1.StudyType = (int)SolidWorks.Interop.swmotionstudy.swMotionStudyType_e.swMotionStudyTypePhysicalSimulation;

 

swMotionStudy1.SetFireOutputTimeStepEvents(true);

 

 



EventListener eventTest = new EventListener();

swMotionStudy1.PartCollideNotify += new DMotionStudyEvents_PartCollideNotifyEventHandler(eventTest.collisionTest);

 

swMotionStudy1.MotorOutputTimeStepChangeNotify += new DMotionStudyEvents_MotorOutputTimeStepChangeNotifyEventHandler(eventTest.timeTest);

 

swMotionStudy1.Calculate();





 





 

 

 

 



 

 





 

 

class EventListener

 

{

 



 

public int collisionTest(double Time, object Component1, object Component2, object Vector1, object Vector2, object SurfaceNormal1, object SurfaceNormal2)

{



 

Console.WriteLine("This is called when the event fires.");

return 1;

}



 

public int timeTest(double Time,object MotorNames,object Position,object Velocity,object Acceleration,object ForceOrTorque,ref object MotorValue)

{

 



Console.WriteLine("This is called when the event fires.");

return 1;

}

}

 

 

















Outcomes