I am trying to use python scripting to compare two Codesys projects. Can someone please help me how to achieve this ? I am very new to python scripting. I am using Codesys V3.
Thanks,
Haritha
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
hpulletikurti3 hat geschrieben:
I am trying to use python scripting to compare two Codesys projects. Can someone please help me how to achieve this ? I am very new to python scripting. I am using Codesys V3.
Here is a simple example:
from__future__importprint_functionimportstringdefget_name(obj):  ifobjisNone:    return'<None>'  returnobj.get_name(False)defget_object(change):  ifchange.left_objectisNone:    returnchange.right_object  else:    returnchange.left_objectproject1=projects.primaryproject2=projects.open(r"c:\temp\Project-B.project",primary=False)
\# project compare which ignores whitespace differencesdiff=project1.compare_to(project2,ComparisonFlags.IGNORE_WHITESPACE)forchangeindiff:Â Â obj=get_object(change)Â Â name=get_name(obj)Â Â print("Object %s: %s"%(name,str(change.differences)))Â Â project2.close()
BR
Martin
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I tried the above code. Got the change.differences printed.
Is there a way that I can generate the compare report using this i.e the report that gets generated when we select Project Menu > Compare...
I tried to use system.commands["project","compare"].execute(r"C:\TEMP\codesys\version3\Data\Test2.project")
but I am getting the error : wrong argument type for the batch command "project compare": Type "FILE/SC" expected for the argument 0
Can you please help me solve this?
Thanks,
Haritha
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
hpulletikurti3 hat geschrieben:
Is there a way that I can generate the compare report using this i.e the report that gets generated when we select Project Menu > Compare...
Do you want just some form of report or do you want to do depending of the compare result? What is your use case?
hpulletikurti3 hat geschrieben:
I tried to use system.commands["project","compare"].execute(r"C:\TEMP\codesys\version3\Data\Test2.project")
but I am getting the error : wrong argument type for the batch command "project compare": Type "FILE/SC" expected for the argument 0
Executing commands should only be used if the feature is missing in the Scripting which is not the case here. Please use the Scripting API for project compare.
BR
Martin
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
hpulletikurti3 hat geschrieben:
I am trying to generate a compare report that Codesys generate using Menu > Project> Compare > Report is attached
Can you please help me how I can get this using the API.
I still don't understand what you want. The screenshot CompareReportCapture.PNG shows the Project Compare view with the differences of the two projects. There is no report only some statistics at the bottom of the view.
BR
Martin
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
My intension is when I run the script it should open the Codesys V3 and simulate the Project Menu > Compare ( given two projects ) and shown the report that is shown in the CompareReportCapture.png.
I mean something like directing the mouse click to Project -> Compare -> and check the boxes for compare options click ok resulting in the report.
I want to run the script and get the above stated report.
Currently my script tells me whether difference of the object exists or not but does not show the actual report in the Codesys IDE.
My question is if the API is capable of doing this kind of directing? If API is capable, what am I missing in the script?
Hope I make some sense
Thanks for the help!
-Haritha
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I cannot use that... for some reason, instead of comparison, codesys just starts as normal, thats all. Maybe there is more exceptions then described on help page
Last edit: asivakov 2020-10-15
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I am trying to use python scripting to compare two Codesys projects. Can someone please help me how to achieve this ? I am very new to python scripting. I am using Codesys V3.
Thanks,
Haritha
Hi Haritha.
Here is a simple example:
BR
Martin
Thanks a million for this help. This is all I need.
-Haritha
Hi Martin,
I tried the above code. Got the change.differences printed.
Is there a way that I can generate the compare report using this i.e the report that gets generated when we select Project Menu > Compare...
I tried to use system.commands["project","compare"].execute(r"C:\TEMP\codesys\version3\Data\Test2.project")
but I am getting the error : wrong argument type for the batch command "project compare": Type "FILE/SC" expected for the argument 0
Can you please help me solve this?
Thanks,
Haritha
Hi Haritha.
Do you want just some form of report or do you want to do depending of the compare result? What is your use case?
Executing commands should only be used if the feature is missing in the Scripting which is not the case here. Please use the Scripting API for project compare.
BR
Martin
Hi Martin,
I am trying to generate a compare report that Codesys generate using Menu > Project> Compare > Report is attached
Can you please help me how I can get this using the API.
Below is my code.
from future import print_function
import os
import scriptengine
from scriptengine import projects
import string
scriptdir = os.path.dirname(file) # Directory of our script.
print(scriptdir);
datadir = os.path.join(scriptdir, "Data") # Enter the subdirectory.
print(datadir);
projectpathone = os.path.join(datadir, "Test1.project") # And add the project name.
print(projectpathone);
projectpathtwo = os.path.join(datadir,"Test2.project") # second project for comparision
print(projectpathtwo);
def get_name(obj):
if obj is None:
return '<none>'
return obj.get_name(False)</none>
def get_object(change):
if change.left_object is None:
return change.right_object
else:
return change.left_object
# Now, we can open the project.
proj = projects.open(projectpathone)
# We fetch the active application.
app = proj.active_application
project1 = projects.primary
project2 = projects.open(r"C:\TEMP\codesys\version3\Data\Test2.project", primary=False)
# project compare which ignores whitespace differences
diff = project1.compare_to(project2, ComparisonFlags.IGNORE_WHITESPACE)
for change in diff:
obj = get_object(change)
name = get_name(obj)
project2.close()
Please see the output in ScriptReport.PNG that I am seeing in the command prompt using the above script.
Thanks for the help.
-Haritha
Hi Haritha.
I still don't understand what you want. The screenshot CompareReportCapture.PNG shows the Project Compare view with the differences of the two projects. There is no report only some statistics at the bottom of the view.
BR
Martin
Hi Martin,
My intension is when I run the script it should open the Codesys V3 and simulate the Project Menu > Compare ( given two projects ) and shown the report that is shown in the CompareReportCapture.png.
I mean something like directing the mouse click to Project -> Compare -> and check the boxes for compare options click ok resulting in the report.
I want to run the script and get the above stated report.
Currently my script tells me whether difference of the object exists or not but does not show the actual report in the Codesys IDE.
My question is if the API is capable of doing this kind of directing? If API is capable, what am I missing in the script?
Hope I make some sense
Thanks for the help!
-Haritha
Maybe don't use script, just use command line switch is what you are after:
https://help.codesys.com/webapp/_cds_co ... n=3.5.15.0
If you figure out the --compare syntax that works for you please post back.
I cannot use that... for some reason, instead of comparison, codesys just starts as normal, thats all. Maybe there is more exceptions then described on help page
Last edit: asivakov 2020-10-15