IImplementationObjectProviderExtension

class

IImplementationObjectProviderExtension.

IImplementationObjectProviderExtension

Bases: object

Class provides access to the interface and implementation text of a POU. This extension is written for texting purposes. Only ST is supported.

implementation_language

Retrieves the identifier Guid of the implementation language used for this POU. The identifiers correspond to the identifiers provided by global instance 'ImplementationLanguages'. Usage Example: myPou = ... if (myPou.implementation_language == ImplementationLanguages.st): print("The POU is implemented in Structured Text")

Type

Guid?

get_implementation_text

Retrieves the implementation text.

Returns

Returns a string of the implementation text.

Return type

string

This example shows how to get the implementation text of a POU.

if not projects.primary:
	system.ui.error('No primary project set')
	
p = projects.primary
pou = p.find('SR_Main', True)[0]
code = pou.get_implementation_text()
print(code)

get_interface_text

Retrieves the interface text.

Returns

Returns the interface text.

Return type

string

This example shows how to get the text of the POU declaration part.

if not projects.primary:
	system.ui.error('No primary project set')
	
p = projects.primary
pou = p.find('SR_Main', True)[0]
decl = pou.get_interface_text()
print(decl)

set_implementation_text

implementationText

Sets the implementation text of the pou.

Parameters

implementationText (string) -- The new implementation text, that is to be set.

This example shows how to set the text of the POU implementation part and the declaration part.

decl = "PROGRAM SR_Main\n" + \
			"VAR\n" + \
			"	iTest: INT;\n" + \
			"END_VAR";

code = "iTest := iTest +1;"
			
if not projects.primary:
	system.ui.error('No primary project set')
	
p = projects.primary
pou = p.find('SR_Main', True)[0]

pou.set_interface_text(decl)
pou.set_implementation_text(code)

set_interface_text

interfaceText

Sets the interface text of the pou.

Parameters

interfaceText (string) -- The new interface text, that is to be set.

This example shows how to set the text of the POU implementation part and the declaration part.

decl = "PROGRAM SR_Main\n" + \
			"VAR\n" + \
			"	iTest: INT;\n" + \
			"END_VAR";

code = "iTest := iTest +1;"
			
if not projects.primary:
	system.ui.error('No primary project set')
	
p = projects.primary
pou = p.find('SR_Main', True)[0]

pou.set_interface_text(decl)
pou.set_implementation_text(code)

has_nwl_implementation

Retrieves a value indicating whether this IScriptObject has a nwl implementation part.

get_networks

Retrieves a list of the networks inside a POU.

This example shows how to get and analyze the networks of a POU and remove some of the contained items.

# Script shows how to get and analyze the network list of a POU and remove some of the containing items.
# We enable the new python 3 print syntax
from __future__ import print_function

# Define the printing function
def print_networks():
	# Prints all networks
	for network in pou.get_networks():
		print(
			"id: %3d, network_number: %2d, title: %-10s, comment: %-20s, label: %-20s, out_commented: %-5s, network_item_count: %2d" %
			(network.id, network.network_number, network.title, network.comment, network.label, network.out_commented, network.network_item_count)
		)

if not projects.primary:
	system.ui.error('No primary project set')

proj = projects.primary

# Get main POU
pou = proj.find("SR_Main", True)[0]

# Get first network and print out comment
first_network = pou.get_network(1)
print("First network's comment: %s" % first_network.comment)

# Print out all networks
print("Before action:")
print_networks()

# Remove all out commented networks
for network in pou.get_networks():
	if network.out_commented: pou.remove_network(network.network_number)

print("After action:")
print_networks()
Returns

Returns a list of the IScriptNetwork s.

Return type

get_network

network_number

Retrieves a network inside a POU specified by its network number.

Parameters

network_number (int) -- The network number.

This example shows how to get and analyze the networks of a POU and remove some of the contained items.

# Script shows how to get and analyze the network list of a POU and remove some of the containing items.
# We enable the new python 3 print syntax
from __future__ import print_function

# Define the printing function
def print_networks():
	# Prints all networks
	for network in pou.get_networks():
		print(
			"id: %3d, network_number: %2d, title: %-10s, comment: %-20s, label: %-20s, out_commented: %-5s, network_item_count: %2d" %
			(network.id, network.network_number, network.title, network.comment, network.label, network.out_commented, network.network_item_count)
		)

if not projects.primary:
	system.ui.error('No primary project set')

proj = projects.primary

# Get main POU
pou = proj.find("SR_Main", True)[0]

# Get first network and print out comment
first_network = pou.get_network(1)
print("First network's comment: %s" % first_network.comment)

# Print out all networks
print("Before action:")
print_networks()

# Remove all out commented networks
for network in pou.get_networks():
	if network.out_commented: pou.remove_network(network.network_number)

print("After action:")
print_networks()
Returns

Returns the specified IScriptNetwork .

Return type

remove_network

network_number

Removes a network inside a POU specified by its network number.

Parameters

network_number (int) -- The network number.

This example shows how to get and analyze the networks of a POU and remove some of the contained items.

# Script shows how to get and analyze the network list of a POU and remove some of the containing items.
# We enable the new python 3 print syntax
from __future__ import print_function

# Define the printing function
def print_networks():
	# Prints all networks
	for network in pou.get_networks():
		print(
			"id: %3d, network_number: %2d, title: %-10s, comment: %-20s, label: %-20s, out_commented: %-5s, network_item_count: %2d" %
			(network.id, network.network_number, network.title, network.comment, network.label, network.out_commented, network.network_item_count)
		)

if not projects.primary:
	system.ui.error('No primary project set')

proj = projects.primary

# Get main POU
pou = proj.find("SR_Main", True)[0]

# Get first network and print out comment
first_network = pou.get_network(1)
print("First network's comment: %s" % first_network.comment)

# Print out all networks
print("Before action:")
print_networks()

# Remove all out commented networks
for network in pou.get_networks():
	if network.out_commented: pou.remove_network(network.network_number)

print("After action:")
print_networks()