input dialog box blender - blender

How to make a simple entry dialog box (like in the image) in blender and processing the text entered through python.I am unable to find any good tutorial on this.

For the dialog box the answer from how to show a message from a blender script? might be a starting point.
But I think a better approach is integrating input into the panel like e.g.
To do this you have to add a StringProperty to your add-on and place it inside your panel (see Addon Tutorial for more information). The basic steps are:
def draw(self, context) :
col = self.layout.column(align = True)
col.prop(context.scene, "my_string_prop")
...
def register() :
bpy.types.Scene.my_string_prop = bpy.props.StringProperty \
(
name = "My String",
description = "My description",
default = "default"
)
...
def unregister() :
del bpy.types.Scene.my_string_prop
...
You can access the string by context.scene.my_string_prop
There is another mode to integrate input. When you add for example a text to your scene you can change the parameters after the operator has been called and see the changes immediately:
Changing Location will move the newly created text object at another place. I haven't worked with this but it should be similar to the code above.

Related

Text Field with Standard PsiElement Auto Completion in IntelliJ Plugin

I'm trying to create a simple text field with auto completion for my IntelliJ plugin. I think this should be pretty simple but so far I've run into dead ends...
E.g. this should work as far as I understand:
EditorTextField format = new TextFieldWithCompletion(currentEditor.getProject(),
provider,
"",
true,
true,
true);
The problem is the provider. I'd expect to see a provider that isn't a list provider. I just want to show the completion matching the current line in the editor cursor so I'd like the full completion dialog and not just a short list of options.
I also looked at TextFieldWithAutoCompletion but it seems to be designed for hardcoded string values instead of free form completion.
I just want the standard Java/Kotlin completion. Not a custom list or anything like that. I saw some discussion with replacing the document of the text field but I couldn't get that to work either. I have a PsiExpressionCodeFragment and would expect there to be a completion provider that accepts that but I can't find it.
For reference what I want to do is something very similar to the conditional statement in the breakpoint dialog.
Another approach illustrated here is:
JavaCodeFragmentFactory jcff = JavaCodeFragmentFactory.getInstance(currentEditor.getProject());
PsiFile pf = PsiDocumentManager.getInstance(currentEditor.getProject()).getPsiFile(currentEditor.getDocument());
PsiElement psiElement = pf.findElementAt(currentEditor.getCaretModel().getOffset());
PsiExpressionCodeFragment fragment = jcff.createExpressionCodeFragment("", psiElement,null, false);
EditorTextField f = new EditorTextField(PsiDocumentManager.getInstance(currentEditor.getProject()).getDocument(fragment),
currentEditor.getProject(),
FileTypes.PLAIN_TEXT, false, true);
This loads the UI but doesn't popup code completion no matter what I type.
The trick is to create an editor that contains an instance of the Document. And this document refers to a language and a psi element context:
JPanel panel = new JPanel();
// Just detect an element under caret for context
PsiFile psiFile = PsiDocumentManager.getInstance(editor.getProject()).getPsiFile(editor.getDocument());
PsiElement element = psiFile.findElementAt(editor.getCaretModel().getOffset());
PsiExpressionCodeFragment code = JavaCodeFragmentFactory.getInstance(editor.getProject()).createExpressionCodeFragment("", element, null, true);
Document document = PsiDocumentManager.getInstance(editor.getProject()).getDocument(code);
EditorTextField myInput = new EditorTextField(document, editor.getProject(), JavaFileType.INSTANCE);
myInput.setPreferredWidth(300);
panel.add(myInput);
return panel;
Here the caret used to be located on dsa5, so the dsa5 variable is not yet visible for the completion.

How to clean existing properties and replace with metadata template on Photoshop (scripting)?

