Problem to save render jpeg with maxscript - save

I am making a script to automate the process of render multiple .max files. I almost finished what I pretend to achive, the only problem is that I don't know how to save the render image by maxscript. I tried several ways I foud on the internet but none of them works.
studioFile = getOpenFileName caption: "Select the Studio"
loadMaxFile studioFile
folderPath = getSavePath caption: "Select the Folder with the Assets to Render"
maxPath = folderPath + "\*.max"
maxFiles = getFiles maxPath
renderPath = getSavePath caption: "Select the Render Folder"
for current in maxFiles do(
xrefs.addNewXRefFile current
currentName = getFilenameFile current
print currentName
for c in cameras where classof c != Targetobject do(
render camera:c output: ("E:\\MUVA\\Renders\\" + currentName + "_" + c.name + "_" + ".jpeg")
)
xrefs.deleteAllXRefs()
)
This is how my code is for now and explaining it:
First, I made a Dialog Box for the user to select what I am calling "Studio" that is a scene with lighting and cameras ready for the render and then open it;
Second, is another Dialog Box for the user to select the folder where the .max files to render are;
Thrid, is another Dialog Box for the user to select the folder where he wish to save the renders;
Then I made a loop where through a list, the program will add the .max file to render as a xref scene and rigth after that get the name of the .max file to use in the saving.
The next and final loop is to get a render from each camera in the scene and then save but the problem is that the image is not been saved in the folder selected.
I really don't know more what to do. So, I would be very grateful if somebody could help me with this.
PS.: The selected folder to save the renders is not been used in the output of the render by now because I was testing putting all the path to the folder.

As per MAXScript reference, the parameter for filename is outputfile:. In your case the line would be:
render camera:c outputfile:("E:\\MUVA\\Renders\\" + currentName + "_" + c.name + "_" + ".jpeg")
There's also another way: you can save the bitmap object that the render() function returns:
bm = render camera:c
bm.filename = "E:\\MUVA\\Renders\\" + currentName + "_" + c.name + "_" + ".jpeg"
save bm
The directory must exist for any of these methods to work, so you may want to create it before your loop:
makeDir "E:\\MUVA\\Renders" all:true

Related

How to recursively read files and folders in ruby

