Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

Community
3ds Max Programming
Welcome to Autodesk’s 3ds Max Forums. Share your knowledge, ask questions, and explore popular 3ds Max SDK, Maxscript and Python topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How can i write a script which allows me to assign texture/materials to my elements ?

18 REPLIES 18
Reply
Message 1 of 19
ilyass.iatissami.1
1147 Views, 18 Replies

How can i write a script which allows me to assign texture/materials to my elements ?

Hello, 

 

 I have a 3D Model which contains a lot of elements with the same name (walls, floors, doors...). What i did is to assign manually the textures to my elements (with bitmap, and Autodesk Material Library). What i want to have is a script with MaxScript allows me to assign automatically the textures to my elements, so if i want to change a texture for example, i can do it automatically not manually. Do you have any idea how i can do this ? 

 

Thank you 

18 REPLIES 18
Message 2 of 19

Now we can go...

 

What do you mean by updating a texture?

You have several scenes with materials, and these materials use a certain texture that one day you want to change? I assume you want to replace the existing filename with a new one.... right?

 


Another frequently asked question is -
how to replace all materials in a scene by taking new ones with the same names from the specified material library? 

 

 

Message 3 of 19

By updating a texture, i just want to assign a certain material and a certain texture from my Library to certain elements which have the same name in my 3D Modele. I want to do this because i dont want to do this processus manually, and if in the future i want to change the materials or the texture file i can change it in the script directly. 

 

 

 

Message 4 of 19

Post an example of your MAX scene and material library (two files, where the .max file is in version 2020).

 

The example scene must contain objects that use materials from the example library...

Message 5 of 19

The size of my model is more than 71 MB :s 

Message 6 of 19

I don't need the whole scene... remove most of it and keep the 10-15 objects that make sense.

If the objects themselves are large, remove most of their geometry... I don't care about the mesh, I'm only interested in the objects (nodes) and materials.

Message 7 of 19

You simply need to understand that in order to find the correct solution, you require something to test, debug, and evaluate it on. If the client doesn't provide such a test case, the developer will have to create one. In our business, this consumes both time and money.

Message 8 of 19

Attached my 3D Model, the thing that happens is i lost all my textures when i export my Revit model to 3ds Max using the FBX Format, so i have to assign materials and textures in 3ds Max to improve the quality of visualisation. 
You can find also an example of a material file (American-cherry) which exists in the Materials Library of 3ds Max, here is the path to this file : C:\Program Files (x86)\Common Files\Autodesk Shared\Materials\Textures\1\Mats\american_cherry.png

 

I would like to have a script allows me to assign this material to all my floors in the model. 

Message 9 of 19

how do I know what is "floor" in your file?

 

Message 10 of 19

By the way... What is your level of proficiency in 3DS MAX system, and MaxScript? Do you know how to evaluate a script (code)?

Message 11 of 19

any horizontal surface. We can just do a test for now

Message 12 of 19

For the moment, i am good at 3ds Max, and i am in the process of learning MaxScript 

Message 13 of 19


@ilyass.iatissami.1 wrote:

any horizontal surface. We can just do a test for now


No. it won't work that way.

It would be a different task - to find all horizontal surfaces. If you think this is trivial, find them all yourself and call them, for example, "floor"... will be your MaxScript homework. 😉

 

Message 14 of 19

learn MXS, study the code... feel free to ask questions...

 

delete objects
gc()

-- make test material library:

meditmaterials[1] = Standard name:"Box" diffusecolor:blue
meditmaterials[2] = Standard name:"GeoSphere" diffusecolor:orange
meditmaterials[3] = Standard name:"Teapot" diffusecolor:green



-- make test sceene:

geo_classes = #(Box, GeoSphere, Teapot)
seed 0


for k=0 to 99 do 
(
	i = random 1 geo_classes.count
	
	p = [mod k 10 * 80, k/10 * 80, 0] 
	c = random orange blue 
	n = geo_classes[i] pos:p wirecolor:c
)


-- base methods:

fn getBasename node = 
(
	(trimright node.name "0123456789_") as name
)


fn applyMaterialByName node lib: = 
(
	basename = getBasename node
	mat = meditmaterials[basename]
	if iskindof mat Material do 
	(
		node.mat = mat
	)
)


/*
-- apply materials by name:

for node in objects do applyMaterialByName node lib:meditmaterials

*/

 

Message 15 of 19

Hi,

 

I think you're going about this the long, complicated and perhaps wrong way;

If you File -> Referance -> 'Manage Links' your fbx export from Revit, then each time the Revit model changes and you export a new fbx... all you have to do is Reload the fbx link in the file referances window and Max will keep all your previous texture assignments (and modifier stack if you added anything to any of the elements of the fbx in the scene in 3DSMax).

darawork_2-1689773455153.png


This way you only need to apply materials once, and not each time you reload the fbx.
Or try to come up with a Maxscript routine to do it for you, as essentially, one already exists.

Regards,

Darawork
AutoDesk User
Windows 10/11, 3DS Max 2022/24, Revit 2022, AutoCad 2024, Dell Precision 5810/20, ASUS DIY, nVidia Quadro P5000/RTX 5000/GTX760

Message 16 of 19

Hi, 

 

 I just change the name of the majority of my walls in the scene and i name them ''wall''. I did the same thing for my floors and i name them ''floor''. 

So for now i want to assign the same texture to all my floors in the model. 
 

Message 17 of 19


@ilyass.iatissami.1 wrote:

Hi, 

 

 I just change the name of the majority of my walls in the scene and i name them ''wall''. I did the same thing for my floors and i name them ''floor''. 

So for now i want to assign the same texture to all my floors in the model. 
 


Well, now all that's left is to save the file in the right version. 😉

(MAX 2020!)

Message 18 of 19

to apply the specified texture file a texture map is required...
to apply the texture map a material is required...

 

some object (floor object, for example) has an Autodesk_Generic material, another a MultiMaterial... 

 

 

 

Do you know what Technical specification is? 

 

A technical specification is a document that outlines the requirements and features that a product has to have in order to work as intended.

 

Therefore, please provide a detailed description of your desired outcome to avoid any further questions or misunderstandings.

 

 

   

Message 19 of 19

I don't understand. If your walls are named "wall", can't you just select them by name and assign wall_material?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report