function [theForce] = getQfForceX(x_position) %It is presumed that QuickField is already started, the problem is opened. %The plunger is placed in x=0 position %1. Move the plunger to proper position (x_position) %2. Calculate the force %3. Move the plunger back to zero position qf = actxserver ('QuickField.Application'); %get link to QuickField pbm = qf.Problems.Item(1); %get link to the problem pbm.LoadModel; %load model mdl = pbm.Model; %get link to the model %1. Move the plunger to proper position (x_position) %select the object to move, i.e. "insulation" %(the plunger core is attached to plunger insulation and would be moved automatically) theShape = mdl.Shapes.get ('LabeledAs','','','insulation'); %specify the displacement vector theVector = qf.PointXY(x_position, 0); %move the selected Shape theShape.Move('qfShift', theVector); mdl.Shapes.BuildMesh(); %build mesh in the model mdl.Save; %save model file %2. Calculate the force pbm.SolveProblem(); %solve the problem pbm.AnalyzeResults; %load results res = pbm.Result; %get link to the result %to calculate the force we should build integration contour %we build the contour in the field window theFieldWindow = res.GetFieldWindow(1); %open the field window theContour = theFieldWindow.Contour; %get link to the contour theContour.AddBlock1 ('plunger_core'); %add "plunger" block to contour %calculate the magnetic force integral theMagneticForce = res.GetIntegral('qfInt_MaxwellForce', theContour).Value; %3. Move the plunger back to zero position theVector = qf.PointXY(-x_position, 0); theShape.Move('qfShift', theVector); mdl.Save; theForce = theMagneticForce.X; %plunger is moved by the X-component of the force