43.1.10.1. Read the *.rplt file without running RecurDyn
Get the data from the RPLT file without running RecurDyn through the Python code.
from recurdyn import *
from recurdyn.utils.rplt import RpltReader
from recurdyn import Chart
# Common Variables
app = None
application = None
model_document = None
plot_document = None
model = None
ref_frame_1 = None
ref_frame_2 = None
# Post Common Variable
post_main_document = None
post_main_window = None
# initialize() should be called before ProcessNet function call.
def initialize():
global app
global application
global model_document
global plot_document
global model
app = dispatch_recurdyn()
application = IApplication(app.RecurDynApplication)
model_document = application.ActiveModelDocument
if model_document is not None:
model_document = IModelDocument(model_document)
plot_document = application.ActivePlotDocument
if plot_document is not None:
plot_document = IPlotDocument(plot_document)
if model_document is None and plot_document is None:
application.PrintMessage("No model file")
model_document = application.NewModelDocument("Examples")
if model_document is not None:
model_document = IModelDocument(model_document)
model = ISubSystem(model_document.Model)
return application, model_document, plot_document, model
# dispose() should be called after ProcessNet function call.
def dispose():
global application
global model_document
model_document = application.ActiveModelDocument
if model_document is not None:
model_document = IModelDocument(model_document)
else:
return
if not model_document.Validate():
return
# Redraw() and UpdateDatabaseWindow() can take more time in a heavy model.
model_document.Redraw()
# model_document.PostProcess() # UpdateDatabaseWindow(), SetModified()
model_document.UpdateDatabaseWindow()
# If you call SetModified(), Animation will be reset.
model_document.SetModified()
model_document.SetUndoHistory("Python ProcessNet")
# Intialize global variable
application, model_document, plot_document, model = initialize()
# Intialize global variable for Post. Uncomment out if you use ProcessNet Post.
# post_application, post_main_window, post_main_document = initialize_post()
# Your code is here!
#RPLT File Path
rplt_path = "D:\\Plot\\Simple.rplt"
#RpltReader
rplt_reader = RpltReader()
rplt_reader.import_file(rplt_path)
#Gets the value of an element of the RPLT. The starting value is 0
name_list = rplt_reader.get_plottable_name_list()
#Input an entity name, returns the value of that entity.
plot_data_body1_pos_tm = rplt_reader.get_plot_data("Bodies/Body1/Pos_TM")
plot_data_time = rplt_reader.get_plot_data(name_list[0])
# draw curve
plot_document = application.ActivePlotDocument
if plot_document is None:
plot_document = model_document.CreatePlotDocument(Chart.PlotDocType.Empty)
chart1 = Chart.IChart(plot_document.ActiveChartControl)
plot_document.DrawPlot("Pos_TX", plot_data_time, plot_data_body1_pos_tm)
dispose()