How to convert the spectrum type ("Spectrum" -> "Convert Data to") - dm-script

Is there a manner in which one can convert the spectrum type, for instance to EELS, by DM scripting? This screenshot represents what I'm referring to. I'd like to import a dataset using the GMS 3.4 Python interface, and then turn that into a EELS dataset for further processing (ideally without having to manually interface with the screenshotted menu bar).

Yes there is.
The "type" is simply a meta-data tag
which you can easily set with the TagGroup commands.
There is, however, one complication:
Data "registers" itself with DM when it first appears. Changing the meta-tags manually doesn't change this registration. (The menu command, however, does.)
Thus, you will only see effect of the type change when
either:
You save, close and reopen the data
You clone the data, throw away the original, and display the clone
The second option might cause issues with data-linkage though, as the unique image ID of the data is newly created.
Example using the first method (requires save & load):
image img:=GetFrontImage()
TagGroup tg = img.ImageGetTagGroup()
tg.TagGroupSetTagAsString("Meta Data:Signal","EELS")
imageDocument doc = img.ImageGetOrCreateImageDocument()
doc.ImageDocumentSave(0)
string path = doc.ImageDocumentGetCurrentFile()
doc.ImageDocumentClose(0)
doc = NewImageDocumentFromFile(path)
doc.ImageDocumentShow()

An alternative option is to rely on the menu command. If it is present, then you can simply use the ChoseMenuItem() command to invoke it.
However, the command will only be available with the UI when the data you want to change is front-most (i.e. not a script window!) You will need to ensure by script, that this is the case. A simple ShowWindow() will do.
image img:=GetFrontImage()
img.ShowImage()
if ( !ChooseMenuItem("Spectrum","Convert Data To","None") )
Throw( "Conversion to none failed.")
if ( !ChooseMenuItem("Spectrum","Convert Data To","EDS") )
Throw( "Conversion to none failed.")
Disadvantage of this solution: You will get the user-prompts.

Related

ReadyAPI - Automation script to get the value from data source step

i am new to ReadyAPI and automation. But now i facing some issue where i wanted to fill in the consent page will the value that will get from the Data source.
The Role value is the value that i need to get and fill into the consent page
Here is my automation code to get the value:
I have to get the value from Data source, then fill into text box, then click button
This is the code im using:
document.getElementById('freeTextHabilitations').value = 'ObjectiveCombinaisons Data Source#Role';
document.getElementById('allowBtn').click();
I having problem where get nothing after the data source ran .
Anyone have any idea on how to inject the value from data source to automation script (java?)
Thank you.
Stanley,
Unclear as to how you are using DOM methods(with ReadyAPI), but to answer your question on accessing Data Source values
For that, you will need property expansion. So, your groovy script should be something like
xxxx.value = context.expand( '${ObjectiveCombinations Data Source#Role}' )
Property Expansion
This can be generated for you by using the Get Data dialog
Get Data Dialog

How can I create the resource string without a big string?

In After Effects scripts, if you want your script to be able to be docked in the program's workspace, the only way to do it as far as I know is to use a resource string like this:
var res = "Group{orientation:'column', alignment:['fill', 'fill'], alignChildren:['fill', 'fill'],\
group1: Group{orientation:'column', alignment:['fill', ''], alignChildren:['fill', ''],\
button1: Button{text: 'Button'},\
},\
}";
myPanel.grp = myPanel.add(res);
The above code creates a script UI with one button ("button1") inside a group ("group1").
I would like to know other ways to create the same resource string. Is it possible to make it using a JSON object and then stringifying it??
I know it can be done somehow, because I have inspected the Duik Bassel script that is dockable and, for example, adds elements like this:
var button1 = myPal.add( 'button' );
but I cannot understand how to do it myself.
TL;DR: I want to make a dockable scriptUI without writing a giant string all at once, but bit by bit, like a floating script.
UI container elements have an add() method which allows you to add other UI elements to them, and you can treat them as normal objects.
var grp = myPanel.add("group");
grp.orientation = "column";
grp.alignment = ['fill', 'fill'];
grp.alignChildren = ['fill', 'fill'];
var group1 = grp.add("group");
…
var button1 = group1.add("button");
button1.text = 'Button'
More details and examples here: https://extendscript.docsforadobe.dev/user-interface-tools/types-of-controls.html#containers
Also worth checking out https://scriptui.joonas.me/ which is a visual scriptUI interface builder. You have to do some work on the code it produces to get panels for AE, but it's not hard.
extendscript still uses a 20th century version of javaScript, which doesn't have JSON built-in, but I have successfully used a JSON polyfill with it.
I used json2.js to get structured data in and out of Illustrator, and it worked beautifully, but I can see there's now a json3.js which might be better for whatever reason. This stackoverflow question addresses the differences.
To load another .js file (such as a polyfill) into your script, you need to do something like
var scriptsFolder = (new File($.fileName)).parent; // hacky but effective
$.evalFile(scriptsFolder + "/lib/json2.js"); // load JSON polyfill
These file locations may differ in other Adobe apps. Not sure what it would be in AfterEffects. I seem to remember that InDesign has a different location for scripts. You can also hardcode the path, of course.
Good luck!

TypeError: setCurrentWindow(): 1st arg can't be coerced to ij.gui.ImageWindow

