Browsing to file location using script

Richard HaseltineRichard Haseltine Posts: 96,896

Is it possible to perform the equivalent of the Content Library's Browse to File Location, opening an OS file window, via script? I have found a browseToAsset(DzAssetPtr) function in the Content Library pane object, but I can't see how to get an asset pointer from a file (ideally direct from a string with the relative path name, or the absolute path name obtained from DzContentMgr, though using a DzFile or FileInfo would be fine). As I am intending to use this, the Content Library would definitely not be showing the asset I wanted to browse to though I think it might be possible to switch to showing the asset in question - but the function also seems to need input other than a straight string or DzFile - and then go back to the original location.

Comments

  • rbtwhizrbtwhiz Posts: 2,181
    edited November 2015

    The context is different (i.e. single file vs multiple files) and this simplifies dealing with database records, but here is a DAZ Script that roughly does what the "Browse to file location..." action in the Content Library context menu does:

    var oPaneMgr = MainWindow.getPaneMgr();var oPane = oPaneMgr.findPane("DzContentLibraryPane");if( oPane ){ var aAssets = oPane.getSelectedAssets(); var sAbsFilePath; var oAsset, oFileInfo; for( var i = 0; i < aAssets.length; i += 1 ){  oAsset = aAssets[ i ];  sAbsFilePath = oAsset.getAsLocalFile();  if( App.version64 >= 1125921381810178 ){//4.5.2.2   App.showInNativeBrowser( sAbsFilePath );  } else {   oFileInfo = new DzFileInfo( sAbsFilePath );   App.showURL( String("file:///%1").arg( oFileInfo.path() ) );  } }}


    -Rob

     

    Post edited by Richard Haseltine on
  • Richard HaseltineRichard Haseltine Posts: 96,896
    edited December 1969

    Ah, thank you - I thought there should be something in App but I wasn't finding it. That's much simpler than going through the content pane (I will be starting with the relative path available, so I just need to turn it absolute and use the show* function). Thanks Rob.

  • When I use this code I get this error :

     

    Script Error: Line 8

    TypeError: Result of expression 'oAsset.getAsLocalFile' [undefined] is not a function.

    Stack Trace: ()@:8

  • That's useful - the conversion from the old forum has stripped out the array index [ i ] as well as the carriage returns. The script should be:

    var oPaneMgr = MainWindow.getPaneMgr();var oPane = oPaneMgr.findPane("DzContentLibraryPane");if( oPane ){	var aAssets = oPane.getSelectedAssets();	var sAbsFilePath;	var oAsset, oFileInfo; 	for( var i = 0; i < aAssets.length; i += 1 ){		oAsset = aAssets[ i ];		sAbsFilePath = oAsset.getAsLocalFile();		if( App.version64 >= 1125921381810178 ){//4.5.2.2			App.showInNativeBrowser( sAbsFilePath );		} 		else {			oFileInfo = new DzFileInfo( sAbsFilePath );			App.showURL( String("file:///%1").arg( oFileInfo.path() ) );		}	}}

     

  • Ahh thanks !

Sign In or Register to comment.