Author Topic: script help and where to find documentation?  (Read 413 times)

2024-04-04, 11:12:39

Jens

  • Active Users
  • **
  • Posts: 198
    • View Profile
    • Ikonoform
Hi, i just installed max 2024 and some scripts aren't working anymore. I wanted to try and use chatgpt to help me create scripts, but it struggles with the coronabitmap and physmaterial. Has something changed in regards to maxscript in corona v11 and where can I find documentation for what the different things are called in maxscript?

I have tried enabling macro recorder and running stuff in max that should do things with coronabitmaps (like the converter), but sadly it doesn't show anything. Also tried google and chaos doc here, but it's not as complete as I had hoped: https://docs.chaos.com/display/CRMAX/MAXScript

Wanted a script like the image plane maker / plane plus scripts, but with some tweaks and having it work in 2024 (none of them does for me, but worked fine in 2023). So I tried this, but it gives errors regarding the coronabitmap and coronaphys material:

-- Function to create a plane from a bitmap's dimensions
fn createPlaneFromBitmap bitmap_file =
(
    -- Load the bitmap to get its dimensions
    local theBitmap = openBitmap bitmap_file

    -- Create a new plane with exact dimensions as the bitmap
    local newPlane = Plane width:theBitmap.width length:theBitmap.height name:(getFilenameFile bitmap_file) position:[0,0,0] isSelected:true

    -- Segmentation of the plane - You may comment out or delete these lines if you don't need segments
    newPlane.widthsegs = 1  -- No segmentation based on your requirement
    newPlane.lengthsegs = 1

    -- Setup Corona Physical Material with the bitmap as a diffuse map
    local coronaPhysicalMtl = CoronaPhysicalMtl()
    local correBitmap = CoronaBitmap texmap:theBitmap.filename realWorldMapSize:true
    coronaPhysicalMtl.diffusemap = correBitmap

    -- Close the bitmap as we no longer need it open
    close theBitmap

    -- Assign material to the plane
    newPlane.material = coronaPhysicalMtl

    -- Select only the newly created plane
    select newPlane

    -- Zoom Extents Selected in active viewport
    actionMan.executeAction 0 "40021"

    newPlane -- return the plane object
)

-- Function to prompt the user to select a bitmap file and create a plane
fn loadBitmapAndCreatePlane =
(
    local bitmapFilePath = getOpenFileName caption:"Load Bitmap File" types:"Image Files|*.bmp;*.jpg;*.jpeg;*.png;*.tif;*.tiff;*.gif|All Files|*.*||"

    if bitmapFilePath != undefined do
    (
        createPlaneFromBitmap bitmapFilePath
    )
)

-- Run the function to load bitmap and create plane
loadBitmapAndCreatePlane()
My small 3D model shop: www.ikonoform.com/shop
My arch viz blog: www.ikonoform.com/blog

2024-04-04, 12:09:46
Reply #1

Frood

  • Active Users
  • **
  • Posts: 1922
    • View Profile
    • Rakete GmbH
Hi,

Code: [Select]
local coronaPhysicalMtl = CoronaPhysicalMtl()
You are overwriting the material class here with undefined before a material is created, this cannot work. This is like calling "undefined()" :)

Choose "coronaMat" for example as local variable to store the material (and replace it as well in the other lines of course). Additionally, there is no #diffusemap property in CoronaPhysicalMtl. The "Base color" texmap is #baseTexmap. So if using "coronaMat" as variable:

Code: [Select]
coronaMat.baseTexmap=correBitmap
And creating CoronaBitmap would be like:

Code: [Select]
local correBitmap = CoronaBitmap filename:theBitmap.filename realWorldScale:true
Instead of the ambiguous action man command I'd just use "max zoomext sel" btw.

Hope it helps,

Good Luck


Edit: CoronaBitmap: property "realWorldMapSize" is actually "realWorldScale", changed.
« Last Edit: 2024-04-04, 12:20:32 by Frood »
Never underestimate the power of a well placed level one spell.

2024-04-04, 14:14:55
Reply #2

Avi

  • Corona Team
  • Active Users
  • ****
  • Posts: 507
    • View Profile
Try this

