Load message when loading PNG

mikey186mikey186 Posts: 84

I'm trying to let the user know when a file with a PNG extension is used, it gives a notice about transparent PNGs, how do I give a message box when it loads a PNG?

var sPath = FileDialog.doFileDialog(true, "Select an Image File", oImageMgr.getImageOpenPath(), "Image Files(*.png *.jpg *.tif)");if(sPath){	oImage = new Image();	if(oImageMgr.loadImage(sPath, oImage)){		var oTexture = oImageMgr.getImage(sPath);		var oFileInfo = new DzFileInfo(sPath);		oImageMgr.setImageOpenPath(sPath);		var sNodeName = "%1".arg(oFileInfo.baseName());			if( DzFileInfo( String( "PNG" ))	{ 		MessageBox.information( "Your image is now PNG.", "Plane created!", "OK", "" );	}		

 

Post edited by mikey186 on

Comments

  • Richard HaseltineRichard Haseltine Posts: 96,718
    edited March 2020

    Don't you want

    if( oFileInfo.extension() == "PNG" ))

    to check the extension? Though I am not entirely following what you are doing anyway.

    Post edited by Richard Haseltine on
  • OK, first I goofed above - had DzFileInfo instead of the actual variable oFileInfo so I've fixed that, though Rob has in any event supplied a more thorough answer:

    (function(){		var oImageMgr = App.getImageMgr();	var sPath = FileDialog.doFileDialog( true, "Select an Image File", oImageMgr.getImageOpenPath(), "Image Files(*.png *.jpg *.tif)" );	if( sPath ){		var oImage = new Image();			if( oImageMgr.loadImage( sPath, oImage ) ){			var oTexture = oImageMgr.getImage( sPath );			var oFileInfo = new DzFileInfo( sPath );			oImageMgr.setImageOpenPath( sPath );			var sNodeName = oFileInfo.baseName();						if( oFileInfo.extension().toLowerCase() == "png" ){				MessageBox.information( "Your image is now PNG.", "Plane created!", "OK", "" );			}						oFileInfo.deleteLater();						//... do something with oTexture and sNodeName?		}				//... do something with oImage?	}	})();

    Points to note, as I understand them:

    • oImageMgr is proeprly initialised (it may, of course, have been initialised elsewhere in your code)
    • oImage is declared as a variable (again, you may have already done this outside the quoted code but if not using it without the var makes it a global, with possibly undesirable effects)
    • variable declarations are pulled out of the code
    • brackets and indenting fixed - again, some of the closing brackets may occur outside the excerpt you posted but having the complete structure (with placeholder comments for the unneeded sections) makes checking more practical)
    • the string structure was unneeded since you were stringifying an unmodified string
    • allowance made for casing, which we had both missed out.
  • mikey186mikey186 Posts: 84

    Thank you! Now in the message box, is there a way when someone clicks a button in the message box, it takes you to a webpage OR a asset to load within DAZ?

  • I'm nots sure - DS can certainly do that, and I wold think the needed functions are in Content Manager and Asset Manager (for content that is in the databasse).

Sign In or Register to comment.