Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

How to use a global struct in mcr script?

How to use a global struct in mcr script?

h.schoenberger
Enthusiast Enthusiast
1,291 Views
3 Replies
Message 1 of 4

How to use a global struct in mcr script?

h.schoenberger
Enthusiast
Enthusiast

Hi

 

I have written some functions to be executed from the 3dsmax menu.

Therefore I created a file 3dsmax/Macroscripts/myScript.mcr.

As I want to re-use functions for multiple commands, I created a struct for it.

If I place a new struct inside the macroscript function, then I can use that struct.

But I need to use that struct in multiple different commands.

But if I try to define the struct outside the Macroscript function, it is not found.

Anything I am missing?

 

Some example:

struct modSceneScripts_global
(

,fn splitFileName &file &ext =
        (
        for c = file.count to 1 by -1 do
            if (file[c]==".") then (
                ext= substring file c (file.count - c+1)
                file= substring file 1 (c-1)
                return OK
            )
        )

)



macroScript Mod_new
category:"Inhouse"
buttontext:"Modify Scene"
tooltip:"Modify Scene"
(

struct modSceneScripts_local
(

,fn splitFileName &file &ext =
        (
        for c = file.count to 1 by -1 do
            if (file[c]==".") then (
                ext= substring file c (file.count - c+1)
                file= substring file 1 (c-1)
                return OK
            )
        )
)


    localClass= modSceneScripts_local()
    globalClass= modSceneScripts_global()

)
0 Likes
Accepted solutions (1)
1,292 Views
3 Replies
Replies (3)
Message 2 of 4

blakestone
Collaborator
Collaborator
Accepted solution

To my understanding every struct/function which is called, that is not within (), is stored globally. Because of this you can call all your structs/functions when starting 3dsMax using fileIn and they should all be accessible from other scripts. This is how I have successfully done this.

 

1. Save all your structs/functions to their own individual files (this makes it easier to manage) and store them in a folder somewhere eg.

 

  • c:\maxscripts\script_001.ms
  • c:\maxscripts\script_002.ms
  • c:\maxscripts\script_003.ms etc.

2. Create a maxscript eg. "my_structs.ms" like the following this and place it within your 3dsMax startup folder:

c:\program files\autodesk\<version>\scripts\startup

 

 

(
	local files = getFiles "c:\maxscripts\*.ms"
	for i in files do fileIn i
)


Now when you launch 3dsMax it will run the "my_structs.ms" and load all your structs/functions globally and will be accessible to all your other scripts.

 

--------------------------------------------------------------------------------------
Technical 3D Graphic Artist
Autodesk 3dsMax 2015 - Service Pack 4
--------------------------------------------------------------------------------------
0 Likes
Message 3 of 4

Anonymous
Not applicable

How can I do this for Python scripts and functions?

0 Likes
Message 4 of 4

blakestone
Collaborator
Collaborator

Are you wanting to know how to make a range of Python functions global or how to access global functions in Python?

I have scripted a little with Python but not in 3dsMax so unsure what you can and can't do with it.

 

--------------------------------------------------------------------------------------
Technical 3D Graphic Artist
Autodesk 3dsMax 2015 - Service Pack 4
--------------------------------------------------------------------------------------
0 Likes