While creating a script that would automate all the different tasks I do when I start working on a new picture on Photoshop, I encountered the following problem.
Manually, I would Ctrl + Alt + Shift + I, click on the template I want and choose the option "Clear existing properties and replace with template properties".
I can't find the way to do precisely this. The best thing I managed to find is something like this :
app.activeDocument.info.author = "test";
app.activeDocument.info.caption = "";
app.activeDocument.info.captionWriter = "";
app.activeDocument.info.headline = "";
app.activeDocument.info.instructions = "";
app.activeDocument.info.keywords = "";
app.activeDocument.info.authorPosition = "";
app.activeDocument.info.credit = "";
app.activeDocument.info.source = "";
app.activeDocument.info.category = "";
app.activeDocument.info.supplementalCategories = "";
app.activeDocument.info.title = "";
// etc.
And it actually doesn't really work like the "Clear existing properties and replace with template properties".
I didn't find anything on the Photoshop scripting guide, nor on the internet. Any help would be greatly appreciated !
What I think is the problem is Photoshop separates file-metadata from its activeDocument-metadata. What you see in "File info..." (via Ctrl+Alt+Shift+I) is supposed to represent the file in the filesystem, which metadata is embedded in.
There are several scripting guides to Photoshop scripting. I think the one relevant for you would be "Javascript Tools Guide", specifically the chapter 10 "Scripting Access to XMP Metadata".
Is it important for you to set up the metadata already when creating a new picture? If not, you may want to look at a solution using a customized export script.
It customizes XMP-metadata upon exporting like
Create a basic metadata object:
var meta = new XMPMeta();
Provide a namespaceURI (see XMP specs) known to photoshop along with tag name, and value:
meta.setProperty(XMPConst.NS_XMP, "CreatorTool", app.version);
Save the image temporarily (using other script):
var imgFile = new File(fileName);
saveImage(fileName);
Finish saving by adding the metadata-object:
var metaFile = new XMPFile(imgFile.fsName, XMPConst.FILE_UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
if (metaFile.canPutXMP(meta)) { metaFile.putXMP(meta); }
metaFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
Doing it this way also erases any existing or default metadata.

Shiny Dashboard Inputs inside MenuItems Problems

I am new to shiny dashboards and I am trying my hand at making a simple dashboard. I am trying to put together a dashboard that will basically go through different clustering algorithms and show how they work.
I have a menu item for the overall branching topic, and then input items within those menus that specify the parameters for the clustering algorithms.
My issue is I cannot get any output on my screen. I cannot render plots of even see the title for the boxes that I placed inside the tabItems. This seems to happen when I place a sub-item inside one of my menu items. I am not sure why.
Attached is my ui.R script and server.R script.
ui.R file:
server.R file:
Any help with this matter would be much appreciated.
So, as far as I can see, the problem is due to the fact that you placed the radioButtons within the menuItem. If you want to only show the radioButtons when the tab kclustering is active, you need to wrap radioButtons in a conditionalPanel. It would look something like that:
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "Bla"),
dashboardSidebar(
sidebarMenu(
id = "tabs",
menuItem(
"K-clustering",
tabName = "kclustering",
icon = icon("cogs")),
conditionalPanel(
"input.tabs == 'kclustering'",
radioButtons("technique", "Technique Choice",
c("K-Means" = "kmeans",
"K-Medians" = "kmedians",
"K-Medoids" = "kmedoids"),
select = "kmedians")
),
menuItem("DBSCAN", tabName = "dbscan")
)
),
dashboardBody(
tabItems(
tabItem("kclustering",
fluidRow(
box(plotOutput("step1"))
))
)
))
server <- function(input, output) {
output$step1 <- renderPlot({
hist(rnorm(5000))
})
}
runApp(shinyApp(ui, server))
In this case, it's important to set the id argument of the sidebarMenu object to be able to formulate your condition.
Bottom line is: don't put your radioButtons, sliderInput and textInput inside the menuItem objects but in the sidebarMenu object itself.

How to check multiple PDF files for annotations/comments?