Code: [Select]
-- Function to create a plane from a bitmap's dimensions
fn createPlaneFromBitmap bitmap_file =
(
    -- Load the bitmap to get its dimensions
    local theBitmap = openBitmap bitmap_file
   
    -- Create a new plane with exact dimensions as the bitmap
    local newPlane = Plane width:theBitmap.width length:theBitmap.height name:(getFilenameFile bitmap_file) position:[0,0,0] isSelected:true
   
    -- Segmentation of the plane - You may comment out or delete these lines if you don't need segments
    newPlane.widthsegs = 1 -- No segmentation based on your requirement
    newPlane.lengthsegs = 1
   
    -- Setup Corona Physical Material with the bitmap as a diffuse map
    local coronaMat = CoronaPhysicalMtl()
    local correBitmap = CoronaBitmap filename:theBitmap.filename realWorldScale:true
    coronaMat.baseTexmap = correBitmap
   
    -- Close the bitmap as we no longer need it open
    close theBitmap
   
    -- Assign material to the plane
    newPlane.material = coronaMat
   
    -- Select only the newly created plane
    select newPlane
   
    -- Zoom Extents Selected in active viewport
    max zoomext sel
   
    newPlane -- return the plane object
)

-- Function to prompt the user to select a bitmap file and create a plane
fn loadBitmapAndCreatePlane =
(
    local bitmapFilePath = getOpenFileName caption:"Load Bitmap File" types:"Image Files|*.bmp;*.jpg;*.jpeg;*.png;*.tif;*.tiff;*.gif|All Files|*.*||"
   
    if bitmapFilePath != undefined do
    (
        createPlaneFromBitmap bitmapFilePath
    )
)

-- Run the function to load bitmap and create plane
loadBitmapAndCreatePlane()
Arpit Pandey | chaos-corona.com
3D Support Specialist - Corona | contact us

2024-04-04, 14:22:51
Reply #3

Jens

  • Active Users
  • **
  • Posts: 198
    • View Profile
    • Ikonoform
thank you guys!!

Since im pretty much clueless in this regard I managed to feed Frood's response to it and it actually (with some iterations) managed to get the script working. Came back here to post the working script, but Avi just beat me to it :)

Still, where can I find more info to how/what to call and name certain functions in maxscript that I can feed to chatgpt if it makes a mistake like this?

It's super powerful for a non-code type of guy like me to be able to make scripts via just my "normal" description of a function I want. If an error happens, I can feed that back to chatgpt and usually it corrects it. Was just this case it couldn't crack what was wrong with the corona bitmap naming.

Yes I know, it would probably be best if I got a basic understanding of this myself, but so far it's been working for 10 years without it ;)
My small 3D model shop: www.ikonoform.com/shop
My arch viz blog: www.ikonoform.com/blog

2024-04-04, 14:30:14
Reply #4

Avi

  • Corona Team
  • Active Users
  • ****
  • Posts: 507
    • View Profile
Get Property of any Material

Code: [Select]
-- Replace '1' with the slot number that contains your material
myMaterial = meditMaterials[1]
showProperties myMaterial

Works in compact material editor.
Arpit Pandey | chaos-corona.com
3D Support Specialist - Corona | contact us

2024-04-04, 15:09:49
Reply #5

Frood

  • Active Users
  • **
  • Posts: 1922
    • View Profile
    • Rakete GmbH
managed to get the script working.

Nice! Amazing enough what you got from the bot. Not sure about your real world scale approach, since it is not explicitly used when creating the plane but later on when creating the bitmap. So I'm attaching "my" version with fixes and real world scale for both, the plane and the material.

As for looking deeper into maxscript objects/classes:

https://help.autodesk.com/view/MAXDEV/2023/ENU/?guid=GUID-879ECFAD-7928-44B3-BCD7-276D53C89B52

where you can find the showProperties command mentioned by Avi as well. Shortest version is creating an instance and show its properties in one go like this:

Code: [Select]
show (CoronaPhysicalMtl())
show (CoronaBitmap())


Good Luck



Edit: typo


« Last Edit: 2024-04-05, 12:29:09 by Frood »
Never underestimate the power of a well placed level one spell.

2024-04-04, 16:09:59
Reply #6

