[Closed] Is setAsBackground broken??
I’m trying to set 2 different viewports to have 2 different backgrounds. The backgroundImageFileName is a global change for all viewports, it was suggested I load an image as a bitmap value then use setAsBackground <bitmap> but this doesn’t seem to work in max 2016/2018 under any of the viewport engines? Am I missing something painfully obvious with this?
a = openBitmap @"c: emp est.jpg"
setAsBackground a
Using your code I can’t set the BG image in 3ds Max 2014. But this works:
- open Viewport Configuration window
- go to Background tab
- check Use Files, set the path to the image(if it is not set already by your code) and press the Apply to Actve View button.
The BG is changed to desireed image.
Thanks but was looking for a programmatic solution. Looks like UIAccessor might be the only choice, but I’ve not seen any examples of how to do file selection using it?? Anyone else?
You already have the code:
a = openBitmap @"c: emp est.jpg"
setAsBackground a
In 3ds Max 2014 those two lines sets the file path in the Viewprot Configuration – Use Files .
Edit: You can try COREInterface and all similar stuff to avoid using UIAccessors.
That code doesn’t work for me, I don’t get anything in the viewport!? Where can I look for reference on the COREInterface stuff?
Please, see those two images(3ds max 2016):
This one is before using your code:
https://drive.google.com/open?id=1U22zgOZOfW5Bst8bHCDT3y2wnpTLzpt2
This is after your code is executed:
https://drive.google.com/open?id=1eGX7h80sn9qX7PbjNIbitr7s-NnGTi4Q
As you can see the l path to the image is set no matter that the Use FIles is not checked. Then you have only to press the Apply to Active Viewport button.
About the GOREInterface stuff is better to ask denisT or Serejah.
So I tried using the setAsBackground <bitmap> and then using the UIAccessor to open up the window, change it to “Use Files”, press the ‘apply to active viewport’ button and then press the ‘ok’ button and then repeating again on another viewport but only end up with one viewport with a background, the 1st one goes back to blank (set back to Use Customize User Interface Gradient Colors). If I open up the viewport config dialog and then change it manually to “Use Files” it’ll have the background of the second viewport instead…
Thanks guys but still none of these work… The ActionMan was useful but the 1st viewport still gets change to be the same image path as the second one… try it with this code example.
viewport.activeViewport = 3
a = openbitmap @"c: emp\imgA.jpg"
setAsBackground a
actionMan.executeAction 0 "620" -- Tools: Use Files Toggle
viewport.DispBkgImage = true;
redrawViews();
viewport.activeViewport = 4
b = openbitmap @"c: emp\imgB.jpg"
setAsBackground b
actionMan.executeAction 0 "620" -- Tools: Use Files Toggle
viewport.DispBkgImage = true;
redrawViews();
viewport.activeViewport = 3
actionMan.executeAction 0 "620" -- Tools: Use Files Toggle
It seams that
setAsBackground
overwrites the file path in the VptConfig UI for all viewports.
But this works for me:
(
pathStrArr = #("D:\Firefox_Download\Blueprints\sukhoi-su-34-fullback.png", "D:\Firefox_Download\fast dynamic viewer.png", "D:\Firefox_Download\Blueprints\sukhoi-su-34-fullback-5.png", "D:\Firefox_Download\Blueprints\su-34.gif")
pathStr = ""
dialogMonitorOPS.UnRegisterNotification id:#miauuChangeStatisticsSettingsID
dialogMonitorOps.enabled = true
function miauuChangeStatisticsSettings =
(
-- Tools: Use Files Toggle
actionMan.executeAction 0 "620"
local TCM_SETCURFOCUS = 0x1330
local backgroundTabIndex = 1
local hwnd = DialogMonitorOPS.GetWindowHandle()
local hwnd_title = UIAccessor.GetWindowText hwnd
if (hwnd_title == "Viewport Configuration") then
(
for kidHWND in (UIAccessor.GetChildWindows hWND) where ((UIAccessor.GetWindowClassName kidHWND) == "SysTabControl32") do
(
UIAccessor.SendMessage kidHWND TCM_SETCURFOCUS backgroundTabIndex 0
)
controls = windows.getChildrenHWND hwnd
lookForPath = false
stopLoop = false
for child in controls while stopLoop == false do
(
if child[5] == "Viewport Background" do
(
lookForPath = true
)
if lookForPath == true do
(
if child[4] == "Static" do
(
-- "set the path here"
UIAccessor.SetWindowText child[1] pathStr
stopLoop = true
)
)
)
UIAccessor.PressButtonByName hwnd "OK"
)
true
)
for i = 1 to 4 do
(
viewport.activeViewport = i
pathStr = pathStrArr[i]
dialogMonitorOPS.UnRegisterNotification id:#miauuChangeStatisticsSettingsID
dialogMonitorOps.enabled = true
dialogMonitorOPS.RegisterNotification miauuChangeStatisticsSettings id:#miauuChangeStatisticsSettingsID
max vptconfig
dialogMonitorOPS.UnRegisterNotification id:#miauuChangeStatisticsSettingsID
dialogMonitorOps.enabled = false
)
viewport.DispBkgImage = true
)
Tested on 3ds Max 2014 and 2018.
Affirmed, works on Max 2016 too thanks! Does it actually open the ‘File Browser’? or does it just set the path in the ViewportConfig/Background tab? I assumed you’d have to ‘press’ the “Files…” button…
This:
UIAccessor.SetWindowText child[1] pathStr
only sets the path in the textbox.