remove_joint.py remove_joint #-*-coding:utf-8-*- importargparse importdnacalibasdnac importdna defloadDNA(path): stream=dna.FileStream(path,dna.FileStream.AccessMode_Read,dna.FileStream.OpenMode_Binary) reader=dna.BinaryStreamReader(stream,dna.DataLayer_All) reader.read() ifnotdna.Status.isOk(): status=dna.Status.get() raiseRuntimeError("ErrorloadingDNA:{}".format(status.message)) returnreader defsaveDNA(reader,path): stream=dna.FileStream(path,dna.FileStream.AccessMode_Write,dna.FileStream.OpenMode_Binary) writer=dna.BinaryStreamWriter(stream) writer.setFrom(reader) writer.write() ifnotdna.Status.isOk(): status=dna.Status.get() raiseRuntimeError("ErrorsavingDNA:{}".format(status.message)) defgetJoints(dna): joints=[] forjointIndexinrange(dna.getJointCount()): joints.append(dna.getJointName(jointIndex)) returnjoints defprintJoints(dna): forjointIndexinrange(dna.getJointCount()): print(dna.getJointName(jointIndex)) defcalibrateDNA(inputPath,outputPath): dna=loadDNA(inputPath) #CopiesDNAcontentsandwillserveasinput/outputparametertocommand calibrated=dnac.DNACalibDNAReader(dna) original_joints=getJoints(calibrated) #Anexamplejointtoremove joint_index=314 joint_name=calibrated.getJointName(joint_index) #Removesjointwithspecifiedindex command=dnac.RemoveJointCommand(joint_index) #ModifiescalibratedDNAin-place command.run(calibrated) modified_joints=getJoints(calibrated) if((len(modified_joints)!=(len(original_joints)-1))or(joint_nameinmodified_joints)): raiseRuntimeError("Jointnotremovedproperly!") print("Successfullyremovedjoint`{}`.".format(joint_name)) print("SavingDNA...") saveDNA(calibrated,outputPath) print("Done.") defmain(): parser=argparse.ArgumentParser(description="DNACalibremovejointexample") parser.add_argument('input_dna', metavar='input-dna', help='PathtoDNAfiletoload') parser.add_argument('output_dna', metavar='output-dna', help='PathwheretosavemodifiedDNAfile') args=parser.parse_args() calibrateDNA(args.input_dna,args.output_dna) if__name__=='__main__': main()