folks.
I've been struggling with a deceptively tricky problem for a few days now. I had been determined to crack it on my own but alas, here I am.
The aim is to create a menu system during the installation of a Rails 5 application using seeds.rb. The menu should mirror an existing directory structure. The code is supposed to start at /home/install/sitename/ and from there, every folder it encounters should become a menu category and every file should become a menu item ( == post).
So far, I have been able to get the folder structure right using the code below, but I can't get it to make the menu items properly.
this_item = 0
Dir.chdir(#installation_media_path + '/menu/') do
this_level = Dir.glob('*/').sort
this_item += 1
# for each folder at this level
this_level.each do |item|
# remove the trailing slash
item = item[0...-1]
# take the number from the beginning of the filename and use it for the menu position
position = item.split(' ')[0]
# the remainder of the filename is used as the item title
title = item.sub(position.to_s + ' ', '')
puts item.to_s + '...'
# create the menu item
brief = File.read(#installation_media_path + '/menu/' + item + '/.brief') if File.exist?(#installation_media_path + '/menu/' + item + '/.brief')
PostCategory.create!(
title: title,
parent: 1,
position: position
)
this_item = PostCategory.last.id
There can be up to four levels of nested directories, and for each one, I repeat this block and use this_item as the parent. I want to do this without repeating code but I can't figure out how to do it.
And then somewhere in there, I need to incorporate the following code, but so far, my attempts have resulted in repeated or blank entries, because I can't figure out where to put this block.
if File.exist?(#installation_media_path + '/menu/' + item + '/*.txt')
articles = Dir.glob('*.txt').sort
articles.each do |article|
title = File.basename(article, ".txt")
body = File.read(article)
Post.create!(title: title, meta_desc: "",
user_id: 1,
post_category_id: this_item,
body: body
)
end
end
Anyway, you get the idea. If anyone can help me figure this out, I'd be very grateful.

How to handle URL relative/absolute "glitch" in contenteditable when copy and pasting

In contenteditable regions, if you paste an element with a URL attribute, in some browsers it converts the URL from relative to absolute.
I've read through some bug reports that claim it's "fixed" in the latest release, but it's not.
I threw together this fiddle to demonstrate: Hurray for Demos!
It's there, it's ugly, and I'm wondering what is the best way to fix it.
The 1st idea that comes to mind is onpaste, find all anchors in the current node and parse it with regex. Not ideal I suppose, but it might be effective.
???
???
I really wish they'd just leave things alone and not create so many browser related issues with contenteditable, but I guess that would make it too easy.
Any thoughts on the best way to address this?
CKEditor, before letting browser break the data, copies all src, name and href attributes to data-cke-saved-src|href attributes. Unfortunately, since data is a string, it has to be done by regexp. You can find the code here: /core/htmldataprocessor.js#L772-L783.
var protectElementRegex = /<(a|area|img|input|source)\b([^>]*)>/gi,
// Be greedy while looking for protected attributes. This will let us avoid an unfortunate
// situation when "nested attributes", which may appear valid, are also protected.
// I.e. if we consider the following HTML:
//
// <img data-x="<a href="X"" />
//
// then the "non-greedy match" returns:
//
// 'href' => '"X"' // It's wrong! Href is not an attribute of <img>.
//
// while greedy match returns:
//
// 'data-x' => '<a href="X"'
//
// which, can be easily filtered out (#11508).
protectAttributeRegex = /([\w-]+)\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|(?:[^ "'>]+))/gi,
protectAttributeNameRegex = /^(href|src|name)$/i;
function protectAttributes( html ) {
return html.replace( protectElementRegex, function( element, tag, attributes ) {
return '<' + tag + attributes.replace( protectAttributeRegex, function( fullAttr, attrName ) {
// Avoid corrupting the inline event attributes (#7243).
// We should not rewrite the existed protected attributes, e.g. clipboard content from editor. (#5218)
if ( protectAttributeNameRegex.test( attrName ) && attributes.indexOf( 'data-cke-saved-' + attrName ) == -1 )
return ' data-cke-saved-' + fullAttr + ' data-cke-' + CKEDITOR.rnd + '-' + fullAttr;
return fullAttr;
} ) + '>';
} );
}
Then, while processing HTML taken from editable element, data-cke-saved-* attributes override the original ones.
This looks like a browser bug that's not specific to contenteditable: https://bugzilla.mozilla.org/show_bug.cgi?id=805359
That issue was opened 10 years ago and last updated 6 years ago. Yet it's still open.
You can see the bug here on StackOverflow. Inspecting any SO link shows that the href value is a relative URL. Copying it and pasting it as HTML has the relative link rewritten into an absolute URL.
Example:

Sporadic access denied error with photos stored on filesystem in ASP.net MVC project

Some Background
I have an ASP.net MVC 4 web application which provides access to a large number of photos. Each photo is given a unique ID from a MySQL table which then makes up the filename in hex form and stored in a folder on the file system.
For example:
D:\Photos\69F.jpg
Throughout the application, different sized thumbnails are displayed which are created using the original photo. Since the thumbnails are changed very rarely, if at all, the thumbnails are created and saved to the same file-system folder in the following formats. (This means that 90% of the time, the photo can simply be returned immediately without any image processing).
Thumbnail Normal - D:\Photos\69F_t.jpg
Thumbnail Map - D:\Photos\69F_tm.jpg
All photos are accessed through a special controller (ImageController), this controller has a number of actions depending on the type of thumbnail that is required. For example, if a normal thumbnail is required, the Thumb action must be called which then determines whether the thumbnail exists and if not, creates & saves it before returning it to the browser.
\Image\Thumb\1695
The application is running under an account which has full access to the folder mentioned above and since most of the time this works, this cannot be a permissions issue!
The issue
The problem I have is that I am getting sporadic errors being reported from the application when calls are being made to get thumbnails. The errors all follow the format below, but of course the photo ID changes (i.e., it happens on more than 1 photo):
The process cannot access the file 'D:\Photos\69F_t.jpg' because it is being used by another process.
or...
Access to the path 'D:\Photos\69F_t.jpg' is denied.
The errors above are both originating from Return File(...) line in the final Try...Catch:
Function Thumb(Optional ByVal id As Integer = Nothing)
Dim thumbImage As WebImage
Dim dimension As Integer = 200
' Create the image paths
Dim imageOriginal As String = System.Configuration.ConfigurationManager.AppSettings("imageStore") + Hex(id) + ".jpg"
Dim imageThumb As String = System.Configuration.ConfigurationManager.AppSettings("imageStore") + Hex(id) + "_t.jpg"
' If no image is found, return not found
If FileIO.FileSystem.FileExists(imageOriginal) = False Then
Return New HttpNotFoundResult
End If
' If a thumbnail is present, check its validity and return it
If FileIO.FileSystem.FileExists(imageThumb) = True Then
thumbImage = New WebImage(imageThumb)
' If the dimensions are correct, simply return the image
If thumbImage.Width = dimension Then
thumbImage = Nothing
Return File(imageThumb, System.Net.Mime.MediaTypeNames.Image.Jpeg)
End If
End If
' If we get this far, either the thumbnail is not the right size or does not exist!
thumbImage = New WebImage(imageOriginal)
' First we must make the image a square
If thumbImage.Height > thumbImage.Width Then
' Portrait
Dim intPixelRemove As Integer
' Determine the amount to crop off the top and bottom
intPixelRemove = (thumbImage.Height - thumbImage.Width) / 2
thumbImage.Crop(intPixelRemove, 0, intPixelRemove, 0)
Else
' Landscape
Dim intPixelRemove As Integer
' Determine the amount to crop off the top and bottom
intPixelRemove = (thumbImage.Width - thumbImage.Height) / 2
thumbImage.Crop(0, intPixelRemove, 0, intPixelRemove)
End If
thumbImage.Resize(dimension + 2, dimension + 2, True, True)
thumbImage.Crop(1, 1, 1, 1)
thumbImage.Save(imageThumb)
thumbImage = Nothing
Try
Return File(imageThumb, System.Net.Mime.MediaTypeNames.Image.Jpeg)
Catch ex As Exception
Return New HttpNotFoundResult
End Try
End Function
The questions
I'm pretty sure that something has left the file open so is not letting the application return the file to the browser, but whatever it is, its very sporadic as this works fine on 90-95% of calls.
Either that or the issue is due to concurrency as more than 1 person tries to access the same file.
Can anyone spot what might be causing this?
Am I likely to suffer more issues if multiple people try to access the same photo thumbnail at the same time?

Removing "undefined" in pre populated url form link (from Modified Google Expense Report script)

I've modified the standard google drive expense report system to use it as a competency and experience matrix where the manager can approve/reject a form.
The problem i'm encountering is when a form is rejected by the manager it sends a link back to the employee with a link to a form pre-populated by the url.
However if the employee didn't enter a value in the original form the url populates it as "undefined".
Question, can I pre-populate a form via url removing or replacing the "undefined" values?
Perhaps the code will explain better than I can.
+ "<P><b>" + 'Please re-submit your form <a href=' + USER_FORM_URL +
'&entry_2=' + encodeURIComponent(row.forename) + '&entry_3=' +
encodeURIComponent(row.surname) + '>here</a></b>'
Any help would be much appreciated, struggled to find a solution "out there".
Tom
image link http://s11.postimage.org/dyd1olkoz/url_stack.jpg as i'm a new poster.
Looks like the getObjects() function in the script may skip adding a value to the row object, later used in sendReportToManager(), if the value is empty in the expense report spreadsheet. So, later trying to append something like row.bananas (or something empty in sheet and thus not defined on object) will result in 'undefined' being appended to the string instead. If you look at your querystring for the form with the 'undefined' values, you should see 'undefined' in the url's querystring.
You can avoid this by wrapping your encodeURIComponent(row.XXXX) calls for potentially empty columns to be something like this: row.XXXX ? encodeURIComponent(row.XXXX) : ""
So, replace the likes of:
+ "<P><b>" + 'Please re-submit your form <a href=' + USER_FORM_URL +
'&entry_2=' + encodeURIComponent(row.forename) + '&entry_3=' +
with
+ "<P><b>" + 'Please re-submit your form <a href=' + USER_FORM_URL +
'&entry_2=' + (row.forename ? encodeURIComponent(row.forename) : "") + '&entry_3=' +

How do I pull the URL/Path of the sharepoint document library I'm in from Excel VB?

I would like to set the filename for an item I create in an Excel Document Library. Howeverm when I try to interfere with the standard save with my own filename, it wants to save to my LOCAL MACHINE. I would happily like to supply the PATH if that is necessary, but I really DONT WANT TO HARD CODE IT.
Are there any properties I can use to parse this info? Meta data? Template?
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If SaveAsUI Then
Sheets("Purchase Order").Range("Description,VendorInfo,QUANTITY1,PRODUCT1,ITEM1,PRICE1,submitter,ShipVia,Terms,MACRO_ALERT").Interior.ColorIndex = xlColorIndexNone
Sheets("Purchase Order").Range("Location").Interior.Color = RGB(184, 204, 228)
Sheets("Purchase Order").Range("MACRO_ALERT").Value = ""
Dim MyFileName As String
Dim MyFilePath As String
' MyFilePath = "http://server/dept/purchasetracking/"
MyFilePath = Application.Path
MyFileName = "PO_" & Format(Now(), "yyyymmdd-hhnnss")
MsgBox (MyFilePath & MyFileName)
ActiveWorkbook.SaveAs Filename:=MyFilePath & MyFileName ', FileFormat:=52
' ActiveWorkbook.SaveAs Filename:=MyFileName
End If
End Sub
I like to use function GetSetting() and statement SaveSetting to save such informations to the registry (last used path, etc.).
When the file is opened from a SHP folder, ActiveWorkbook.Path starts with "http://". In this case you could save this path from a Sub Workbook_Open() procedure into the registry to retain the SHP path information. This can be later on used to offer a good path/filename to the user.
Hope that helps .... Good Luck MikeD

Resources