Set the camera on Maya's vray render - camera

In Autodesk Maya, when I click on Display Render Settings button, there is an attribute called Renderable Camera.
I need to set the right camera in this attribute via MEL script but I can't find the name of this attribute (I'm not even sure which node has this attribute in a first place).
Can anyone help me on this? Thanks!

This attribute is called cameraShape#.renderableand it must be set to true (for cameraShape1, cameraShape2, etc). Also you need to turn off all the other four scene cameras (top, front, side, persp). And then you can change main attributes for your renderable cam as well as output resolution.
camera -focalLength 24;
setAttr "cameraShape1.renderable" 1;
setAttr "frontShape.renderable" 0;
setAttr "perspShape.renderable" 0;
setAttr "sideShape.renderable" 0;
setAttr "topShape.renderable" 0;
setAttr "defaultResolution.width" 1024;
setAttr "defaultResolution.height" 512;
setAttr "cameraShape1.focalLength" 50;
setAttr "cameraShape1.farClipPlane" 100000;
setAttr "cameraShape1.depthOfField" 1;
setAttr "cameraShape1.backgroundColor" -type double3 0 1 1;
Attribute .renderable is located in cameraShape# node.

Related

.innerHTML and .innerText undefined

writing a tampermonkey script, grabbed an htmlcollection of all td's on the page with getElementsByTagName, returning 400+ tds. go to step through those to examine the contents of each td.. and debug console in browser is showing TypeError: Cannot read properties of undefined (reading 'innerText') or 'innerHTML' when I swap those two out. obv, I am referencing the items in the collection incorrectly, but I thought I was following examples...
var cells = document.getElementsByTagName("td");
var cellvalue = "example";
/* steps through all the items in the array looking at each one individually */
for (let i = 0; 1 < cells.length; i++) {
/* grabs the contents of the td */
cellvalue = cells[i].innerText;
I tried using .innerText, .innerHTML, and a few other things but I always get the same TypeError. console logging cells.length is showing correctly finding hundreds of tds, but I cant seem to reference them properly.

Processing can't access PShape array

I'm afraid I have a problem with a "NullPointerException".
I'm writing a Processing (v4) Sketch, which should load multiple svg files from a folder, into a PShape Array. Initializing the array works fine, giving it a length works fine but somehow when I want to overwrite a value, I get a NullPointerException.
int imageCount = 1;
PShape[] images;
void setup() {
images = new PShape[imageCount];
for (int i = 0; i<images.length; i++) {
println(images.length); //prints the expected result 1
images[i] = loadShape("platzhalter/Platzhalter_2_"+str(i)+".svg");
// throws NullPointerException
}
}
I hope someone here can help me, thx!
Okay so I solved it in the meantime.
Turns out that processing has some kind of limitations in terms of interpreting svg files. I had to transform text to outlines in the adobe illustrator export settings to make it work. Hope this helps anyone with the same issue.

save and close images without asking

I try to write some code to save and close top 7 images, as it is below, but when I execute the code, the DM still ask “Save changes to xxx before closing? What command or code I need to add then the code can automatically save the changes of top 7 images without any pop-up ask window. Thanks
image temp:=getfrontimage()
string imgname=getname(temp)
string currentpath, currentdirectory
if(!SaveAsDialog("Save As",imgname,currentpath))exit(0)
currentdirectory=pathextractdirectory(currentpath,2)
number i
string newname, startstring
for(i=0; i<7; i++)
{
image front:=getfrontimage()
string imgname=getname(front)
string thispath=pathconcatenate(currentdirectory, imgname)
saveasgatan(front, thispath)
hideimage(front)
closeimage(front)
}
If you want to remove an image from memory, you can delete it rather than close it. The following removes the front most image without prompting:
image img := GetFrontImage()
DeleteImage( img )
It is also good to know that image objects are the actual data array, but imageDocuments are the objects which are linked to file and window. It is therefore a command of the imageDocument class which is needed. To close an image (or rather it's imageDocument) without asking to save, you can use:
image img := GetFrontImage()
imageDocument iDoc = img.ImageGetOrCreateImageDocument()
iDoc.ImageDocumentClose( 0 ) // parameter is Boolean for "askToSave"
There is also a command to get you the front most imageDocument right away, so you may also use:
GetFrontImageDocument().ImageDocumentClose(0)

Getting Actual Placement of a Flyout

I have a flyout that appears near the cursor when a particular user input is triggered.
According to the docs, the Flyout.Placement property is only a preference and does not necessarily reflect the position of the flyout.
I expect the framework to call GetFlyoutPlacement to determine the actual placement. I want to know what the actual placement is so that I can add a little arrow pointing at the cursor position, something like shown in the following:
Is my only option to make the call to GetFlyoutPlacement myself (triggered on the Flyout.Opening event), or is there some more convenient way to do this?
My calls on GetFlyoutPlacement and GetFlyoutPlacementTargetInfo resulted in Error HRESULT E_FAIL has been returned from a call to a COM component. which didn't leave me very much to go on, so I just ended up implementing what I imagine is the logic behind those functions:
public static FlyoutPlacementMode GetActualFlyoutPlacement(
Rect placementTarget,
Size flyoutSize,
FlyoutPlacementMode preferredPlacement )
{
Rect ViewArea = Window.Current.Bounds;
ViewArea.X = 0; // may have non-zero offset for multi-monitor setups
ViewArea.Y = 0; // but we are only interested in offset relative to app view area
switch (preferredPlacement)
{
case FlyoutPlacementMode.Right:
if (desiredSize.Width < ViewArea.Width - placementTarget.Right) return FlyoutPlacementMode.Right;
if (desiredSize.Width < placementTarget.Left) return FlyoutPlacementMode.Left;
if (desiredSize.Height < placementTarget.Top) return FlyoutPlacementMode.Top;
return FlyoutPlacementMode.Bottom;
case FlyoutPlacementMode.Left:
...
}
}
Checkout the approach I suggested here. I believe it is better, because instead of guessing the internal placement algorithm it just compares the absolute coordinates of the flyout and the target element.

Getting Window Number through OSX Accessibility API

I am working on an application that moves windows of third party applications around on the screen.
To get an overview of all currently open windows, I use
CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID);
This returns an array of dictionaries defining every open window.
Here's an exemplary dictionary returned:
{
kCGWindowAlpha = 1;
kCGWindowBounds = {
Height = 442;
Width = 475;
X = 3123;
Y = "-118";
};
kCGWindowIsOnscreen = 1;
kCGWindowLayer = 0;
kCGWindowMemoryUsage = 907184;
kCGWindowName = Untitled;
kCGWindowNumber = 7328;
kCGWindowOwnerName = TextEdit;
kCGWindowOwnerPID = 20706;
kCGWindowSharingState = 1;
kCGWindowStoreType = 2;
kCGWindowWorkspace = 3;
},
The dictionary is full of good information used elsewhere but lacks an accessibility object that could be used to modify the windows' positions. Windows are clearly identified by the Window Number.
I am now using the PID (kCGWindowOwnerPID) to create an accessibility object for the window's application:
AXUIElementRef app = AXUIElementCreateApplication(pid);
Followed by retrieving a list of all windows the application has opened using AXUIElementCopyAttributeValues:
NSArray *result;
AXUIElementCopyAttributeValues(
(AXUIElementRef) app,
kAXWindowsAttribute,
0,
99999,
(CFArrayRef *) &result
);
This works and returns an array of AXUIElements.
This is where I am stuck. There seems to be no API call to retrieve the Window Number of an accessibility object. Is there any way to either
a) Find the accessibility object's Window Number (to ultimately iterate over the array and find the right window)
or
b) Otherwise clearly match a window described in the array returned by CGWindowListCopyWindowInfo to the Accessibility Objects returned by AXUIElementCopyAttributeValues?
We ended up hiring a dedicated Accessibility Developer for this task.
It turns out there is no way to do this without using undocumented APIs (a no go in our case).
Luckily, there is a practical workaround:
Loop over all open windows of the app. Get their position, size and title:
AXUIElementCopyAttributeValue(target, kAXPositionAttribute, (CFTypeRef*)&posValue);
AXUIElementCopyAttributeValue(target, kAXSizeAttribute, (CFTypeRef*)&sizeValue);
AXUIElementCopyAttributeValue(target, kAXTitleAttribute, (CFTypeRef*)&titleValue);
Next, convert the position and size into actual CGPoint and CGSize values:
AXValueGetValue(posValue, kAXValueCGPointType, &point);
AXValueGetValue(sizeValue, kAXValueCGSizeType, &size);
Compare the size, position and title against the values returned by the object in CGWindowListCopyWindowInfo().
If they match, you can safely assume it's the window you were looking for and use the already open AXUIElement (target in our case) to work it.
The overhead for looping through all open windows turns out to be negligible on OSX. There is a pretty low cap on how many windows are open at the same time.
Also, while this is not 100% accurate (it is possible that 2 windows have the same position, size and title), we haven't encountered any situation in real usage where this happens so far.
There is a private function for obtaining CG window number for a given AX object for window: _AXUIElementGetWindow .
More details in SO discussion Uniquely identify active window on OS X
It looks like there is no public API to do the task with 100% probability. Identifying windows by title and frame (as described in answer above) will works in 99.9% of cases.
Clarifying other answers that suggest the undocumented call of _AXUIElementGetWindow.
In Swift, do this:
1. Create Bridged-Header.h with the following contents:
#import <AppKit/AppKit.h>
AXError _AXUIElementGetWindow(AXUIElementRef element, uint32_t *identifier);
2. Reference this file in your build settings: (your path may vary, it is relative to project root)
3. Call like this:
// variable 'window' is your AXUIElement window
var cgWindowId = CGWindowID()
if (_AXUIElementGetWindow(window, &gcWindowId) != .success) {.
print("cannot get CGWindow id (objc bridged call)")
}
Congrats, you succesfully called objective C functions via a bridge!