Digital Art Zone

 
     
DazScript import external script file?
Posted: 25 October 2012 03:51 PM   [ Ignore ]
Member
Rank
Total Posts:  54
Joined  2010-09-22

Simple question—I’ve built a library of utility functions located in a file “tools.dsa”.  I want to include that script from another Daz script so that I can call the functions in it.  How do I do this? 

I’ve tried :

import("tools.dsa"); 

No error, but my functions aren’t available from the calling script.  I’ve dug around DazScript and QTScript docs but can’t seem to find an answer.  I found the DzScript object but that doesn’t appear to be what I need.

Thanks

 

Profile
 
 
Posted: 26 October 2012 12:24 AM   [ Ignore ]   [ # 1 ]
Administrator
Avatar
RankRank
Total Posts:  372
Joined  2003-10-09

void include( String scriptPath

Includes the contents of scriptPath in the same context as the calling script. This function should only be called within the global scope of the script; it should not be called within a nested scope and it should not be called inline. As a safeguard against circular references, the script engine keeps an internal list of unique paths for included scripts; per script context, per execution. Each time the function is called, scriptPath is checked against the list to ensure that the path has only been included once within the context of the script.

Parameters:
    scriptPath  - The path of the script to include. The path is assumed to be relative to the ./scripts directory. Absolute paths are also supported.

-Rob

 Signature 

- Documentation Center
- Install Manager
- DAZ Studio 4.x
- DSON Importer
- DSON File Format Specification

Profile
 
 
Posted: 28 February 2013 10:17 AM   [ Ignore ]   [ # 2 ]
Active Member
Avatar
RankRank
Total Posts:  488
Joined  2007-09-01

...but what if the imported DAZ script is in a random DAZ content directory? The code below seems to work, but…

n=App.getContentMgr().getNumContentDirectories()
sFile="";
i=0;
while (
i<=&& sFile=="")
{ s=App.getContentMgr().getContentDirectoryPath(i++)+"/scripts/ScriptName.dsa";
 
oNewFile = new DzFile(s);
 if (
oNewFile.exists())
  sFile
=s;
}
if (sFile!="")
{
 
include (sFile);
 
// Do more stuff
}
else
 
MessageBox.warning("Unable to find ScriptName.dsa. Terminating.""TITLE""&OK;""" ); 

...does it fall foul of the ”...should not be called within a nested scope and it should not be called inline” criteria?

(P.S. Of course, the ‘// Do more stuff’ involves calling the functions from the included file)

 

 Signature 

Website: UnrealImperfect | Freebies: Renderosity, ShareCG | ‘Art’: DeviantArt | Blog: Blogger
(aka Pete Williams)

Profile
 
 
Posted: 28 February 2013 01:48 PM   [ Ignore ]   [ # 3 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  15290
Joined  2003-10-09

An alternative, if you want to execute a script, is to use DzScript - that lest you load a script (DzScript.loadFromFile( name ) ) as an object and modify or execute it. The include command is like the equivalent directive in C or BASIC - it expands the included code and runs it as part of the flow of the script (it’s there to avoid duplication of code that needs to be used in multiple scripts without modification).

 Signature 

DAZ Studio Frequently Asked Questions

Index of free DAZ Studio scripts and plugins list

Profile
 
 
Posted: 11 March 2013 01:07 AM   [ Ignore ]   [ # 4 ]
Active Member
Avatar
RankRank
Total Posts:  488
Joined  2007-09-01

Thanks Richard, using DzScript seems to work fine.
But now I want to pass parameters to the script,  so I use ‘Boolean execute (Array args)’ as per the DAZ Script 2: DzScript docs:

o_Script = new DzScript(sFile); 
 
o_Script.loadFromFile(sFile,true)
 o_Script
.execute["Parameter-String1","Parameter-String2"]

I just can’t work out how to pick up those parameters in the called script!
rolleyes

 Signature 

Website: UnrealImperfect | Freebies: Renderosity, ShareCG | ‘Art’: DeviantArt | Blog: Blogger
(aka Pete Williams)

Profile
 
 
Posted: 11 March 2013 08:55 AM   [ Ignore ]   [ # 5 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  15290
Joined  2003-10-09

getArguments() returns the parameters as an array.

 Signature 

DAZ Studio Frequently Asked Questions

Index of free DAZ Studio scripts and plugins list

Profile