Dear Developers,
again I am having trouble with matrixes,
I pass a null (inside Axisnull are lots of polygons) to the join comand and get an object (not inserted jet) that I pass to a matrix manipulation definition to get the position in worldspace after that i place it into the hirachy.
I want the Axis of Axisnull ( parenmg ) to be my PolygonObject Axis
and inserted in the hirachy
I guess some trouble stems from not knowing where the returned object is in Space hence its only in memory ? but I wanted to insert the object after all the manipulation. This should be doable.
Hirachy dummy:
CADfilenull (masternull)
__|-Axisnull (join comand acts here)
__|-Axisnull (join comand acts here)
_|-CADfilenull subgroup
___|-Axisnull (join comand acts here)
___|-Axisnull (join comand acts here)
___|-Axisnull (join comand acts here)
___|-Axisnull (join comand acts here)
___|- ....
def movematrix(parentmg, op):
#GetUpMg() is not correct hence wrong parent, axis null is killed by this time, use parentmg !
mg = op.GetMg()
ml = op.GetMp()
ps = op.GetAllPoints()
#############################################
# trouble starts here - I gues this is all not necessary somehow
center = op.GetMp() # local center from op
center *= mg # Global Center
new_m = c4d.Matrix(parentmg) # Set the matrix including rotation from parent
new_m.off = center # overwrite the position from the object
loc_m = ~new_m * mg # multiply invers with original matrix
op.SetAllPoints([loc_m.Mul(p) for p in ps ])
op.SetMg(new_m)
op.Message(c4d.MSG_UPDATE)
# trouble end
#############################################
def JoinCommand(doc, op):
res = c4d.utils.SendModelingCommand(command = c4d.MCOMMAND_JOIN,
list = [op],
mode = c4d.MODELINGCOMMANDMODE_ALL,
doc = doc)
if c4d.GetC4DVersion() < 21000:
res[0].SetAbsPos(c4d.Vector()) #found in forum just in case
# Cheks if the command didn't failed
if res is False:
raise TypeError("return value of Join command is not valid")
elif res is True:
print ("Command successful. But no object.")
elif isinstance(res, list):
op.Remove() # <--- why is this needed somtimes ?
return res[0] # Returns the first item containing the object of the list. ??? GetClone() ???
def joinmanagment(n):
# n "Axis" null will be not alive in a few steps get everything we need from it
parent = n.GetUp()
parentmg = n.GetMg()
newobject = JoinCommand(doc, n) # combine the poly objects
if not newobject.IsAlive():
raise TypeError("Object is not alive.")
return False
newobject.SetName(str(parent.GetName()))
movematrix(parentmg, newobject)
newobject.InsertUnder(parent)
#dummy main for completeness
def main():
allachsen = [list of Nulls]
for n in allachsen:
secondcounter += 1
statusbar(null_counter, secondcounter)
if joinmanagment(n) == False:
break
kind regards
mogh