Hi @suraj.james6 .
Using the attached f3d file, I made a sample to get CenterOfMass while changing SlideValue.
The result will be displayed in the TextCommands palette.
# Fusion360API Python script
import adsk.core, adsk.fusion, traceback
def run(context):
ui = adsk.core.UserInterface.cast(None)
try:
app :adsk.fusion.Application = adsk.core.Application.get()
ui = app.userInterface
des :adsk.fusion.Design = app.activeProduct
root :adsk.fusion.Component = des.rootComponent
res = getCenterOfMass_SlideMotion(
root,
root.joints[0],
-10,
10,
1)
dumpMsg('\n'.join(res))
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def getCenterOfMass_SlideMotion(
targetComp :adsk.fusion.Component,
targetJoint :adsk.fusion.Joint,
minValue :float,
maxValue :float,
stepValue :float) -> list:
ui = None
try:
app = adsk.core.Application.get()
des = app.activeProduct
ui = app.userInterface
jm :adsk.fusion.JointMotion = targetJoint.jointMotion
originalValue = jm.slideValue
unitsMgr = des.unitsManager
defLenUnit = unitsMgr.defaultLengthUnits
covUnit = unitsMgr.convert(1, unitsMgr.internalUnits, defLenUnit)
com = targetComp.physicalProperties.centerOfMass
info = ['SlideValue,X{0},Y{0},Z{0}'.format(defLenUnit)]
value = minValue
while True:
jm.slideValue = value
info.append(f'{value}, {com.x * covUnit}, {com.y * covUnit}, {com.z * covUnit}')
value += stepValue
if value > maxValue:
break
jm.slideValue = originalValue
return info
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def dumpMsg(msg :str):
adsk.core.Application.get().userInterface.palettes.itemById('TextCommands').writeText(str(msg))
