CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Mon Feb 24, 2020 9:08 pm

All times are UTC+01:00




Post new topic  Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Fri Jan 03, 2020 12:15 am 
Offline

Joined: Wed Oct 23, 2019 5:55 pm
Posts: 6
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


Top
   
PostPosted: Thu Jan 09, 2020 10:45 am 
Offline
Frequent User
Frequent User

Joined: Tue Nov 13, 2012 9:20 am
Posts: 262
Hi Haritha.

hpulletikurti3 wrote:
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:
Code:
from __future__ import print_function

import string

def get_name(obj):
    if obj is None:
        return '<None>'
    return obj.get_name(False)

def get_object(change):
    if change.left_object is None:
        return change.right_object
    else:
        return change.left_object

project1 = projects.primary
project2 = projects.open(r"c:\temp\Project-B.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)

    print("Object %s: %s" % (name, str(change.differences)))
   
project2.close()

BR
Martin

_________________
Check out the CODESYS store: http://store.codesys.com/

CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions


Top
   
PostPosted: Thu Jan 09, 2020 9:32 pm 
Offline

Joined: Wed Oct 23, 2019 5:55 pm
Posts: 6
Thanks a million for this help. This is all I need.

-Haritha


Top
   
PostPosted: Thu Jan 09, 2020 11:10 pm 
Offline

Joined: Wed Oct 23, 2019 5:55 pm
Posts: 6
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


Top
   
PostPosted: Wed Jan 15, 2020 9:42 am 
Offline
Frequent User
Frequent User

Joined: Tue Nov 13, 2012 9:20 am
Posts: 262
Hi Haritha.

hpulletikurti3 wrote:
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 wrote:
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

_________________
Check out the CODESYS store: http://store.codesys.com/

CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions


Top
   
PostPosted: Wed Jan 22, 2020 11:07 pm 
Offline

Joined: Wed Oct 23, 2019 5:55 pm
Posts: 6
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)

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)

print("Object %s: %s" % (name, str(change.differences)))

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


You do not have the required permissions to view the files attached to this post.


Top
   
PostPosted: Tue Jan 28, 2020 11:48 am 
Offline
Frequent User
Frequent User

Joined: Tue Nov 13, 2012 9:20 am
Posts: 262
Hi Haritha.

hpulletikurti3 wrote:
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

_________________
Check out the CODESYS store: http://store.codesys.com/

CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions


Top
   
PostPosted: Thu Feb 13, 2020 10:28 pm 
Offline

Joined: Wed Oct 23, 2019 5:55 pm
Posts: 6
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


Top
   
PostPosted: Fri Feb 14, 2020 7:56 am 
Offline

Joined: Tue Mar 26, 2019 4:28 pm
Posts: 95
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.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 9 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited