[Closed] node.wirecolor on camera don't work
Hi, I hope this is the correct Forum for this Question.
I have a problem.
I want that everytime when a camera is made its wirecolor gets red, and the name changes.
This is the Problem while the name changes, the wirecolor is still the same. I don’t know where my Problem is, if I use it for a normal Geometric it works without problems.
The problematic code:
[...]
txt = "if (superclassof node == camera) then (
node = callbacks.notificationParam()
node.name = \"cam:\"
node.wirecolor = color 255 0 0
)
"
callbacks.addscript #nodeCreated txt \
id:#AssignMaterial persistent:false
[...]
I hope you can help
And by the way: Is there a easier method to work whit the callbacks, beside putting it in a String?
Do cameras have a wirecolor property at all? If I remember right, cameras and lights do not have that which would explain why your script isn’t working(i could be wrong though).
If I make something like:
$.wirecolor = color 255 0 0
the color of the camera changes to red in the viewport. So I think there should be something like this, so my new made camera gets red.
Hi,
Yes, cameras and lighs do have a wirecolor property, as proven by this snippet of code:
c=freecamera()
c.wirecolor=red
However, strangely you cannot change it while the node is being created:
fn callbacknodecreated=
(
obj = callbacks.notificationParam()
obj.wirecolor=red
if superclassof obj==camera then
(
print obj.name
obj.wirecolor=red
)
)
--callbacks.addscript #nodeCreated "callbacknodecreated()" id:#cameratest
/*
callbacks.show()
callbacks.removeScripts id:#cameratest
Note I have modified your code since there were a couple of errors, for example the word ‘node’ is a protected word.
J.
Yes, cameras and lighs do have a wirecolor property, as proven by this snippet of code:
I stand corrected.
Hi, how can i use that script?
I tried executing it in maxscript, but when i created a camera nothing changed.
Hi Nahuel,
The thing is, it doesn’t work. It works with other typed of objects, like geometry but for some reason it doesn’t work with cameras.
J.
The problem is not in the wirecolor property which can be freely set via MAXScript to anything.
The problem is that a camera gets its wirecolor set to a globally defined Custom Color (see the Color tab in Customize UI dialog) AFTER it has been created, and unfortunately, this happens AFTER the #nodeCreated callbacks has been called.
In fact, your callback is wrong because it tests the node variable’s superclass before the node variable is defined, but if you fix it and print the node.wirecolor, you will notice that each time you create a camera, it prints a RANDOM color (as any object would), which shows that the final (default blue) color of the camera is assigned AFTER the callback you registered.
I could not find a better callback to work around this (except using the #selectionSetChanged one which unfortunately works only with target cameras due to the fact that the selection switches between camera and target twice and thus triggers the callback after the final color has been set).
If I find anything else, I’ll let you know.
First, Thank you for the Answers.
I’m not sure, but is it possibly to change the “Global Custom Color”? So that I could set it to red and then set it back to its original color?
Unfortunately, the methods for accessing the colors (see colorMan interface) do not seem to support the custom colors (or at least I don’t know how to get the right ID to access these definitions) – they were made to work mostly with the standard color scheme elements and with icons. If there is a way to get and set these custom colors via the methods in the interface, I just don’t know it. If I figure it out, I will let you know (these methods were added to Max 4 before my days of documentation editing…)
There IS a way to work around that and I wrote some code to switch the Camera color back and forth, but it is quite hacky and requires a reload of the CLR definition file which is relatively slow and causes a flashing of the Max UI. So I don’t think it is the right approach.
A much faster workaround would be to register a callback of type #selectionSetChanged which changes the color of ALL cameras each time the selection changes. This is very fast and it does not matter whether you do it once or 100 times, as long as you really want all cameras to be red.
If you want the color to be set just once at creation time, you have two options – store some flag (in UserProps or AppData) that the color was already set once so your script would ignore the camera in the future thus allowing the user to change the color post-creation, or register a DotNet callback that changes the color of the newly created camera some milliseconds after the creation has finished. This will allow you to override whatever default color Max think it has to give it after the callback…
All these are quire advanced workarounds and I am not sure if they are worth it attempting, but I thought I would propose them just in case…
You can get/set the default camera wirecolor using GetUIColor <index_integer> and SetUIColor <index_integer> <point3>:
GetUIColor 30
[0.341176,0.470588,0.8]
SetUIColor 30 [1,0,0]
[1,0,0]
All color IDs are listed in MAXScript help topic : 3ds Max User Interface Colors
Note: Any changes using this method will not automatically get saved in your custom UI colors file.
Martijn
Nice one, totally missed it. Thanks!
I wonder who’s to blame it is not cross-linked from the colorMan topic…