ImageJ "There are no images open" - macros

I have the following code, which works fine except that when I try to close the ROI Manager and montage at the end I get the error:
There are no images open
I started without specifying the windows, then tried specifying the windows, have tried run("Close"); and just close();.
Both the ROI Manager and the montage do close with the current macro, but the message pops up after. What am I doing wrong here?
macro "draw rois [v]"{
var list="/Volumes/bkonk7/old_OCT/ROI_list.txt";
pathroot="/Volumes/bkonk7/old_OCT/";
var pathlist=File.openAsString(list);
var pathsplit=split(pathlist, "\n");
for(i=0;i<pathsplit.length;i++){
var roilist=split(pathsplit[i], ".");
run("Image Sequence...", "open="+pathroot+roilist[i]+" sort");
run("Rotate 90 Degrees Right");
run("RGB Color");
roiManager("Open", pathroot+pathsplit[i]);
roicount=roiManager("count");
for(j=0;j<roicount;j++){
roiManager("Select", j);
run("Draw", "slice");
}
saveAs("Tiff", pathroot+roilist[i]+"_edit.tif");
run("Image Sequence...", "open="+pathroot+roilist[i]+" sort");
run("Rotate 90 Degrees Right");
run("RGB Color");
splitname=split(roilist[i],"/");
run("Combine...", "stack1="+splitname[2]+"_edit.tif stack2="+splitname[2]);
saveAs("Tiff", pathroot+roilist[i]+"_edit.tif");
selectWindow("ROI Manager");
run("Close");
selectWindow(splitname[2]+"_edit.tif");
close();
}
}

You can use:
list = getList("image.titles");
if (list.length != 0) {
close();
}
or the close(pattern) macro function.

Related

How to allow raycasting when the player is at a certain distance from object?

I've implemented opening drawers/doors features on my game but the issue I'm facing is that when The player opens a drawer, it gets pushed back so the drawer has some room to be opened. sometimes it jitters when pushed back.
Physics.Raycast(mainCamera.transform.position, mainCamera.transform.forward, out hit, 3f);
if (hit.transform)
{
interactiveObjects = hit.transform.GetComponent<InteractiveObjects>();
}
else
{
lookObject = null;
interactiveObjects = null;
}
if (Open)
{
if (interactiveObjects)
{
interactiveObjects.OnOpen();
}
}
I'm using raycast to open the drawer. Is there a way to only allow the raycasting, when the player is not too close to the drawer? so it doesn't get pushed back by the drawer.
You can check the distance after doing the raycast. If the distance is within the tolerable range, execute the rest of your code.
if (Physics.Raycast(mainCamera.transform.position, mainCamera.transform.forward, out hit, 3f))
{
if (hit.distance >= minDistance)
{
// Code to execute when range is acceptable
}
else
{
Debug.Log("Player is too close to object!");
}
}
The distance used above does not take into account the height difference between the hit point and the camera. You can get a much more consistent distance by setting the y component of both vectors equal before getting the distance.
var cameraPos = mainCamera.transform.position;
cameraPos.y = hit.point.y;
var distance = Vector3.Distance(hit.point, cameraPos);

How do i fix the placement tool in my level editor?

So i'm currently making a game, and i've recently added a level editor, but the placing tool does not work how i wanted it to.
https://youtu.be/MuUvnVTL6eg
If you've watched this video, you've probably realized that the block placing works pretty much how placing rectangles in ms pain with alt does, and i want it to work like placing rectangles in ms pain without alt xd.
I'm using this code to place the block:
if (Input.GetKeyDown(KeyCode.Mouse0)){
startDrawPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
tmpObj = spawnObject(blocks[selected].gameObject, startDrawPos);
drawing = true;
}
if (Input.GetKey(KeyCode.Mouse0)){
Vector2 mPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector2 tmpScale = new Vector2(startDrawPos.x - mPos.x, startDrawPos.y - mPos.y);
tmpObj.transform.localScale = tmpScale;
}
if (Input.GetKeyUp(KeyCode.Mouse0))
{
drawing = false;
var scale = tmpObj.transform.localScale;
//Code below destroys the object if it's too small to avoid accidental placements
if (scale.x <= 0.1 && scale.x > -0.1 || scale.y <= 0.1 && scale.y > -0.1)
{
Destroy(tmpObj);
}
}
(All of this code is in the Update() function)
(spawnObject function just instantiates the object prefab)
There is a bit more code but it has nothing to do with the position of the block, it just detect which block is selected and decides if it can be resized or not.
I solved this problem. But because your complete script is not in question, I rebuilt the code with IEnumerator, Here, by pressing the left mouse button, IEnumerator is activated and all commands are grouped in one method to make the code more efficient.
private void Update()
{
if (Input.GetKeyDown(KeyCode.Mouse0)) StartCoroutine(DrawRect());
}
How does the Desktop Rect formula work?
By running IEnumerator, the code first records the starting point of the mouse. It also makes a simple cube because I do not have access to your objects. Now until the mouse is pressed. Resize Rect to the difference between current and recorded points. The only thing is that to avoid ALT control, you have to place it between the current and initial points. The reason for adding the camera forward is to be seen in the camera.
cubeObject.transform.position = (startDrawPos + currentDrawPos) / 2;
The final structure of the DrawRect is as follows:
public IEnumerator DrawRect()
{
drawing = true;
var scale = Vector2.zero;
var startDrawPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
var cubeObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
while (Input.GetKey(KeyCode.Mouse0))
{
var currentDrawPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
cubeObject.transform.position = (startDrawPos + currentDrawPos) / 2 + Camera.main.transform.forward * 10;
scale = new Vector2(startDrawPos.x - currentDrawPos.x, startDrawPos.y - currentDrawPos.y);
cubeObject.transform.localScale = scale;
yield return new WaitForEndOfFrame();
}
if (scale.x <= 0.1 && scale.x > -0.1 || scale.y <= 0.1 && scale.y > -0.1) Destroy(cubeObject);
drawing = false;
}

