# # This file is: mrpcs.py # # Move Relatively Positioned Component Set # # Rev. 1.0 15-Mar-2015 # # # -i input_fileneam : required # -o output_filename : optional # -dx Delta_X value : required or defaults to 0.0 # -dy Delta_Y value : required or defaults to 0.0 # # # For the Comp layout it would be nice to be able to move # a "Relatively Positioned Set of Components" by some # displacement delta_X delta_Y # # MRPCS (Move Relatively Positioned Comp Set) # # > python mrpcs.py -i input_comps_filename -dx delta_X_value -dy delta_Y_value # # It adjusts all comp X,Y values in the file input_comps_filename # by delta_X delta_Y and then using these new x,y values # the program writes a new version of this comp file with # the filename extension .mrpcs. # # # Recall the general format of the Mentor Components File # any number of spaces =>1 may appear between fields # # # # # Some Comments, possibly many lines of them or possibly none # # # # UNITS mm # # # # # Board_Location # # Ref Part_Number Symbol Geometry X Y Properties # #----- ----------- ------ ------------------ -------------- ---------- # # # # # # C505 Cap_1_nFd_0603 SY_JUNK rc0603 45.00 79.00 1 0 # # R501 Res_50_Ohm_0603 SY_JUNK rc0603 45.00 74.00 1 0 # # # More Comments at anytime, then more real component statements # # R5 Res_1k_Ohm_0603 SY_JUNK rc0603 5.00 0.00 1 0 # # # # # Note: If the Mentor Components file has an incorrect format # then this program may/will not operate correctly. # Specifically each line in the Comps file needs to be either: # a blank line # a Mentor UNITS Statement # a comment starting with a # sign # or a properly formated Mentor Component Statement # # # import sys import string usage_string = ' \n' \ + 'Usage: \n' \ + ' python mrpcs.py -i input_comps_filename \n' \ + ' [ -o output_comps_filename ] \n' \ + ' [ -dx delta_x value ] \n' \ + ' [ -dy delta_y value ] \n' \ + ' where: \n' \ + ' if not specified then the output \n' \ + ' filename = input filename.mrpcs \n' \ + ' and \n' \ + ' if not specified then delta_x and \n' \ + ' delta_y default to zero \n' # ##print usage_string # Default Initial Parameter Values # -------------------------------- input_comps_file_name = "" output_comps_file_name = "" Delta_X = 0.0 Delta_Y = 0.0 word_num_x = 4 word_num_y = 5 # Read and Parse Command Line Arguments # ------------------------------------- command_line_argument = sys.argv[1:] cmdarg_tot = len ( command_line_argument ) cmdarg_num = 0 while ( cmdarg_num < cmdarg_tot ) : # check for known argument switch and that there will always be a filename after the switch if ( ( command_line_argument[cmdarg_num] not in ( "-i", "-o", "-dx", "-dy" ) ) or ( cmdarg_num+1 >= cmdarg_tot ) or ( command_line_argument[cmdarg_num+1][:1] == "-" ) ) : status = "Command line error at argument <%s>" % command_line_argument[cmdarg_num] print "" print status print "" print usage_string print "" sys.exit( 1 ) # input comps filename elif ( command_line_argument[cmdarg_num] == "-i" ) : input_comps_file_name = command_line_argument[cmdarg_num+1] # output comps filename elif ( command_line_argument[cmdarg_num] == "-o" ) : output_comps_file_name = command_line_argument[cmdarg_num+1] # Delta_X Value elif ( command_line_argument[cmdarg_num] == "-dx" ) : Delta_X = eval ( command_line_argument[cmdarg_num+1] ) # Delta_Y Value elif ( command_line_argument[cmdarg_num] == "-dy" ) : Delta_Y = eval ( command_line_argument[cmdarg_num+1] ) cmdarg_num = cmdarg_num + 2 # Verify that we have an Input File # --------------------------------- if ( input_comps_file_name == "" ) : status = "Please provide Mentor comps filename" print "" print status print "" print usage_string print "" sys.exit( 1 ) # Check for Output Filename and Assign One if Necessary # ----------------------------------------------------- if ( output_comps_file_name == "" ) : output_comps_file_name = input_comps_file_name + ".mrpcs" # Print the Argument Values that will be used in this run of MRPCS # ---------------------------------------------------------------- print "" print " Input comps filename is: <%s>" % input_comps_file_name print " Output comps filename is: <%s>" % output_comps_file_name print " Delta_X is: <%f>" % Delta_X print " Delta_Y is: <%f>" % Delta_Y print "" # Open the Input and Output files # ------------------------------- input_comps_file = open ( input_comps_file_name, "r" ) output_comps_file = open ( output_comps_file_name, "w" ) # Read Input File Lines to Get Started # ------------------------------------ input_lines = input_comps_file.readlines() # Process the Components File One Line at a Time # ---------------------------------------------- input_line_num = 0 for input_line in input_lines : input_line_num += 1 input_line_words = input_line.split() # IF this line starts with UNITS then it is a # Mentor Units Statement and the whole line # should be copied to the output file and # processing should move on to the next line. if ( input_line[:5] == "UNITS" ) : output_comps_file.write ( input_line ) # IF this line starts with # sign then it # is a comment and the whole line should be # copied to the output file and processing # should move on to the next line. elif ( input_line[:1] == "#" ) : output_comps_file.write ( input_line ) # ELSE this line is a real Mentor Component Statement. # Process the Component Statement lines one word at a # time, changing the X and Y values as necessary, to # build the output line. else : output_line = "" for word_num in range ( len(input_line_words) ) : # the default is just to copy the word from the input to the output output_line_word = input_line_words[word_num] # But IF this word is the X or Y Coordinate if (word_num == word_num_x) : # Make the Delta_X change to the X Coordinate # and replace the default output word conv_coord_int = Delta_X + eval ( output_line_word ) conv_coord_str = "%f" % conv_coord_int output_line_word = conv_coord_str elif (word_num == word_num_y) : # Make the Delta_Y change to the Y Coordinate # and replace the default output word conv_coord_int = Delta_Y + eval ( output_line_word ) conv_coord_str = "%f" % conv_coord_int output_line_word = conv_coord_str # tack the appropriate version of the # output_line_word into the output line output_line = "%s%s " % ( output_line, output_line_word ) # write the output line output_comps_file.write ( "%s\n" % output_line ) # Close the Input and Output files # -------------------------------- input_comps_file.close () output_comps_file.close () # Inform the User that We Are Finished Mondifying the Components File # ------------------------------------------------------------------- print "" print " MRPCS has finished changing the component locations by " print " Delta_X, Delta_Y and the output file has been writen." print "" Fini = " Ca" Fini = Fini + " Suffit" print Fini print "" print ""