Notifications
Clear all

[Closed] Automation of substitute modifier?

Im attempting to replace a large amount of CAD blocks in a scene. At the moment i have to go through each and manually apply the substitute modifier, then select the xref file. I would like to automate this by saving a file with each cad block name followed by the path to its model equivalent. then load this into a script UI that iterates through each line of the file replacing the cad blocks if they are in the scene.

So all i have to go off is the script i currently use which merges in each block, this takes a long time to complete as it was written a very long time ago and its very tempermental and not really futureproof. and what i get from the listener when applying the substitute modifier.


testpath = "L:\\Models\\Ambient Core Shelving\\Black\\G11-1335_1000x470_generic_core_kit_black.max"
modPanel.addModToSelection (Substitute ()) ui:on
$.modifiers[#Substitute].objectreference = testpath
$.modifiers[#Substitute].SubstituteType = "Type: xref" 

This doesnt work^ i cant seem to figure out how to hard code the path to the object i need to xref. at the moment it just uses the object name.

Can anyone help?
Ive been struggling with different ways to do this for about 4 months now and everything has either almost worked but nobody can help me figure out why it didnt, or i havent been able to get going with it due to my limited knowledge on maxscript.

Any help is massively appreciated!
Jack

5 Replies

I have never worked with Xref Objects in MaxScript and very few with modifiers.
But the code below works and may help to you.

testpath = @"L:\Models\Ambient Core Shelving\Black\G11-1335_1000x470_generic_core_kit_black.max" -- The file that contains the Xref object
objectname = "Sphere001"	--	The name in the file of the object you want to merge 
Xref_Object = xrefs.addNewXRefObject testpath objectname -- Import the Xref Object to your scene


The_modifier = Substitute()	-- Create a Substitute modifier
The_modifier.ObjectReference = Xref_Object	-- Asign the Xref Object to the modifier
The_modifier.ObjectName = objectname	-- Assign a name to display in the modifier pannel (not necessary)

addModifier selection (The_modifier)	-- Add the modifier to all selected objects of your scene (as an instance)

delete Xref_Object -- Delete the imported Xref Object from the scene (I'm sure there's a way to import an Xref Object whithout creating it, but I don't know how)

Thats awesome thanks! However there is one small problem. The modifier usually pops up a dialog asking about whether the materials should be brought through with the xref object but in this case it doesnt and it just applies the wire colour of the cad block to the xref model. Any ideas? The dialog option isnt displayed ijn the maxscript help for the modifier.

I wonder if i could somehow grab the material on the xref file then set it to apply after the substitution

1 Reply
(@aaandres)
Joined: 11 months ago

Posts: 0

Have you tried to find it by your own?
It’s really not difficult. Maxscript has a quite good help. But you have to try and waste time to go on.
Here you are:

testpath = @"L:\Models\Ambient Core Shelving\Black\G11-1335_1000x470_generic_core_kit_black.max" -- The file that contains the Xref object
objectname = "Sphere001"	--	The name in the file of the object you want to merge 
Xref_Object = xrefs.addNewXRefObject testpath objectname -- Import the Xref Object to your scene


The_modifier = Substitute()	-- Create a Substitute modifier
The_modifier.ObjectReference = Xref_Object	-- Asign the Xref Object to the modifier
The_modifier.ObjectName = objectname	-- Assign a name to display in the modifier pannel (not necessary)

addModifier selection (The_modifier)	-- Add the modifier to all selected objects of your scene (as an instance)

mat = Xref_Object.mat	-- Get material from Xref Object
-- mat = mat.GetSourceMaterial(true)	-- Don't comment this line if you want the material not to be an XrefMaterial
for o in selection do o.mat = mat	-- Assign material to selected objects

delete Xref_Object -- Delete the imported Xref Object from the scene (I'm sure there's a way to import an Xref Object whithout creating it, but I don't know how)

wow haha its really that simple? i have been trying to get the object material into an xrefmaterial.source and xrefmaterial.object then apply that to the substituted object. i didnt realise you could do it like this. Thanks youre awesome

EDIT: Unknown property mat in undefined. ill keep working at it