Hi I am a very novice when it comes to scripting. I am trying to write a Jython script that will take an image that is not at the front, in imageJ, and bring it to the front. I have tried using the WindowManager but routinely run into a similar error.
TypeError: setCurrentWindow(): 1st arg can't be coerced to
ij.gui.ImageWindow
or some other form of this error. It seems as though activating an image that is not at the front shouldn't be too difficult.
Here is the code I'm using:
from ij import IJ
from ij import WindowManager as WM
titles = WM.getIDList()
WM.setCurrentWindow(titles[:1])
The WindowManager.setCurrentWindow method takes an ImageWindow object, not an int image ID. But you can look up the ImageWindow for a given ID as follows:
WM.getImage(imageID).getWindow()
Here is a working version of your code:
from ij import IJ
from ij import WindowManager as WM
print("[BEFORE] Active image is: " + IJ.getImage().toString())
ids = WM.getIDList()
win = WM.getImage(ids[-1]).getWindow()
WM.setCurrentWindow(win)
win.toFront()
print("[AFTER] Active image is: " + IJ.getImage().toString())
Notes
I renamed your titles variable to ids because the method WindowManager.getIDList() returns a list of int image IDs, not a list of String image titles.
The WM.getImage(int imageID) method needs an int, not a list. So I used ids[-1], which is the last element of the ids list, not ids[:1], which is a subarray. Of course, you could pass whichever image ID you wish.
I added the call win.toFront(), which actually brings the window to the front. Calling WM.setCurrentWindow(win) is important in that it tells ImageJ that that image is now the active image... but it will not actually raise the window, which is what it seems like you want here.

Display PDF from application server in Webdyn Pro ABAP

I'm working on a report which contains actions allowing the user to reach a a new page. In this new page pdf stored on the application server has to be displayed.
On the PDF view I created an interactive form linked with my context (PDF_DATA-PDF : xstring)
gv_filepath = '/tmp/test.pdf'.
" Open the file in binary mode
OPEN DATASET gv_filepath FOR INPUT IN BINARY MODE.
IF sy-subrc = 0.
READ DATASET gv_filepath INTO gv_filedata.
IF sy-subrc = 0.
CLOSE DATASET gv_filepath. "Close the file
" Convert the file from hex-string to Binary format
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = gv_filedata
IMPORTING
output_length = gv_filesize
TABLES
binary_tab = gt_bin_data.
Here, I don't know what to do ....
lo_node = wd_context->get_child_node( 'PDF_DATA' ).
lo_node->set_attribute( name = 'PDF' value = ?).
wd_comp_controller->gestion_affichage( ).
ENDIF.
ENDIF.
Please suggest how do I handle this?
There are a couple of ways to implement this:
Use a FileDownload element and perform the operations you described above in the Supply method of the context element. That's probably the easiest way to implement this, but it might have the drawback that the file is not displayed, but offered for download instead. It's worth giving it a try though since it's very easy to implement.
Create a new ICF service (not a WebDynpro application!) that will return the PDF file with an appropriate MIME type when requested. Then, open a new browser window with the URL of that service.
As before, but use an IFrame element to display the PDF file in-place. Be aware that the usage of this element is discouraged (although probably only to push customers towards EP...?).
To display a PDF file in Web Dynpro ABAP page,
Add the InteractiveForm control to the View
Bind the pdfSource property to the Context node containing the PDF content
Load the PDF file to the context node
Here is an example with screen shots
Well i solved my problem with my colleague, thank you
I just have to add the following code after the OPEN DATASET
CLEAR l_len.
CLEAR l_data_tab.
DO.
READ DATASET gv_filepath INTO l_data actual LENGTH l_len.
IF sy-subrc <> 0.
IF l_len > 0.
file_size = file_size + l_len.
APPEND l_data to l_data_tab.
ENDIF.
EXIT.
ENDIF.
file_size = file_size + l_len.
APPEND l_data to l_data_tab.
ENDDO.

How to make jedit file-dropdown to display absolute path (not filename followed by directory)?

All is in the title.
If a have opened the three files:
/some/relatively/long/path/dir1/file_a
/some/relatively/long/path/dir1/file_b
/some/relatively/long/path/dir2/file_a
The file dropdown contains:
file_a (/some/relatively/long/path/dir1)
file_a (/some/relatively/long/path/dir2)
file_b (/some/relatively/long/path/dir1)
And that bother me because I have to look on the right to differentiate the two file_a, and on the left for the others. This happens a lot to me mostly because I code in python, and thus I often have several __init__.py files opened.
How do I get jedit to display
/some/relatively/long/path/dir1/file_a
/some/relatively/long/path/dir1/file_b
/some/relatively/long/path/dir2/file_a
config:
jedit 5.1.0
java 1.6.0_26
mac osx 10.6
Unfortunately this is not easily possible currently, I just had a look at the source and this is not configurable.
You can:
Submit a Feature Request to make this configurable (good idea in any case)
Create or let create a startup macro that
registers an EBComponent with the EditBus that listens for new EditPanes getting created
retrieve the BufferSwitcher from the EditPane
retrieve the ListCellRenderer from the BufferSwitcher
set a new ListCellRenderer to the BufferSwitcher that first calls the retrieved ListCellRenderer and then additionally sets the text to value.getPath()
Try the Buffer List plugin as to whether it maybe suits your needs
Now follows code that implements the work-part of option two, runnable as BeanShell code which does this manipulation for the current edit pane. The third line is not necessary when done in an EBComponent, this is just that the on-the-fly manipulation is shown immediately.
r = editPane.getBufferSwitcher().getRenderer();
editPane.getBufferSwitcher().setRenderer(
new ListCellRenderer() {
public Component getListCellRendererComponent(list, value, index, isSelected, cellHasFocus) {
rc = r.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
rc.setText(value.getPath());
return rc;
}
});
editPane.repaint();