class
IScriptAnalysisData.
IScriptAnalysisData
Bases: object
reasoning
Get access to reasoning API.
edges
Retrieves the edges of the analyzed application or library.
List of IScriptEdge
The example shows how code analysis data can be queried, using edges to find all FunctionBlock instances in an application.
# Generate analysis data for the application
analysis_data = projects.primary.active_application.code_analysis.get_analysis_data()
# We want to get all instances of any function blocks inside the Application
# Find all edges that are an "IsA"-Edge, with a variable as the source and a FunctionBlock as the target.
# This means we are looking for the variables that are FunctionBlocks. After that we select the name of the source which is the variable name.
instances = analysis_data.edges.where(
lambda e : (e.type == EdgeTypes.IsA) &
(e.source.fullname.startswith('Application.')) &
(e.source.type == NodeTypes.Variable) &
(e.target.type == NodeTypes.FunctionBlock)
).select(
lambda n : ( n.source.fullname)
)
# Print all instance names
for instance in instances:
print(instance)
nodes
Retrieves the nodes of the analyzed application or library.
List of IScriptNode
The example shows how code analysis data can be queried, using nodes to find all variables with a name longer than 40 characters.
# Generate analysis data for the application
analysis_data = projects.primary.active_application.code_analysis.get_analysis_data()
# We want to get all variables inside the application that have a name which is longer than 40 characters
# Select all nodes and filter for those that satisfy the following conditions:
# - Must have a name with a length of over 40
# - Must be a variable
# - Must be inside the Application and not for example inside a library
# Of the found variables only the full name is selected
variables = analysis_data.nodes.where(
lambda n : (len(n.name) > 40) &
(n.type == NodeTypes.Variable) &
(n.fullname.startswith('Application.'))
).select(
lambda n : ( n.fullname)
)
# Print all variable names
for variable in variables:
print(variable)
get_edge
uri
Retrieves a edge specified by uri.
get_edges
type
Retrieves edges of specified type.
get_node
fullname
Retrieves a node specified by its fullname.
fullname (string) -- The fullname of a node
get_nodes
name
Retrieves nodes specified by its name.
execute
query_chain
Executes a query chain and returns the result as list of IScriptElementBase .
query_chain (IScriptQueryChain) -- The query chain to execute
A list of IScriptElementBase
IList
The example shows how code analysis data can be queried. For this a SPARQL Query is created and executed to find all FunctionBlock instances in an application.
# Generate analysis data for the application
analysis_data = projects.primary.active_application.code_analysis.get_analysis_data()
# We want to get all instances of any function blocks inside the Application
# Write a SPARQL query for that and execute it using the execute method
instances = analysis_data.execute(
"""SELECT ?FullName WHERE
{
?VarNodeId a :Variable;
:FullName ?FullName.
?EdgeId a :IsA;
:Source ?VarNodeId ;
:Target ?TargetNodeId .
?TargetNodeId a ?TargetType .
FILTER(?TargetType = :FunctionBlock && strstarts(?FullName, 'Application') )
} """)
# Print all instance names
for instanceResultRow in instances:
print(instanceResultRow.values[0].value)