Message 1 of 9
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello there,
I created the following macroscript, with the intention of projecting UV map channel 2, from multiple selected objects (LOD0), to their corresponding low resolution objects (LOD1 and LOD2):
macroscript MyCustomTool2
category:"MyTools"
tooltip:"Project UVs multiple LOD0"
(
rollout projectMutipleUVsRollout "Project UVs"
(
button projectMutipleUVsButton "Project UVs"
on projectMutipleUVsButton pressed do
(
-- Retrieve the selected objects
local selectedObjects = selection as array
-- Check if any objects are selected
if selectedObjects.count > 0 then
(
-- Loop through each selected object
for z = 1 to selectedObjects.count do
(
-- Add Projection modifier to the selected object
local obj = selectedObjects[z]
local projMod = Projection ()
addModifier obj projMod
-- Get the name of the selected object
local objName = obj.name
-- Extract the base name
local baseName = substring objName 1 (objName.count - 1)
-- Iterate through all objects in the scene
for i = 1 to objects.count do
(
local currObj = objects[i]
local currObjName = currObj.name
-- Check if the object name matches the pattern
if (findString currObjName baseName) == 1 and (currObjName != objName) do
(
--Add the matched object to the Reference Geometry List
projMod.addObjectNode currObj
)
)
--Add a Projection Mapping
projMod.addRegisteredProjectionType 1
pMap = projMod.getProjectionType 1
--Get that Projection Mapping for work with it
pMap = projMod.getProjectionType 1
--Assign UV map channels
pMap.sourceMapChannel = 2
pMap.sameAsSource = false
pMap.targetMapChannel = 2
projMod.projectAll()
)
-- Display a message
messageBox "UV projection completed."
)
else
(
-- Display a message if no objects are selected
messageBox "No objects selected." title:"Error"
)
)
)
createDialog projectMutipleUVsRollout 250 50
)
If I only select one object (LOD0), it works perfectly, but when I select multiple objects, I don't understand why, but "projMod.addRegisteredProjectionType 1" doesn't seem to work, and the code breaks after that. So, if any one could explain to me why these is happening, and give me some solution, I'll be really grateful. Thanks for your time.
Solved! Go to Solution.