Jump to content

import python module from a script in current file


twk

Recommended Posts

I suppose that it is possible, however "import" uses the current sys.path which might not what you want

 

The possibilities I see are:

- modify sys.path to have the path you need

- use one of the functions of https://docs.python.org/3.5/library/runpy.html (if it suits you)
- use one of the functions of https://docs.python.org/3.5/library/importlib.html

 

As I have never used any of them from the Python provided with VW, I am not sure what the best solution might be.

 

 

Link to comment
  • 2 weeks later...
  • 1 year later...

In Vectorscript the following will get you a handle to a script object in the current file. I have not figured out how to get the text out of the object to be able to run it. I don't think there is a way to run Vectorscript, but PythonExecute should work IF you can find a way to get the text out of the handle to the object.

 

Procedure Test;

Var    NumItems, ListID:LongInt;
    H1:Handle;
    S1:DynArray of Char;

Begin
    ListId:=BuildResourceList2(49,0,'',NumItems,False);
    AlrtDialog(Concat(ListID,'  -  ',NumItems));
    H1:=GetResourceFromList(ListID,1);
    AlrtDialog(GetName(H1));
End;

Run(Test);

Procedure Test;

Var	NumItems, ListID:LongInt;
	H1:Handle;
	S1:DynArray of Char;

Begin
	ListId:=BuildResourceList2(49,0,'',NumItems,False);
	AlrtDialog(Concat(ListID,'  -  ',NumItems));
	H1:=GetResourceFromList(ListID,1);
	AlrtDialog(GetName(H1));
End;

Run(Test);

 

  • Like 2
Link to comment
  • 9 months later...

I would like to do the same. I'm testing the function vs.GetScriptResource('Nameofmyscript)[1].

 

If I run a Script like this:

text = str(vs.GetScriptResource('Ebenenauswahl')[1])

vs.CreateText(text)

I get all the text of my script. But if I want to use a name out of 'Ebenenauswahl' it says "name '...' is not defined.

 

What am I missing?

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...