Problem: I routinely receive PDF reports and annotate (highlight etc.) some of them. I had the bad habit of saving the annotated PDFs together with the non-annotated PDFs. I now have hundreds of PDF files in the same folder, some annotated and some not. Is there a way to check every PDF file for annotations and copy only the annotated ones to a new folder?
Thanks a lot!
I'm on Win 7 64bit, I have Adobe Acrobat XI installed and I'm able to do some beginner coding in Python and Javascript
Please ignore the following suggestion, since the answers already solved the problem.
EDIT: Following Mr. Wyss' suggestion, I created the following code for Acrobat's Javascript console to be run only once at the beginning:
counter = 1;
// Open a new report
var rep = new Report();
rep.size = 1.2;
rep.color = color.blue;
rep.writeText("Files WITH Annotations");
Then this code should be applied to all PDFs:
this.syncAnnotScan();
annots = this.getAnnots();
path = this.path;
if (annots) {
rep.color = color.black;
rep.writeText(" ");
rep.writeText(counter.toString()+"- "+path);
rep.writeText(" ");
if (counter% 20 == 0) {
rep.breakPage();
}
counter++;
}
And, at last, one code to be run only once at the end:
//Now open the report
var docRep = rep.open("files_with_annots.pdf");
There are two problems with this solution:
1. The "Action Wizard" seems to always apply the same code afresh to each PDF (that means that the "counter" variable, for instance, is meaningless; it will always be = 1. But more importantly, var "rep" will be unassigned when the middle code is run on different PDFs).
2. How can I make the codes that should be run only once run only at the beginning or at the end, instead of running everytime for every single PDF (like it does by default)?
Thank you very much again for your help!
This would be possible using the Action Wizard to put together an action.
The function to determine whether there are annotations in the document would be done in Acrobat JavaScript. Roughly, the core function would look like this:
this.syncAnnotScan() ; // updates all annots
var myAnnots = this.getAnnots() ;
if (myAnnots != null) {
// do something if there are annots
} else {
// do something if there are no annots
}
And that should get you there.
I am not completely positive, but I think there is also a Preflight check which tells you whether there are annotations in the document. If so, you would create a Preflight droplet, which would sort out the annotated and not annotated documents.
Mr. Wyss is right, here's a step-by-step guide:
In Acrobat XI Pro, go to the 'Tools' panel on the right side
Click on the 'Action Wizard' tab (you must first make it visible, though)
Click on 'Create New Action...', choose 'More tools' > 'Execute Javascript' and add it to right-hand pane > click on 'Execute Javascript' > 'Specify Settings' (uncheck 'prompt user' if you want) > paste this code:
.
this.syncAnnotScan();
var annots = this.getAnnots();
var fname = this.documentFileName;
fname = fname.replace(",", ";");
var errormsg = "";
if (annots) {
try {
this.saveAs({
cPath: "/c/folder/"+fname,
bPromptToOverwrite: false //make this 'true' if you want to be prompted on overwrites
});
} catch(e) {
for (var i in e)
{errormsg+= (i + ": " + e[i]+ " / ");}
app.alert({
cMsg: "Error! Unable to save the file under this name ('"+fname+"'- possibly an unicode string?) See this: "+errormsg,
cTitle: "Damn you Acrobat"
});
}
;}
annots = 0;
Save and run it! All your annotated PDFs will be saved to 'c:\folder' (but only if this folder already exists!)
Be sure to enable first Javascript in 'Edit' > 'Preferences...' > 'Javascript' > 'Enable Acrobat Javascript'.
VERY IMPORTANT: Acrobat's JS has a bug that doesn't allow Docs to be saved with commas (",") in their names (e.g., "Meeting with suppliers, May 11th.pdf" - this will get an error). Therefore, I substitute in the code above all "," for ";".

Require a textbox to have value in FIllable PDF

I have a fillable PDF file. I would like to require that a TextBox has a value when the user saves the PDF document i.e. the value is not blank.
Here is what I tried:
(1) Setting the "Required" field on the "TextBox".
PROBLEM: That didn't do much except color the textbox red.
(2) I tried to use the following code in the "onBlur" event:
f = getField(event.target.name)
if (f.value.length == 0)
{
f.setFocus()
//Optional Message - Comment out the next line to remove
app.alert("This field is required. Please enter a value.")
}
PROBLEM: If the user never clicks this box there is no problem
(3) I tried to use the "Validation" tab and run a custom JavaScript.
PROBLEM: If you don't click on the box there is no validation so it is perfectly happy to leave the textbox blank if the user forgets to fill it in
OK, I am out of ideas... Anyone?
Since you are using Acrobat JavaScript I assume you use a viewer that supports and executes Acrobat JavaScript. In this situation you can set the document's WillSave action to a custom JavaScript action and perform validation here. I'm not sure if you can cancel the save operation but at least you can display an alert if the validation fails.
UPDATE: This script will loop through all the fields and display and alert if the field value is empty.
for ( var i = 0; i < this.numFields; i++) {
var fieldName = this.getNthFieldName(i);
var field = this.getField(fieldName);
if (field.value.length == 0)
{
field.setFocus()
app.alert("Field " + fieldName + " is required. Please enter a value.")
}
}
Put the script in document's Will Save action and it will run every time the user saves the form. In Acrobat you set this in Tools > JavaScript > Set Document Actions and select Document Will Save.