Unity3d. How to find detect incorrect convex mesh

I wrote mesh generator for MeshCollider. But sometimes, when I set convex property to ture, some errors happened to appear the log.
For example, now I have a Mesh with 44 vertices and this errors:
CreateTrianglesFromPolygons: convex hull has a polygon with less than 3 vertices!
or
convex hull init failed! Try to use the PxConvexFlag::eINFLATE_CONVEX flag.
or something else...
All I want, is to detect and handle this error. But try catch do not work:
try
{
collider.convex = true;
UnityEngine.Debug.Log("Success! TrCount: " + collider.sharedMesh.triangles.Length.ToString()); // "Success! TrCount: 84"
}
catch
{
UnityEngine.Debug.Log("Error occur"); // never appear
}
Maybe there are some rules to detect it before setting convex to true.
Thank you for any help ).
You forgot catch(ExceptionType)
try
{
collider.convex = true;
UnityEngine.Debug.Log("Success!");
}
catch(Exception e)
{
UnityEngine.Debug.Log("Error occur: " + e.Message);
}
Include using System; at the top.
EDIT:
The error message is NOT an exception so the method below should solve your problem. Remember that convex requires the triangle to be < 255 to work. The code below makes sure that your trigs is between 3 and 254.
if (generatedMesh.triangles.Length >= 3 && generatedMesh.triangles.Length < 255)
{
collider.convex = true;
UnityEngine.Debug.Log("Success!");
}else
{
UnityEngine.Debug.Log("Error occur: " + e.Message);
}

How add code lines in Umazing unity plugin?

enter image description here
Since that the Unity Plugin mentioned above display only the Character into the Game Scene when I cliked the button DONE, I am trying to add code into UmazingCC.cs file to display both Character and the Name added in the tab to show both of them in the Game Scene.
The original UmazingCC part code is the following
enter code hereif (GUILayout.Button("Done", bottomBarButtonStyle)){
// Save the character, fade out the camera and load up the game scene
GameObject avatarGO;
if (selectedGender == "Man") {
avatarGO = maleAvatarSpawn;
} else {
avatarGO = femaleAvatarSpawn;
}
var avatar = avatarGO.GetComponent<UMAAvatarBase>();
if( avatar != null )
{
string finalPath = savePath + "/" + characterName + ".txt";
if (finalPath.Length != 0)
{
PersistentNameHolder.characterName = characterName;
var asset = ScriptableObject.CreateInstance<UMATextRecipe>();
asset.Save(avatar.umaData.umaRecipe, avatar.context);
System.IO.File.WriteAllText(finalPath, asset.recipeString);
ScriptableObject.Destroy(asset);
// If the camera has a fader, make it fade out and load the game scene, otherwise just load the scene ourselves
if (orbitCamera.GetComponent<CameraFader>() != null) {
orbitCamera.GetComponent<CameraFader>().fadeOutAndLoadScene(gameSceneName);
} else {
Application.LoadLevel(gameSceneName);
}
The Name metod code is the following
enter code here void FinishWindowContents (int windowID) {
GUILayout.BeginHorizontal(horizontalLayoutStyle);
GUILayout.BeginVertical(verticalLayoutStyle);
GUILayout.Label ("Nombre", bottomBarLabelStyle);
characterName = GUILayout.TextField(characterName);
GUILayout.EndVertical();
GUILayout.BeginVertical(verticalLayoutStyle);
if (characterName.Length == 0) {
GUI.enabled = false;
}
For it, Could anybody say me what code lines should I add in this place to show both Character and its name in the Game Scene?
Thanks in advance and sorry for my little english.
Ps. I added a screen image to see better the problem.

Unity shader error; presumably in if statement

I am doing two line plane intersections in a shader, however I need to take account if a ray was not hit and which one of the rays has the shortest distance.
The following code however throws an error which doesn't give me any useful information (and points me in the wrong direction). If I set tex and selectN to say intersection.xy and N, it works fine (but ofcourse doesn't give the result I need).
I'm working in Unity.
float3 selectN;
float2 tex;
if (dist == 0.0) {
selectN = N2;
tex = intersection2.xy;
} else if (dist2 == 0.0) {
selectN = N;
tex = intersection.xy;
} else if (dist < dist2) {
selectN = N;
tex = intersection.xy;
} else {
selectN = N2;
tex = intersection2.xy;
}
I needed to add #pragma target 3.0 because my shader was getting "too complex".