Hello,
I have an oven with 4 drawers,
the upmost drawer has a reference frame which I want to copy and move to the other drawer and the same drawer by an offset.
The oven is the component and has 4 links/joints, 1 for each drawer.
The world coordinate system is like
^ z
x |
\|
<---|
y
All the drawers coordinate systems are like
^ x
|
|
<---|
y \
\
z
I have a script thats responsible for moving the frames which is placed at the behaviour of the component (oven)
from vcScript import *
import vcMatrix
class Offset(object):
def __init__(self, x, y, z, ):
self.X = x
self.Y = y
self.Z = z
def printMe(self):
print("X: "+ str(self.X) + "; Y: " + str(self.Y) + "; Z: " + str(self.Z))
def createAndTranslateFrame(referenceFrameName, targetFrameName, offset, translate_rel=False, rootFeature="Root", sub_node_name=None):
'''
Creates new frames with an offset relative to a reference frame
'referenceFrameName' : The name of the frame to which the new frames are offset
'targetFrameName' : The root name of new frame (the x,y and z position is added in the result)
'offset' : The translation matrix with x, y, z coordinates (beware: relative to the sub_node coordinate system)
'translate_rel' : True: translates along the frame axis itself, False: translates along the parent coordinates
'rootFeature" : The feature to which to add the new frames
'sub_node_name' : (string) the name of the components subnode where to add the newly created frame
'''
if rootFeature is None:
targetFeature=_comp
else:
targetFeature = _comp.findFeature(rootFeature)
if targetFeature is not None:
rootFrame = _comp.findFeature(referenceFrameName)
if rootFrame is not None:
# prevent multiple creation
if _comp.findFeature(targetFrameName) is None:
if (sub_node_name is not None):
node=_comp.findNode(sub_node_name)
targetFeature = node.getFeature(rootFeature)
print("targetfeature is: " + targetFeature.Name + " in Node: " + node.Name)
new_frame = targetFeature.createFeature( VC_FRAME, targetFrameName)
posmat = rootFrame.PositionMatrix
new_frame.PositionMatrix = posmat
print("before")
printMatrix(posmat)
print("offset")
offset.printMe()
if translate_rel:
posmat.translateRel(offset.X,offset.Y,offset.Z)
else:
posmat.translateAbs(offset.X,offset.Y,offset.Z)
print("after")
printMatrix(posmat)
print("created feature '" +targetFrameName+"' in feature '" + targetFeature.Name +"'")
else:
print("feature '"+targetFrameName+"' already exists." )
else:
print("could not find reference frame: " + referenceFrameName)
else:
print("could not find root feature: " + rootFeature)
_comp = getComponent()
#############################################
print("creating frames for circuit board ")
_distanceZ = -175
_distanceY = 500
_rootFeature="Root"
_rootFrameNames = ["RefFrame_PlatineVorn", "RefFrame_PlatineHinten"]
for rootFrameRoot in _rootFrameNames:
print(rootFrameRoot)
for drawer in range(1,5):
newFrameName = rootFrameRoot[3:] +"_D" + str(drawer)
subNode = "Drawer"+str(drawer)
print(subNode)
for yPos in range (2):
finalName = newFrameName+"_"+str(yPos+1)
print(finalName)
offset = Offset(0,_distanceY*yPos,_distanceZ*(drawer-1) )
createAndTranslateFrame(rootFrameRoot, finalName,offset, True ,_rootFeature,subNode )
_comp.rebuild()
I used it 4 times with offset (x: 0,y: _distanceYyPos,z: _distanceZ(drawer-1))
- assigning the position matrix of the new frame BEFORE translating the frame in RELATIVE (drawer) coordinate system
- result look: x moved by 0 (expected +175), y moved by 0 (expected +500), z moved by -175 (expected 0)
- result measured: x: -0.6 (expected +175), y: +0.6 (expected +500), z: -175.6 (expected 0)
- result matrix: x: -174.6 mm (expected +175), y: +500mm (expected +500), z: 0 (expected 0)
- expected: x moved in -z, y correct, z moved in x
- assigning the position matrix of the new frame BEFORE translating the frame in RELATIVE (drawer) coordinate system
- result look: x moved by 0 (expected +175), y moved by 0 (expected +500), z moved by -175 (expected 0)
- result measured: x: -0.6 (expected +175), y: +0.6 (expected +500), z: -175.6 (expected 0)
- result matrix: x: -174.6 mm (expected +175), y: +500mm (expected +500), z: 0 (expected 0)
- expected: x moved in -z, y correct, z moved in x
- assigning the position matrix of the new frame BEFORE translating the frame in ABSOLUTE (world/global) coordinate system
- result look: x moved by 0 (expected 0), y moved by 0 (expected +500), z moved by -175 (expected -175)
- result measured: x: 0.6 (expected 0), y: 0.6 (expected +500), z: -175.6 (expected -175)
- result matrix: x: 0 mm (expected 0), y: +500mm (expected +500), z: -175 (expected -175)
- expected: x correct, y correct, z correct
- assigning the position matrix of the new frame AFTER translating the frame in ABSOLUTE (world/global) coordinate system
- result look: x moved by +175 (expected 0), y moved by +500 (expected +500), z moved by -175 (expected -175)
- result measured: x: 174.7 (expected 0), y: +500.9 (expected +500), z: 174.7 (expected -175)
- result matrix: x: 0 mm (expected 0), y: +500mm (expected +500), z: -175 (expected -175)
- expected: x correct, y correct, z correct
and 4 times with offset (x: _distanceZ*(drawer-1),y: _distanceY*yPos,z: 0)
- assigning the position matrix of the new frame BEFORE translating the frame in RELATIVE (drawer) coordinate system
- result look: x moved by 0 (expected), y moved by 0, z moved by x value given (expected)
- result measured: x: -0.6 (target0), y: +0.6 (target +500), z: -175.6 (target -175)
- result matrix: x: 0 mm (target 0), y: +500mm (expected), z: +175 (traget -175)
- expected: xyz correct (Global)
- assigning the position matrix of the new frame AFTER translating the frame in RELATIVE (drawer) coordinate system
- result look: x moved by x value given, y correct (expected), z moved by x value given (expected)
- result measured: x: -175.3 (target0), y: +500.3 (target +500), z: -174.7 (target -175)
- result matrix: x: -0.9 mm (target 0), y: +500mm (expected), z: +175 (traget -175)
- expected: xyz correct (Global)
- assigning the position matrix of the new frame BEFORE translating the frame in ABSOLUTE (world/global) coordinate system
- result look: x moved by 0 (expected -175), y moved by 0 (expected +500), z moved by -175 (expected 0)
- result measured: x: 0.6 (expected -175), y: 0.6 (expected +500), z: -175.6 (expected 0)
- result matrix: x: -174.6 mm (expected -175), y: +500mm (expected +500), z: 0 (expected 0)
- expected: x correct, y correct, z correct
- assigning the position matrix of the new frame AFTER translating the frame in ABSOLUTE (world/global) coordinate system
- result look: x moved by 0 (expected -175), y moved by +500 (expected +500), z moved by -350 (expected 0)
- result measured: x: 0.3 (expected -175), y: +500.9 (expected +500), z: -349.7 (expected 0)
- result matrix: x: -174.6 mm (expected -175), y: +500mm (expected +500), z: 0 (expected 0)
- expected: x correct, y correct, z correct
where none gave the expected result.
Sooo…
- What do I have to change to get the expected result?
- Why is it that assigning a position matrix to an object and then changing/moving it leads to different results then chaning a position matrix and then assigning it to an object?
I added some of the result files (txt) where I wrote down what I expected and what the result was with reduced log files.
I also added the oven (vcmx) I am working with including the scripts.
Hope you can help me. Thank in advance.
translateAbs - assignment of posmat after change (wrong offset).txt (797 Bytes)
translateAbs - assignment of posmat before change.txt (786 Bytes)
translateRel - assignment of posmat before change (correct offset).txt (728 Bytes)
translateRel - assignment of posmat after change (correct offset).txt (764 Bytes)
test_Oven.vcmx (5.6 MB)