Getting Started with DAZ3D/LUA Scripting
neverstoplearning
Posts: 69
I know Javascript. I have written code in over 20 languages over the last 40+ years. But the Daz API is ... er, how shall I put it? ... not well documented.
I'd like to give back. If someone could "seed" me with a fragment, I'd be able to get going. I'd even be prepared to write some doc if/when I get to know my way around.
So this is what I'd like to do ...
- Start with a new workspace.
- Load a scene subset "A" with lights.
- Merge a scene subset "B" with buildings, props, etc.
- Merge several different scene subsets, ""C", "D", and "E" each with a single preconfigured character, with outfit, weapons, etc in it.
- Move the characters on all 3 axes. Rotate same.
- Apply purchased poses or locally saved poses to the characters.
- Save as a scene "S"
Can this be done with the Daz API? If anyone can help me with even PART of this, I'd de grateful.
Comments
Yes, most of that (except for the Move Characters bit) would just be using the DzContentMgr to load files and then to save, possibly with DzFileInfo to parse directories if you are wanting to work on watever fiels are found rather than specific files. DzNode gives access to the transforms, which are usually DzFloatProperty. All of those are documented http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/start
Thanks for that. I did find a post by you from back in 2012 and tried that. A single line script executed from the IDE:
App.getContentMgr().openFile( "...\\My Library\\Scenes\\test.duf", true );
This successfully loaded the file, a single previously saved figure (G3F Caro) with an outfit.. But I got the following messages in the IDE log:
Executing Script...
fileinput\dzassetdaz.cpp(4866): Could not find modifier definition.
fileinput\dzassetdaz.cpp(1427): Failed to prepare modifier: !Nat2 CreateNipples!
fileinput\dzassetdaz.cpp(1438): Failed to create modifier: !Nat2 CreateNipples!
fileinput\dzassetdaz.cpp(5795): Could not find target property for formula: Genesis3Female:/data/DAZ%203D/Genesis%203/Female/Morphs/Slosh/Genesis2Legacy/Victoria6/CTRLVictoria6Lgcy.dsf#CTRLVictoria6Lgcy?value in file : /data/DAZ%203D/Genesis%203/Female/Morphs/Zev0/Bend%20Control/Smoother%20Victoria%206%20R.dsf
followed by over 130 more error messages quite like the last line above. I do not have Victoria 6 or Gia 6 or Bethany 7 or many others that were mentioned in the error list.
I can post the entire list of error messages if it would be helpful.
So my next question is, what is the difference between Scene.loadScene() and App.OpenFile()?
I tried:
var rc = Scene.loadScene("...\\My Library\\Scenes\\test.duf", Scene.MergeFile);
var message = getErrorMessage(rc);
MessageBox.information(rc + " - " + message, "Information", "&OK");
When I ran the above code, I got an invalid file format message. Should I just iterate a List of duf files with App.Openfile() calls? Should I just ignore Scene.loadScene() ?
In your previous reply above, are you saying that I cannot move a node with the Script API?
This forum software is ... ahem ... slightly flaky. I used some of the provided icons to bullet and/or bold some stuff, and it didn't work. Since there is no edit capability, I cannot fix it.
Indeed, I couldnt even respond to your post! Had to resort to quoting you to get my cursor. Anyway looking with interest what you will be doing, I am interested in the coding side, though I am not very skilled as a coder.
You are welcome. I am making some progress. Tiny steps. I will tentatively assume you are using Windows.
Start with a new empty workspace.
Open up the Scrip IDE in Daz, with Window->Panes->Script IDE. The IDE will upen up with an undocked pane. Optionally you can dock it where you want. Paste the follwing 2 lines of code into the IDE.
var rc = App.getContentMgr().openFile( "C:/Users/casga/Daz3D/My Library/Scenes/test.duf", true );
MessageBox.information(rc ? "Success" : "Failure", "Information", "&OK");
Edit the file name to point to an existing scene or scene subset in your library. Note that you must use EITHER forward slashes OR TWO backslashes instead of the usual single backslash.
Press the Execute button in the IDE.
Click the gear icon at top-right of your post (when the mouse is over it) and select Edit from the menu.
I suspect you'd get those errors loading diectly isntead of via script, they look like a content issue.
The \\ or / is standard to Javascript as far as I know - \ is the escape character, used to insert codes (e.g. \t for tab, or \n for a new line) so a real \ needs to be escaped as a special code. Using / is safer and more universal.
Richard, thankyou.
I simply cut and pasted those lines from my tiny little first snippet in the DAZ IDE.
I was using the internet in the mid 1980s. For four years I delved into the internals of TCP/IP and added stuff to it, and have products and patents to prove it. I have written code in C and C++ and Java and Javascript, on Windows, IBM AIX, Solaris and Linux platforms. I have written code that generates and consumes HTML, I have written parsers, decoders, encoders, designed and built and team-led several complete Web Applications from frontend to backend.
All in my past. I am 70 and no longer as sharp as I used to be.
I was pointing out the slashes/backslashes thing to Paintbox in a friendly way because he said he isn't a coder, and he might otherwise miss the edit he would need to do to the filename string if he pastes it from, for example, Windows Explorer, or worse, he might get a confusing error message.
... and it was a one-sentence piece of constructive advice, much less than this rant by me.
I thank you for the gear icon advice as well. The gear icon is not exactly the intutively obvious place to hide a USER function, and it only shows up if you hover the mouse in the rectangle of the message, and is therefore extremely easy to miss completely.
I also ran usability tests in my day, inviting customers to come by and help us do that.
BUT ...
Unfortunately, when I edit the post, as you describe, the garbled miscoding is somehow swallowed or re-encoded by the application, and so it does not show up in the edit window. When I save, it returns. Seems like a bug to me.
OK, that's quite enough from me.
I was eventually able to clear the scrambled encoding by cutting the text out of the window, pasting it into notepad, and then copying and pasting it back, thuse removing the available HTML format option in the clipboard. Messy but effective.