[Closed] Script loading order?
So, I have a scripted custom attribute on an object in my scene. For some reason, I have to load my scene twice to make it work. The first time, it comes up complaining about the missing “plugin”, but somewhere during that load, the scripted plugin does its thing and is happily stored in memory. Then when I reload my scene, the custom attribute is exactly where it belongs and I get no errors.
How the hell do I fix this?
hi,
Where is your script stored?
could you please post the exact error message?
Bettr yet can you post the offending file. CA’s are really no different then scripted plugins but I have never seen one complain that the plugin is not loaded.
probably it is becouse the order of variables declared in the script. (look into listener for errors )
in help look for declare and assign variabels
and scope of variables
(sorry I can not help more but I am not a scripter so…(but when I had problem like U describe it was this global local variables and stuff) )
I think I figured out what’s happening…
I’m referencing a material inside the parameters of the custom attribute. I’m getting the impression that the material isn’t getting loaded when the custom attribute is, thus it’s throwing an error and generally collapsing under the weight of its own horribleness.
I’d post the rig, but I don’t have much room for attachments, and I don’t actually have my own site to put it up on, so unless there’s a really good and free place to upload this, I’m at a loss.
Basically, I’m using a custom attribute to hold a reference to a material whose diffuse value is being driven by the length of the spline (to which the CA is attached). The CA also has the three colors that make up safe, warning, and danger colors, since I don’t want people to stretch the spline to far.
attributes stretchWarning
(
parameters main rollout:params
(
safeColor type:#color ui:safe default:(color 0 150 0 255)
warningColor type:#color ui:warning default:(color 255 255 0 255)
dangerColor type:#color ui:danger default:(color 150 0 0 255)
offset type:#float ui:stretchOffset default:0
dialMat type:#material ui:mat material:($h_spineStretchWarning.material.materialList[2])
)
rollout params "Stretch Warning"
(
colorpicker safe "Safe color"
colorpicker warning "Warning Color"
colorpicker danger "Danger Color"
progressBar stretchOffset color:safe.color
materialButton mat material:($h_spineStretchWarning.material.materialList[2])
fn colorInterp color0 color1 p =
(
undo off
(
newColor = Color 0 0 0 255
newColor.r = floor ((color0.r * (1 - p)) + (color1.r * p))
newColor.g = floor ((color0.g * (1 - p)) + (color1.g * p))
newColor.b = floor ((color0.b * (1 - p)) + (color1.b * p))
return newColor
)
)
fn update =
(
undo off
(
local currentLength = curveLength $h_spineSpline 1
local diffLen = abs (currentLength - 55.5296)
local diffRatio = diffLen / 55.5296
local stretchRatio = diffRatio / 0.1
if stretchRatio > 1 do stretchRatio = 1
local finalColor = case of
(
(stretchRatio < 0.5): colorInterp safe.color warning.color (stretchRatio / 0.5)
(stretchRatio > 0.5): colorInterp warning.color danger.color ((stretchRatio - 0.5) / 0.5)
)
mat.material.diffuse = finalColor
stretchOffset.color = finalColor
stretchOffset.value = ceil (100 * stretchRatio)
)
)
)
)
This is the first time I’ve gone to these lengths for character rigging, and thus my first scratch-written CA, so I expect this to look kinda ugly to anyone with more experience. Also, my progress bar doesn’t work, but it’s just there for another visual indicator and I can live without it.
I ran into a similar problem with custom attributes.
denisT illustrated to me that the custom attribute rollout is not created until you call the line ‘max modify mode’.
myBox = box()
customAttributes = attributes objectData
(
rollout paramsRollout "BkgWrkr CAs"
(
checkbutton lockCharCk "xxxxx" checked:false pos:[8,45] width:145
checkbutton lockBipCk "xxxx" checked:false pos:[8,115] width:145
)
parameters main rollout:paramsRollout
(
tinyCharIDlock type:#boolean ui:lockCharCk default:false
tinyBipIDlock type:#boolean ui:lockBipCk default:false
)
)
custAttributes.add myBox customAttributes
max modify mode -- now the rollout was created the first time
At that point the custom attribute is created and you can access the CAs with the dot syntax (example: myBox.objectData.paramsRollout.lockCharCk.state)
Perhaps you are trying to access the CAs before they are created? This would throw an error similar to “Runtime error: Plug-in not active, unable to access plug-in local or parameter: ____ “.
Here’s the thread I’m referencing. Hope this helps.