I am getting a syntax error called -- Syntax error: at ;, expected <factor> In line: -- File name: ) C:\Users\selva\OneDrive\Desktop\code_14.ms -- Line number: 50

I am getting a syntax error called -- Syntax error: at ;, expected <factor> In line: -- File name: ) C:\Users\selva\OneDrive\Desktop\code_14.ms -- Line number: 50

selvakvigneshmaya
Advocate Advocate
824 Views
5 Replies
Message 1 of 6

I am getting a syntax error called -- Syntax error: at ;, expected <factor> In line: -- File name: ) C:\Users\selva\OneDrive\Desktop\code_14.ms -- Line number: 50

selvakvigneshmaya
Advocate
Advocate

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 = false

    button 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



  •  
0 Likes
Accepted solutions (1)
825 Views
5 Replies
Replies (5)
Message 2 of 6

selvakvigneshmaya
Advocate
Advocate

UPDATE
I now actually separated  the code into three parts, each handling the functionality of one button each time now part 1 and part 2 didnt had any errors in it but the part 3 alone had the issues.


Part 1: Folder Selection for Source

This part contains the functionality to select the source folder.

Part 2: Folder Selection for Target and Same as Input Checkbox

This part allows the user to select the target folder and use the "Same as input" option.

Part 3: Conversion Functionality

This part contains the conversion logic from .max to .fbx.


now the code in the PART 3 is

-- Part 3: Start Conversion

try (destroyDialog convertDialog) catch()
rollout convertDialog "Start Conversion" width:300 height:100
(
-- UI Elements
button btnConvert "Start conversion" pos:[10,10] width:280
local sourceFolder = "YourSourceFolderHere" -- Replace this with the selected source folder
local targetFolder = "YourTargetFolderHere" -- Replace this with the selected target folder
local sameAsInput = false -- Replace with the actual state from your UI

-- 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
if sameAsInput then
(
fbxPath = folderPath + fileName + ".fbx"
)
else
(
-- Create a subfolder in the target folder that mirrors the source folder structure
local relativePath = folderPath[sourceFolder.count+2] -- relative subfolder path
fbxPath = targetFolder + "\\" + relativePath + "\\" + fileName + ".fbx"
makeDir (getFilenamePath fbxPath) -- Create subfolder if not exists
)

-- Load and export the file
loadMaxFile maxFile useFileUnits:true quiet:true
exportFile fbxPath #noPrompt using:FBXEXP
format "Converted: % to %\n" maxFile fbxPath
)

messagebox "Conversion complete!"
)
)

createDialog convertDialog

i think it will make a bit easier for you guys to solve my problem

 

 

0 Likes
Message 3 of 6

MartinBeh
Advisor
Advisor
Accepted solution

"and the code i wrote with the help of chat gpt ,Gemini and when i ran the code i am always getting the error"

 

No offense but I doubt people here will find the time to help you to debug AI-written code.

Why do you think this code should work?

 

What you describe what you are trying to get is a batch converter that loads from source and exports to target folder as FBX. There should be already a handful of free (and functional) scripts out there that will do this for you.

 

Here are the three top hits I found when searching for "3ds Max batch converter"

I have not tested any of them but your time might be better spent evaluating this (or trying to understand their code) rather than wasting time with AI generated code...

 

good luck

Martin B   EESignature
→ please 'Like' posts that are helpful; if a post answers your question please click the "Accept Solution" button.
Message 4 of 6

denisT.MaxDoctor
Advisor
Advisor

Sometimes, I successfully use ChatGPT to write code. ChatGPT generates good names for functions and variables and writes excellent comments. Of course, I always remove the body of its functions, but everything else can be utilized.👍

Message 5 of 6

istan
Advisor
Advisor

Honestly speaking, the keyword is sometimes. I would rather use the words rarely and depends on. 😁

 

Message 6 of 6

denisT.MaxDoctor
Advisor
Advisor

@istan wrote:

Honestly speaking, the keyword is sometimes. I would rather use the words rarely and depends on. 😁

 


the key words - "remove the body of the function" 😁