Announcements

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

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

ilyass.iatissami.1
Participant
Participant

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

ilyass.iatissami.1
Participant
Participant

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 

0 Likes
Reply
1,137 Views
18 Replies
Replies (18)

denisT.MaxDoctor
Advisor
Advisor

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? 

 

 

0 Likes

ilyass.iatissami.1
Participant
Participant

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. 

 

 

 

0 Likes

denisT.MaxDoctor
Advisor
Advisor

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...

0 Likes

ilyass.iatissami.1
Participant
Participant

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

0 Likes

denisT.MaxDoctor
Advisor
Advisor

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.

0 Likes

denisT.MaxDoctor
Advisor
Advisor

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.

0 Likes

ilyass.iatissami.1
Participant
Participant

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. 

0 Likes

denisT.MaxDoctor
Advisor
Advisor

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

 

0 Likes

denisT.MaxDoctor
Advisor
Advisor

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

0 Likes

ilyass.iatissami.1
Participant
Participant

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

0 Likes

ilyass.iatissami.1
Participant
Participant

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

0 Likes

denisT.MaxDoctor
Advisor
Advisor

@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. 😉

 

0 Likes

denisT.MaxDoctor
Advisor
Advisor

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

*/

 

0 Likes

darawork
Advisor
Advisor

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

0 Likes

ilyass.iatissami.1
Participant
Participant

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. 
 

0 Likes

denisT.MaxDoctor
Advisor
Advisor

@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!)

0 Likes

denisT.MaxDoctor
Advisor
Advisor

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.

 

 

   

0 Likes

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