@m_adam Thank you so much for the help, that works perfectly and thank you for showing me both methods, that's very helpful and appreciated!
Posts made by randymills
-
RE: Set VERTEXCOLOR in PaintTool
-
Set VERTEXCOLOR in PaintTool
I'm working on a python script that will assign vertex color tags with random colors to each mesh in my object to prep my models for working in Substance Painter. I have a sample script that is getting me close to what I need, but I can't for the life of me figure out what I'm doing wrong with the c4d.DescID(c4d.DescLevel) setup. I continue to get the following error, which suggests the DescLevel is reading c4d.ID_CA_PAINT_TOOL_VERTEXCOLOR, c4d.DTYPE_VECTOR as an integer, even though I'm defining it as a vector (unless I'm misinterpreting this):
Traceback (most recent call last): File "scriptmanager", line 43, in <module> File "scriptmanager", line 22, in main TypeError: 'c4d.Vector' object cannot be interpreted as an integer
Current code sample (simplified but w/ test code included to show what I've tried already):
import c4d doc: c4d.documents.BaseDocument # The currently active document. op: c4d.BaseObject | None # The primary selected object in `doc`. Can be `None`. def main() -> None: if op is None: raise RuntimeError("No object selected") c4d.CallCommand(431000045) # Create Vertex Color Tag doc.SetAction(1021286) #Makes the paint tool active tool = doc.GetAction() tool = c4d.plugins.FindPlugin(tool, c4d.PLUGINTYPE_TOOL) if not tool: print("Vertex Paint tool not found!") return False # Set the vertex color parameter myVertexColor = c4d.Vector(0.0,1.0,0.0) # Green # myVertexColor = c4d.DescLevel(c4d.Vector(0.0,1.0,0.0)) # Green desc_level = c4d.DescLevel(c4d.ID_CA_PAINT_TOOL_VERTEXCOLOR, c4d.DTYPE_VECTOR, 0) # Debug: Verify the DescID print(f"DescID: {desc_level}") vertexColorSuccess = tool.SetParameter(desc_level, myVertexColor) if not vertexColorSuccess: print("Failed to set vertex color parameter!") return False # Debug: Verify the parameter was set current_value = tool.GetParameter(desc_level, c4d.DESCFLAGS_GET_0) print(f"Set color: {current_value}") # tool[c4d.ID_CA_PAINT_TOOL_VERTEXCOLOR]=myVertexColor # myVertexColorTag = c4d.DescID(c4d.ID_CA_PAINT_TOOL_VERTEXCOLOR, c4d.DTYPE_VECTOR, 0) # tool.SetParameter(myVertexColorTag, myVertexColor, c4d.DESCFLAGS_SET_0) c4d.CallButton(tool, c4d.ID_CA_PAINT_TOOL_APPLY_ALL) # Applies the color to all vertices c4d.EventAdd() if __name__ == '__main__': main()
Am I thinking about this all wrong...should I be accessing/setting the vertex color a different way?
-
RE: Encountered a possible error in the example code in the docs for AssetDataBasesInterface.FindRepository
Thanks Ferdinand and that does seem very plausible given that I am very new to type hinting in my code, and I have actually caught myself swapping the colon for the equals sign already. Learning from you guys every day though! I'm off to break some more sh!t! Thanks so much for your time, will let you know when I get stuck...
-
RE: Encountered a possible error in the example code in the docs for AssetDataBasesInterface.FindRepository
Ferdinand, I stand corrected and apologize for any confusion. Thank you for taking the time to explain that so thoroughly, very helpful! Having examples, like you provided in the documentation here, has been the ONLY way I've been able to navigate my way through the API. I'm quickly finding out the difference between what's included in the Python API vs. the C++ API and learning to work my way around my shortcomings as a coder, so I greatly appreciate your help and your time. After reading your response I have a much clearer understanding of this concept. Thank you!
It does seem that I made a mistake somewhere on my end, since I tried again this morning after reconnecting my custom databases in the Asset Browser and it is working as you described above. I'm not sure what happened yesterday to cause the "issubclass() arg 1 must be a class" error, but it is not reproduceable this morning, and changing the class in maxon.Cast back to "AssetRepositoryRef" now works. I'll continue testing and let you know if I come across this issue again, but I can't seem to reproduce it today and it's working as intended. Would resetting the databases in the Asset Browser make sense to you as to why it may have solved this issue on my end? Could I have stored something other than a subclass in memory somehow?
Again, thank you for your time!
-
Encountered a possible error in the example code in the docs for AssetDataBasesInterface.FindRepository
I have been working on a bit of code that versions up an asset automatically based on the timestamp of a master asset and I was having a really hard time figuring out how to properly assign the custom database to the new version. I was using the example for AssetDataBasesInterface.FindRepository found here https://developers.maxon.net/docs/py/2024_4_0a/modules/maxon_generated/frameworks/asset/interface/maxon.AssetDataBasesInterface.html#maxon.AssetDataBasesInterface.FindRepository, but I think there may be an error in the code.
I was consistently getting an issubclass error when running the example code:
url: maxon.Url = maxon.Url(r"/Volumes/database") obj: maxon.ObjectRef = maxon.AssetDataBasesInterface.FindRepository(url) if obj.IsNullValue(): raise RuntimeError(f"Could not establish repository for: {url}.") # Cast #obj to an AssetRepositoryRef. What #obj must be cast to depends on the repository #url # is representing. But all repositories are of type AssetRepositoryInterface, so a ref for that # will give access to all common asset repository methods. repo: maxon.AssetRepositoryRef = maxon.Cast(maxon.AssetRepositoryRef, obj) if repo.IsNullValue(): raise RuntimeError(f"Could not establish repository for: {url}.")
After reading a little more about issubclass() I figured out that I needed to define the class to Cast as maxon.AssetRepositoryInterface instead of maxon.AssetRepositoryRef and that seems to work perfectly.
The updated version looks like this and works for me:
url: maxon.Url = maxon.Url(r"/Volumes/database") obj: maxon.ObjectRef = maxon.AssetDataBasesInterface.FindRepository(url) if obj.IsNullValue(): raise RuntimeError(f"Could not establish repository for: {url}.") # Cast #obj to an AssetRepositoryRef. What #obj must be cast to depends on the repository #url # is representing. But all repositories are of type AssetRepositoryInterface, so a ref for that # will give access to all common asset repository methods. repo: maxon.AssetRepositoryRef = maxon.Cast(maxon.AssetRepositoryInterface, obj) if repo.IsNullValue(): raise RuntimeError(f"Could not establish repository for: {url}.")
Thought I'd post here in case anyone else is struggling with this as hard as I've been!
-
RE: TexBox CustomGUI for Python?
Was there any further investigation into this topic? We are trying to add a drag and drop field to our python dialog for textures from image assets in the asset browser...I can make a separate post, but scouring the forum first for relevant articles.