Avi

  • Corona Team
  • Active Users
  • ****
  • Posts: 507
    • View Profile
Some more examples:

Get Property of any modifier

Code: [Select]
showProperties $.modifiers[#CoronaDisplacementMod]
Code: [Select]
showProperties lastCreatedObj
Code: [Select]
showClass "CShading_LightSelect*.*"
You can also use this: https://corona-renderer.com/doc

I hope this helps.







Arpit Pandey | chaos-corona.com
3D Support Specialist - Corona | contact us

2024-04-04, 16:48:55
Reply #7

Frood

  • Active Users
  • **
  • Posts: 1922
    • View Profile
    • Rakete GmbH
Btw, kind of bug report/annoyance:

Code: [Select]
showclass "Standardmaterial.*"
showclass "CoronaLegacyMtl.*"
showclass "CoronaPhysicalMtl.*"
showclass "_CoronaPhysicalMtl.*"
apropos "CoronaPhysical"


Good Luck



Never underestimate the power of a well placed level one spell.

2024-04-05, 09:26:23
Reply #8

Avi

  • Corona Team
  • Active Users
  • ****
  • Posts: 507
    • View Profile
I just consulted our devs internally and it seems like there was no better way to do this than it currently is. This is expected behavior for now.
Arpit Pandey | chaos-corona.com
3D Support Specialist - Corona | contact us

2024-04-05, 09:33:01
Reply #9

Frood

  • Active Users
  • **
  • Posts: 1922
    • View Profile
    • Rakete GmbH
Thanks for looking into it anyway,

Edit: Oh, and if this has been done just to have CoronaPhysicalMaterial on top of the material list using the material editor, please reconsider. It crumbles the basement and adds confusion just to achieve some UI effect.


Good Luck


« Last Edit: 2024-04-05, 09:44:23 by Frood »
Never underestimate the power of a well placed level one spell.

2024-04-05, 12:03:13
Reply #10

Avi

  • Corona Team
  • Active Users
  • ****
  • Posts: 507
    • View Profile
Yes, you are correct. This was done on purpose when we introduced this in corona. The goal was to make the material stand out in the UI as it helps more users overall.

Arpit Pandey | chaos-corona.com
3D Support Specialist - Corona | contact us

2024-04-05, 12:20:42
Reply #11

Frood

  • Active Users
  • **
  • Posts: 1922
    • View Profile
    • Rakete GmbH
stand out in the UI

Yes, it indeed does :) And looks ugly. I understand the purpose to "promote" CoronaPhysicalMtl those days. It comes as a bad hack affecting basic stuff though. All that renaming materials/maps in order to place them differently in any listing (or to avoid clipping) is crap imho, but go on.


Good Luck



Never underestimate the power of a well placed level one spell.

2024-04-05, 17:25:52
Reply #12

Jpjapers

  • Active Users
  • **
  • Posts: 1654
    • View Profile

Nice! Amazing enough what you got from the bot.

Ive been using chatgpt to make some maxscripts recently and it takes some time but its generally pretty good. I used it today to write a little script that organises revit imports into layers by whatever BIM property the user selects from a dropdown and it works great. I find that if you manage to get it working you can then feed the script back into chatgpt and ask it to look at code practices, efficiencies and commenting and it tends to clean things up quite nicely. Sometimes you need to prompt it with pages from the maxscript help. It also doesnt get the 'If, Then Else' structure and keeps trying 'If, Do, Else'.

I also used it to write myself a custom map node that loads colour libraries from csv files and then used it to scrape various paint manufacturers sites for all of the paint hex codes, then parse the hex, name and rgb values into the format i need for the script. Works an absolute dream! I did however manage to break it and now cant figure out how to fix it. More chatGPT maybe!

2024-04-12, 12:30:02
Reply #13

Frood

  • Active Users
  • **
  • Posts: 1922
    • View Profile
    • Rakete GmbH
Hi,

thanks for sharing your experience, I remember requesting exactly this:

a custom map node that loads colour libraries from csv files

as an additional feature for the Corona Color Picker as soon as it was introduced, but withdrawed it because standard Max material libraries appeared to be good enough and are generally usable. Still something interesting though :)


Good Luck



Never underestimate the power of a well placed level one spell.