Skip to main content

Posts

Contents of My Hyperspace

1. Blogger Settings: 2. InDesign: 3. LaTeX: 4. Programming: 5. Taigu:
Recent posts

Using C# to run WSL process (python script) on Windows

Every times when Nvidia updates its drivers, the task with Tensorflow is more or least impacted. Quote from TF's website: TensorFlow 2.10 was the last TensorFlow release that supported GPU on native-Windows. Starting with TensorFlow 2.11, you will need to install TensorFlow in WSL2, or install tensorflow or tensorflow-cpu and, optionally, try the TensorFlow-DirectML-Plugin. PyTorch works fine with CUDA. With some modifications on environment variables to use the toolkit 12.1, it is easy to setup for running PyTorch projects on Windows with GPU. To attempt to run TF project on WSL2 with GPU, there comes an idea to create a C# project to run a WSL-python-script process on Windows. Create a C# WinForm project with Visual Studio. Set the project with x64 platform (replace with "Any CPU")! (Otherwise, the running process will be in 32-bit, on which, WSL is not installed.) The code looks like this ( Please refer to the original code ): using (var proc...

A Simple Sample to Make Color List in InDesign

Here is a simple sample to make color list in InDesign. It is very simple, because, there are no left-right page handling, no color values for cyan, magenta, yellow and black, no page numbers, no comments, and no drawing the border of the color-box. And I don't have much time to reply any question. Please try it on your own. Here is the code: main(); function main() { if (app.documents.length == 0) { var myDocument = app.documents.add(); basicSetup(myDocument); myDocument.textFrames.item(0).remove(); makeSwatch(myDocument); } return 0; } function basicSetup(myDocument) { myDocSetup(myDocument); myMasterSpreads(myDocument); } function myDocSetup(myDocument) { with (myDocument.documentPreferences) { pageHeight = "29.8cm"; pageWidth = "21.6cm"; pageOrientation = PageOrientation.portrait; facingPages == true; documentBleedUniformSize = true; documentBleedTopOffset = "3p"; documentSlugUniformSize = true; slugTopOffset = ...

First Trying of Python Scripting on FontLab 7 (6)

I just updated my FontLab from 5 to 7. In the last weekend (Aug. 1. 2020), I'd tried to move my old python codes for FontLab 5 to FontLab 7 (6). Although, there is the online documentation, as usual, I needed to guess and try to work out the code for correct result. Here I listed my first attempt to add empty glyph to a font. First Two Lines: import fontlab as fl7 import fontgate as fgt We need two modules, "fontlab" to work with the application FontLab, and "fontgate" to handle the opened font(s) and the glyphs of the font(s) in FontLab. To Count the Opened Font(s) openedFontCounts = fl7.CountFonts() # it's type of "integer". To Get the Font From the Opened Fonts allFonts = fl7.AllFonts() # type of "fgPackages" font1 = allFonts[0] # if there is at least a font opened. it's of the type "fgFont". font2 = allFonts[1] # if there are at least two fonts opened. it's of the type "fgFont". ... We may also get t...

InDesign Scripting with ScriptUI: Add a TestIt Button to Play Around

Based on my previous article " InDesign Scripting with ScriptUI: How to Move Cursor and Select Text ", let's add a button to play around. The original code looks like this: // --- Last Part of UI (No Panel) --------------------------------------------- function AddCloseButton(w) { w.grpButtons = w.add('group'); w.btnClose = w.grpButtons.add('button {text: "Close"}'); w.btnClose.onClick = function () { w.close(); } } // ------------------------------------------------------- Let me add a button to select a piece of text. Below in in the listener function "TestIt", I don't add the boundary checking . You may try and modify the variables "start" and "end" to go over the boundary. And see what happens. // --- Last Part of UI (No Panel) --------------------------------------------- function AddCloseButton(w) { w.grpButtons = w.add('group'); w.grpButtons.orientation = "column"; ...

InDesign Scripting with ScriptUI: How to Move Cursor and Select Text

Based on the code pattern in my  previous article , here I’d like to show the methods to move the cursor and to select text with button click on ScriptUI. Using buttons to move cursor and to select text is useful when working with a script, which has a UI. You don’t need to move your mouse running all over the whole screen very often for doing your tasks. Most of the time, you can concentrate your mouse movement just around the UI of your script. The code is divided into 4 parts: Part 1 , from line 10 to line 28: This is the coding pattern for the modeless dialog. Part 2 , from line 37 to line 57: The main UI is created in this part. Part 3 , three groups of buttons are created here, together with the functions, which are attached to the button click event. Group 1: from line 60 to line 67, the code setups the buttons for moving cursor. from line 69 to line 118, the event listener "MoveCursor" is defined. Group 2: from line 121 to line 128, the code s...

A Programming Pattern to Create a Modeless Dialog with Adobe ScriptUI

I'd like to create a dialog box to input some special characters onto InDesign without running the dialog every time, after I clicked on some button to input characters. A modeless dialog is the choice. But I got many crashes. Finally, with the sample from Adobe, I got a stable programming pattern, which works with Adobe CC. Here is the code: #targetengine session; // the above line is necessary to create a modeless dialog with // var win = new Window("palette", ...); // // refer to the sample program from Adobe: "SnpCreateDialog.jsx". // Which is usually located at the folder (Windows): // C:\Program Files (x86)\Adobe\Adobe ExtendScript Toolkit CC\SDK\Samples\javascript function AModelessDialog() { this.windowRef = null; } function setupWindow() { var ww = new Window("palette", "A Modeless Dialog"); addComponents(ww); return ww; } AModelessDialog.prototype.run = function() { var win = setupWindow(); this.windowRef = win; w...