Is It Possible To Access The Internal Name From A PP2 In DS4 Via DAZ Script? [How About The OBJ Name

2»

Comments

  • jag11jag11 Posts: 885

    ok. Apology accepted.

  • 3dcheapskate3dcheapskate Posts: 2,719
    edited November 2015

    Thanks - I really must remember to switch my brain on more often! blush

    Also I need to remind myself that with modern code you start at the bottom and work up (I still tend to write code in a very dated monolithic inline way, only very occasionally pulling chunks out into seperate functions). I completely missed this bit at the bottom of your code:

    var nodeList = Scene.getNodeList();
    nodeList.forEach(function(n){
    	if(n.className() == "DzFigure") {
    		logger.info(reflector.setObject(n).toString());
    		logger.info("    name: %1", n.name);
    		logger.info("   class: %1", n.className());
    		logger.info("assetUri: %1", n.assetUri);
    	}

    Original comment edited a second time - when I say something foolish I'm happy to admit it!

     

    Post edited by 3dcheapskate on
  • What is it suppose to do ?

  • 3dcheapskate3dcheapskate Posts: 2,719
    edited November 2015

    jag11 indicated that his code presents a dialog and lets you get the full path of a figure along with properties and methods of objects.

    I'd guess that it's logging the name, className and assetUri for every figure in the scene and displaying them all in a dialog.

    But it needs somebody who understands OO (i.e. not me!  ;o) ) to explain the details. Anybody ?

    Post edited by 3dcheapskate on
  • jag11jag11 Posts: 885

    Here I go, I only hope not to confuse you more, but code looks weird cause it is compiled code, intended to be consumed as regular DAZ objects. Project has 3 main classes:

    // Class to send debug messages to console / log file.declare class Logger {    static INFO: string;    static WARN: string;    static ERROR: string;    lines: string[];    // clear messages list    clear(): void;    // outputs an informational debug message    info(fmt: string, ...args: any[]): void;    // outputs a warning debug message    warn(fmt: string, ...args: any[]): void;    // outputs an error debug message    error(fmt: string, ...args: any[]): void;    write(type: string, fmt: string, args: any[]): void;    // gets the string representation of message list    toString(): string;}// Class to expose implementation details out of DAZ Objectsdeclare class Reflector {    name: QString;    properties: PropertyInfo[];    methods: MethodInfo[];    ancestorName: QString;    constructor();    initialize(): void;    // Set instance object to reflect    setObject(o: any): Reflector;    addProperty(o: any, name: string): void;    addMethod(o: any, name: string): void;    // Gives string representation of current object    toString(): string;}// creates reflector application declare class DazReflectorApplication extends ApplicationBase {    pixmapLabel: DzLabel;    constructor(appName?: string);    initialize(): void;}// global variablesdeclare var logger: Logger;declare var reflector: Reflector;var app = new DazReflectorApplication("Any app name");var nodeCount = Scene.getNumNodes();var nodeList = Scene.getNodeList();nodeList.forEach(function(n){	if(n.className() == "DzFigure") {		logger.info(reflector.setObject(n).toString());		logger.info("    name: %1", n.name);		logger.info("   class: %1", n.className());		logger.info("assetUri: %1", n.assetUri);	}});app.run();

    Last part of the code is very simple as it creates an application instance, which is a dialog with two Tab objects, one of them serves as a console message. then, we get the node list from the Scene and test each node to be a valid DzFigure before getting the file location(assetUri).

    The idea to share all this code is to help others to use it as a base to dig the inner details of scripting objects.

  • djigneodjigneo Posts: 283
    edited December 2015

    @3dcheapskate, the intent of the code is to have an easy way to know what methods and properties are on any given object in DAZ Script. Think of it as an API generator.  Example usage code:

    // in place of the "main" code at the end of the file, starting with// var app = .../**Prints out information for the specified oObject*/function printObjectDetails(oObject) {	var oReflector = new Reflector();	oReflector.setObject(oObject);	print(oReflector.toString());}// new "main" codevar oDialog = new DzDialog(); // example object, this could be anything you're curious aboutprintObjectDetails(oDialog);

    Creates output that looks like the following:

    declare class DzDialog extends QObject { caption: string; // enabled: boolean; // true font: QObject; // [object Object] globalX: number; // 0 globalY: number; // 0 height: number; // 30 maxHeight: number; // 16777215 maxWidth: number; // 16777215 ...}

    So then you can think "Oh, DzDialog has a property called caption! Now I can code with confidence!"

    Post edited by djigneo on
  • Ah! Now that is useful, what with all the holes in the documentation...  :)

    Thanks jag11 and djigneo

Sign In or Register to comment.