[Closed] create objects with default properties
How we can create an object with default settings, not current settings in the scene. for example when I want to create a point helper in cross form, I have to override all other settings like box and axistripod.
Looking at the source code for the point helper object, I can see the ADesk developer who wrote it did not add the P_RESET_DEFAULT flag to its parameter block entries, which means all settings will be sticky upon creation.
In the SDK you could just iterate through the pblock of your newly created point and set each entry to its default value, but I don’t think there’s a way to access those default pblock values with maxscript. Maybe there’s a clever way using C#? I’m not sure.
Doesn’t seem to work. Or maybe these defaults are overwritten until the next max session
delete helpers
pt = point()
g = (dotNetClass "Autodesk.Max.GlobalInterface").Instance
pb2 = (g.COREInterface.GetINodeByHandle pt.inode.handle).objectref.GetParamBlock 0
for id=0 to pb2.numparams - 1 do (
pdef = pb2.getparamdef id
pb2.setValue pdef.id g.COREInterface.Time pdef.def.f 0
--pb2.Reset pdef.id -1 true true
)
pb2.ResetAll true true
fn createDeafultPointHelper = (
local pt = Point()
local g = (dotNetClass "Autodesk.Max.GlobalInterface").Instance
local pb2 = (g.COREInterface.GetINodeByHandle pt.inode.handle).objectref.GetParamBlock 0
local props = getpropnames pt
local types = (pb2.getparamdef 0).Type
for i=0 to pb2.NumParams-1 do (
local pdef = pb2.getparamdef i
case pdef.Type of (
(types.Bool2): setProperty pt props[i+1] (pdef.def.i > 0)
default: setProperty pt props[i+1] pdef.def.f
)
)
pt
)
Nice! it’s work, is it possible to use it for other objects like lights and cameras? I’m thinking to change the code to construct the object at creation time, not modifying after create.
fn createDeafultPointHelper = (
local g = (dotNetClass "Autodesk.Max.GlobalInterface").Instance
local sclass_id = (dotnetclass "Autodesk.Max.Sclass_id").Helper -- point.superClassID
local class_id = g.class_id.create 8211 0 asdotnetobject:true -- point.classID
local pt = g.COREInterface.CreateInstance sclass_id class_id
local pb2 = pt.GetParamBlock 0
local types = (pb2.getparamdef 0).Type
for i=0 to pb2.NumParams-1 do (
local pdef = pb2.getparamdef i
case pdef.Type of (
(types.Bool2): pb2.SetValue pdef.id g.COREInterface.Time (dotNetObject "system.int32" pdef.def.i) 0
default: pb2.SetValue pdef.id g.COREInterface.Time pdef.def.f 0
)
)
_node = g.coreinterface.createobjectnode pt
getnodebyname _node.name
)
Cool!, this encourage me to know more about SDK. what about MaxPlus? do you think we can use it?
I never thought of using python in max as long as .Net is available. Can’t see any real benefits.
I’d try to create an instance with specified sclass_id & class_id and then iterate on all available paramBlocks.
Maybe someone experienced in c++ SDK can help us with classes that has zero paramBlocks to set? How can we create class instance with default parameters in that case?
(
fn createDeafultNode class = (
local g = (dotNetClass "Autodesk.Max.GlobalInterface").Instance
local sclass_id = (dotnetclass "Autodesk.Max.Sclass_id").toObject (dotnetclass "Autodesk.Max.Sclass_id") class.superClassID
local class_id = g.class_id.create class.classID[1] class.classID[2] asdotnetobject:true
global obj = g.COREInterface.CreateInstance sclass_id class_id
if obj.NumParamBlocks > 0 then (
for i = 0 to obj.NumParamBlocks-1 do
(
local pb2 = obj.GetParamBlock i
local types = (pb2.getparamdef 0).Type
for i=0 to pb2.NumParams-1 do
(
local pdef = pb2.getparamdef i
case pdef.Type of
(
(types.Bool2): pb2.SetValue pdef.id g.COREInterface.Time (dotNetObject "system.int32" pdef.def.i) 0
default: pb2.SetValue pdef.id g.COREInterface.Time pdef.def.f 0
)
)
)
) else format "% has 0 paramBlocks :(
" class
_node = g.coreinterface.createobjectnode obj
getnodebyname _node.name
)
gc()
delete objects
pos = [0,0,0]
for class in GeometryClass.classes where class.Creatable do (
try
(
h = createDeafultNode class
h.pos = pos
pos += [10,0,0]
) catch ( format "Failed to create: %
" class )
)
redrawViews()
)