Author Topic: Support for Substance2 Map in Relink Bitmaps  (Read 3034 times)

Hello Substance team,
     I'm Colin and I am the creator of Relink Bitmaps and I love substance.  I got a request from some of my users to add support for substance in Relink Bitmaps.

Relink Bitmaps is a 3dsmax script that repaths all of your textures/hdris/point caches/etc. assets to another directory, making it easy to work on different computers with drives mapped.

Here's a video on Relink Bitmaps:
https://www.youtube.com/watch?v=6mxfqodWjd4

While adding support I've found a bug with the integration into Max, I'm unsure if it's on your side or Autodesk's so I wanted to report it.  The bug is with the Substance2 map type.  The Substance(1) map type is working as intended.

Specs:
Win10 - x64 Pro
3dsMax 2018.4 Update (20.0 - 20.4.0.4254)

Running this Maxscript generates an error:

Maxscript
Code: [Select]
clearListener()

-- Create a new Substance2 map
sub = Substance2()

-- put it in slot 1 of the material editor
medit.putMtlToMtlEditor sub 1
MatEditor.Open()

-- Print all of the properties of a Substance2 map
print (getPropNames sub)

-- Print the SubstanceFilePath
print sub.SubstanceFilePath

Listener
Code: [Select]
OK
Substance2:Substance2
OK
OK
#SubstanceFilePath
#ExportPresetFilePath
#ImportPresetFilePath
#numIMultipleOutputChannels
#Coordinates
OK
-- Error occurred in anonymous codeblock; filename: C:\Users\colin\Desktop\RB_Substance_Bug.ms; position: 307; line: 14
-- Known system exception
-- ########################################################################
-- Address: 0x6d32b8a9; nCode: 0x00000000C0000005
-- Desc: EXCEPTION_ACCESS_VIOLATION The thread tried to read from or write to a virtual address for which it does not have the appropriate access.
--       Read of Address: 0x000002B53F800000
-- ########################################################################
-- MAXScript callstack:
-- thread data: threadID:20312
-- ------------------------------------------------------
-- [stack level: 0]
-- In top-level
-- ########################################################################
-- C++ callstack:
-- (maxutil): (filename not available): MaxSDK::Util::Logger::GetLogHandle
-- (maxutil): (filename not available): MaxSDK::Util::MaxString::FromUTF16
-- (maxutil): (filename not available): WStr::WStr
-- (ParamBlk2): (filename not available): NURBSTextureChannel::GetTextureSurface
-- (ParamBlk2): (filename not available): CopyParamBlock2ToParamBlock
-- (MAXScrpt): (filename not available): MAXWrapper::get_interfaces_vf
-- (MAXScrpt): (filename not available): MAXWrapper::get_property
-- (MAXScrpt): (filename not available): MAXWrapper::get_property
-- (MAXScrpt): (filename not available): PropertyThunk::eval
-- (MAXScrpt): (filename not available): MappedGeneric::apply
-- (MAXScrpt): (filename not available): CodeTree::eval
-- (MAXScrpt): (filename not available): SourceFileWrapper::eval
-- (MAXScrpt): (filename not available): Listener::set_style
-- (USER32): (filename not available): GetWindowRgnBox
-- (USER32): (filename not available): Ordinal2573
-- (USER32): (filename not available): Ordinal2573
-- (USER32): (filename not available): CallWindowProcW
-- (USER32): (filename not available): CallWindowProcW
-- (UIControls): (filename not available): InitializeCustomUI
-- (UIControls): (filename not available): (function-name not available)
-- (USER32): (filename not available): CallWindowProcW
-- (USER32): (filename not available): DispatchMessageW
-- (USER32): (filename not available): IsDialogMessageW
-- (3dsmax): (filename not available): NodeAndAnims::SetNode
-- ########################################################################

Here is the equivalent Substance (v1) map type that does not throw an error

Maxscript
Code: [Select]
clearListener()

-- Create a new Substance2 map
sub = Substance()

-- put it in slot 1 of the material editor
medit.putMtlToMtlEditor sub 1
MatEditor.Open()

-- Print all of the properties of a Substance2 map
print (getPropNames sub)

-- Print the SubstanceFilePath
print sub.SubstanceFilename

Listener
Code: [Select]
OK
Substance:Substance
OK
OK
#SubstanceFilename
#coords
#globalTextureWidth
#globalModeScale
#localRelativeTextureWidth
#localAbsoluteTextureWidth
#localMode
#globalTextureHeight
#localRelativeTextureHeight
#localAbsoluteTextureHeight
#lockAspectRatio
#rolloutStates
#numIMultipleOutputChannels
#output
OK
""
""
Last Edit: July 23, 2018, 06:47:58 am

Is this intentional behavior? 

@Colin Senner The attributes in the new plugin are more dynamic, so at that point the filepath hasn't really been initialized as an attribute, as no Substance has actually been loaded into the Substance2 node. It may not be intended per se, but it's more a particularity in difference between the two plugins.

If you're using that to attempt to determine whether a Substance has been loaded, we should look at adding a direct MaxScript call to the Substance to determine that directly, such as a Substance2.isInitialized() method to return true/false.

Although as a whole, our function call should return something default and not throw an error, so that in itself is not intended and should be addressed.
Software Engineer, Integrations
Maya, 3ds Max and Core Libraries

Testing it on my machine, it returns an empty path as of now.

Code: [Select]
#SubstanceFilePath
#ExportPresetFilePath
#ImportPresetFilePath
#numIMultipleOutputChannels
#Coordinates
#Substance_Output_Settings
""

It may be that something has already been changed there for the next release.
I hope that helps.
Software Engineer, Integrations
Maya, 3ds Max and Core Libraries

@Galen
Testing it on my machine, it returns an empty path as of now.

Code: [Select]
#SubstanceFilePath
#ExportPresetFilePath
#ImportPresetFilePath
#numIMultipleOutputChannels
#Coordinates
#Substance_Output_Settings
""

It may be that something has already been changed there for the next release.
I hope that helps.

Great, just not throwing an error is what I'm after.  I can add support for substance file paths for Relink Bitmaps.  Can you point me to the most up-to-date substance plugin that resolves this issue?

Thanks!
Last Edit: July 31, 2018, 08:39:07 am

The 2.1.1 release of the plugin is out now on the webpage. If the problem is still there for you in that version, please let me know.
Software Engineer, Integrations
Maya, 3ds Max and Core Libraries

The 2.1.1 release of the plugin is out now on the webpage. If the problem is still there for you in that version, please let me know.

Many thanks!

@Colin Senner

Hi Colin,

Did the new update fix your issue? I'd like to know if there's still more to do to fix the error you found.
Software Engineer, Integrations
Maya, 3ds Max and Core Libraries

Galen, thanks for following up, I apologize for not getting back to you earlier.  I haven't revisited it yet since we last spoke.  It's still in my todo list.  I'll post here when I get to the next release. 

Thanks for all your help.
Colin