Set Xref Material with script

Set Xref Material with script

bertv
Enthusiast Enthusiast
1,457 Views
5 Replies
Message 1 of 6

Set Xref Material with script

bertv
Enthusiast
Enthusiast

Hello,

 

I'm trying to set a Xref Material with Maxscript. But without success so far.

I can create the material, but I'm unable to set the file  name ref for some reason.  The object ref works fine.

local fileName = getOpenFileName
$.material = XRef_Material name:"my_xref_mat" srcFileName:fileName srcItemName:"box"

 

Any ideas?

0 Likes
Accepted solutions (1)
1,458 Views
5 Replies
Replies (5)
Message 2 of 6

10DSpace
Advisor
Advisor

@bertv 

 

You forgot the () after 

getOpenFileName

try

 

filename = getOpenFileName() 

 

and the filename should be returned.

0 Likes
Message 3 of 6

bertv
Enthusiast
Enthusiast

Thanks,

 

The path reads out correctly now

 

local fileMerge = getOpenFileName()
$.material = XRef_Material name:"item01" srcFileName:fileMerge srcItemName:"item01"

 

 

Problem I can't manage to link the Xref material correctly this is how the shader looks.

It says status: Unresolved Xref, File Not Found

 

xrefMaterial.JPG

 

I think it has something to do with Xref objects. But not sure how to set this by script.

 

Regards

Bert

0 Likes
Message 4 of 6

10DSpace
Advisor
Advisor

@bertv 

 

"I think it has something to do with Xref objects. But not sure how to set this by script."

 

See link below:

 

https://help.autodesk.com/view/3DSMAX/2016/ENU/?guid=__files_GUID_8B7E81F0_AC81_4518_8D8E_B0C9C67176...

0 Likes
Message 5 of 6

denisT.MaxDoctor
Advisor
Advisor
Accepted solution

@bertv wrote:

I think it has something to do with Xref objects. But not sure how to set this by script


you think it right... you have to do "merging" first. for example to "add new xref object":

 

xrec = xrefs.addnewxrefobject <xref_file> <object_name> #proxy dupMtlNameAction:#useXRefed
-- xrec is an object if all was merged well
<my_object>.material = xrec.material
-- you can name the material
delete xrec

  

0 Likes
Message 6 of 6

bertv
Enthusiast
Enthusiast

Wow,

 

Thanks for the info.

The Xref materials is working with your code @denisT.MaxDoctor 

 

Regards

Bertv

0 Likes