How can I copy a script that is used in one project to another project via Python?

Category:
Scripting
Answer

For this tasks you should use the AddCopy() method. For more information on this method refer to our Python technical reference.

Example:

import powerfactory

app=powerfactory.GetApplication()

user= app.GetCurrentUser() #accessing the current activated user

# Inactive Project- Project where the script is saved

InactiveProject=user.GetContents(‘NameOfTheProject.IntPrj')[0][0] #accessing to the inactivated project

ObjectToCopy=InactiveProject.GetContents('ToBeCopied.ComDpl',1)[0][0] #call the script you would like to copy

app.PrintPlain(ObjectToCopy.IntExpr)

#Active Project-Where the script should be copy into

StudyCasesFolder=app.GetProjectFolder('study') #call ProjectFolder StudyCases from the activated project

StudyCase= StudyCasesFolder.GetContents()[0]

app.PrintPlain(StudyCase)

NewCopiedObject=StudyCase.AddCopy(ObjectToCopy,'CopiedObject_',ObjectToCopy.loc_name) #copy the ObjectToCopy object inside of StudyCase

Back