Dear Community User! We have started the migration process.
This community is now in READ ONLY mode.
Read more: Important information on the platform change.

cancel
Showing results for 
Search instead for 
Did you mean: 
SOLVED

Execute a Python script from any directory.

Execute a Python script from any directory.

Felix_
Established Member

Hi everyone, 

I was experimenting with the Python runtime app and discovered that I can only run my script from the main folder activeConfiguration located at /var/snap/rexrothautomationcore/common/solutions/activeConfiguration. Even after setting all the necessary permissions for the folder and the script, it still only works from this specific directory. 

Felix__1-1731422715040.png

Is this due to security restrictions, or am I missing something? I don't want to clutter the main folder with multiple Python files.

Thank you

 

5 REPLIES 5

Sgilk
Frequent Contributor

@Felix_ ,

I think this is actually a problem with the script instance rather than the script. Is it possible you are just not returning properly from script execution? You can try adding exit(0) at the bottom of your script.

How are you executing the script? Where is the script you are trying to run located? I can execute without error at /scripts/main.py

Felix_
Established Member

Hi @Sgilk thank you for the answer,

I changed my script with a basic helloword and i still have the error 😒.

Following this How To , i execute the script from the PLC : 

Felix__2-1731938463006.png

 

 

Felix__1-1731938250632.png

 

 

I guess my path isn't good, i get this error : 

Felix__0-1731938132113.png

 

and again my test.py script works in the folder /var/snap/rexroth-automationcore/common/solutions/activeConfiguration/test.py
but not in /var/snap/rexroth-automationcore/common/solutions/activeConfiguration/scripts/test.py

Except for updating the path in the PLC and creating a new instance, nothing else should change, no ?

Thank you

 

Sgilk
Frequent Contributor

@Felix_ ,

Try using the symlink 'activeConfiguration/script/test.py'. The path you have listed is too long for a STRING(80). Both of your listed paths work in my test project attached. Set .HMI_Variables.bStartScript TRUE to execute the python script on interpreter instance Demo1.

Felix_
Established Member

@Sgilk,

Thank you, the new link works 💪. I never would have expected that the length of my path was causing the error.

One last question: with the IDE app, we can't import and use the Python runtime libraries ?

for examples : 

Felix__0-1732004572006.png

 

Thanks again

 

Sgilk
Frequent Contributor

@Felix_ ,

To use the integrated datalayer library with intellisense...

 

import ctrlxpy.datalayer as datalayer

 

Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist