- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Now I am completely new to the max scripting to be frank for scripting itself so i was trying to make a max script that allows me to have this functionalities
Functionality:
- Source Folder Selection: When you click Select source folder, it opens a dialog to choose a folder. This folder is stored in the sourceFolder variable.
- Target Folder Selection: Clicking Select target folder allows you to select a destination folder unless the Same as input checkbox is selected.
- Same as Input Checkbox: If this is checked, the script saves the .fbx file in the same folder as the .max file.
- Conversion Process: When you press the Start conversion button, the script converts all .max files in the source folder (and subfolders) to .fbx. The .fbx files are saved either in the target folder or in the same folder as the .max file, depending on the checkbox.
and the code i wrote with the help of chat gpt ,Gemini and when i ran the code i am always getting the error
-- Syntax error: at ;, expected <factor>
In line: -- File name:
)
C:\Users\selva\OneDrive\Desktop\code_14.ms
-- Line number: 50
this is the code i generated using the ai can any one review it and explain what i am doing wrong-- UI Creation
try (destroyDialog convDialog) catch()rollout convDialog "Max to FBX Converter" width:300 height:200
(
-- UI Elements
local sourceFolder = ""
local targetFolder = ""
local sameAsInput = falsebutton btnSource "Select source folder" pos:[10,10] width:280
button btnTarget "Select target folder" pos:[10,50] width:280
checkbox chkSameAsInput "Same as input" pos:[10,90] width:280
button btnConvert "Start conversion" pos:[10,130] width:280-- Function to Select Source Folder
on btnSource pressed do
(
sourceFolder = getSavePath caption:"Select Source Folder"
if sourceFolder != undefined then
format "Source folder selected: %\n" sourceFolder
else
messagebox "No source folder selected!"
)-- Function to Select Target Folder
on btnTarget pressed do
(
targetFolder = getSavePath caption:"Select Target Folder"
if targetFolder != undefined then
format "Target folder selected: %\n" targetFolder
else
messagebox "No target folder selected!"
)-- Toggle Same as Input Checkbox
on chkSameAsInput changed state do
(
sameAsInput = state
if sameAsInput then
targetFolder = ""
)-- Conversion Function
on btnConvert pressed do
(
if sourceFolder == "" then
(
messagebox "Please select a source folder!"
return
)
-- Ensure a target folder or "Same as input" is selected
if not sameAsInput and targetFolder == "" then
(
messagebox "Please select a target folder or enable 'Same as input'!"
return
)
-- Gather .max files from the source folder and subfolders
local maxFiles = getFiles (sourceFolder + "\\**\\*.max")if maxFiles.count == 0 then
(
messagebox "No .max files found in the selected folder!"
return
)-- Loop through all .max files and convert to .fbx
for maxFile in maxFiles do
(
local folderPath = getFilenamePath maxFile
local fileName = getFilenameFile maxFile
local fbxPath-- Set output folder based on checkbox state
if sameAsInput then
(
fbxPath = folderPath + fileName + ".fbx"
)
else
(
-- Create a subfolder in the target folder that mirrors the source folder structure
-- Corrected relative path calculation
local relativePath = substring(folderPath, (sourceFolder.count + 2), (folderPath.count - (sourceFolder.count + 1)))
fbxPath = targetFolder + "\\" + relativePath + "\\" + fileName + ".fbx"
makeDir (getFilenamePath fbxPath) -- Create subfolder if not exists
)-- Load and export the file safely with error handling
try
(
loadMaxFile maxFile useFileUnits:true quiet:true
exportFile fbxPath #noPrompt using:FBXEXP
format "Converted: % to %\n" maxFile fbxPath
) catch()
)messagebox "Conversion complete!"
)
)createDialog convDialog
thanks
Solved! Go to Solution.