How to create a cdb with ET (instead of ETBLOCK), but have all other commands blocked?
Rohith Patchigolla
Member, Moderator, Employee Posts: 206
✭✭✭✭
in Structures
Answers
-
You can create both the default (blocked) and unblocked (fmat option in CDWRITE command) cdb files and use the below Python script to create a new cdb file which will have all the commands as blocked except for ET and Keyopt i.e. instead of ETBLOCK one would have ET and Keyopt commands in the cdb file.
You can run the python script in a normal python console, or Mechanical scripting console (inside Mechanical --> Automation ribbon --> Scripting) or WB scripting console (File --> Open --> Command Window)
#Inputs - Please rename the default and ublocked files as shown below. originalCDBFileName = "file_default.cdb" originalUnblockedCDBFileName = "file_unblocked.cdb" #Provide a location where the default and unblocked cdb files are stored. workingDir = r"D:\del\cdb_test" #Name of the modified cdb file created modifiedCDBFileName = "file_modified.cdb" import os #Read the CDB file and extract part of it based on Start and Stop keywords def read_and_extract(file_name, output_file_name, start_text,stop_text): writeFile = False with open(file_name, 'r') as input_file: with open(output_file_name, 'w') as output_file: for line in input_file: if line.split(",")[0] == start_text: writeFile = True if writeFile == True: if line.split(",")[0] == stop_text: break output_file.write(line) #Combine multiple files into a single file def combine_files(input_files, output_file): with open(output_file, 'w') as combined_file: for file_name in input_files: with open(file_name, 'r') as input_file: combined_file.write(input_file.read()) combined_file.write('\n') # Add a newline character between files #We read the original CDB file which has ETBLOCK commands and simply extract the text before and after the ETBLOCK command set #We also read the unblocked CDB file and extract the ET and KEYOPT commands that would be replacement for ETBLOCK commands #We then combine all the pieces to create a new CDB file, which has no ETBLOCK but ET & KEYOPT and readable in MATSA #Extract Part1 of the CDB file from the beginning to just before when ETBLOCK command starts read_and_extract(os.path.join(workingDir,originalCDBFileName), os.path.join(workingDir,"filePart1.cdb"),"/COM","ETBLOCK") #Extract Part 2 of the CDB file (Unblocked) which would be replacement for ETBLOCK commands from the Original CDB file. read_and_extract(os.path.join(workingDir,originalUnblockedCDBFileName), os.path.join(workingDir,"filePart2.cdb"),"ET","N") #Extract Part 3 of the CDB file from where "NBLOCK" command starts till the end. read_and_extract(os.path.join(workingDir,originalCDBFileName), os.path.join(workingDir,"filePart3.cdb"),"NBLOCK","") #Combine the pieces extracted from original and unblocked CDB files input_file_names = [os.path.join(workingDir,"filePart1.cdb"),os.path.join(workingDir,"filePart2.cdb"),os.path.join(workingDir,"filePart3.cdb")] output_file_name = os.path.join(workingDir,modifiedCDBFileName) combine_files(input_file_names, output_file_name) #Remove the temporary files not needed anymore for file in input_file_names: os.remove(file)
0