Jump to content
twk

import python module from a script in current file

Recommended Posts

As the title suggests, is this possible? If so, what is the syntax?

 

image.thumb.png.152ee13d81e84c4d6eda6aa7c725e6e3.png

  • Like 1

Share this post


Link to post

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.

 

 

Share this post


Link to post

No I meant, I'm trying to import a module from a script inside the VWX file.

 

Share this post


Link to post

I had the same problem

You have to add the path file into the "Script Options..." dialog

Is that what you meant twk?

971469283_Schermata2020-01-17alle23_39_54.thumb.png.9399d17e41a56781774d0a863e03f585.png

Share this post


Link to post

I was wanting to call a function from another script that is within the document resources. Not on a file somewhere else on the computer.

cheers

  • Like 1

Share this post


Link to post

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

Share this post


Link to post

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.


 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×
×
  • Create New...