Start a new topic

Traslation Values

Original Post by: Fri Sep 18 09:47:33 2015


Hi,


i want help for a python script that can copy the Transformation Matrix Value of Group Node to be copied to the external node which is child to the group node. Once it is copied the translation value of Group node should be removed also.

I'm attaching the screenshots of what I want to achieve.


Thanks in advance...


Original Post by: Tue Sep 22 04:51:49 2015


Thanks a lot it works same as i expected :)

Original Post by: ChrisRogers Mon Sep 21 16:44:15 2015


Another note, your import statements are not needed. You do not need to import anything from the api when running scripts inside of Creator. That is only needed when writing standalone scripts.


Hope all this helps!

Original Post by: ChrisRogers Mon Sep 21 16:42:47 2015


Ok, first let me point out some of the issues I see with this script.


The most glaring issue is the overall flow. It looks like you are trying to walk the hierarchy. You are doing so in two different ways. First you are calling mgWalk and telling it to call fltGroupN on every node in the hierarchy. However, when looking into the definition of fltGroupN, I see that you are getting the root of the hierarchy (the db) and then walking the children of that group node. You ignore the rec parameter in your function. That is the variable that holds the current nod to be processed. In effect, your script processes the each direct child of the database n times, where n is the number of nodes in the database. (or it would if you returned MG_TRUE from your walk function.)


I also see that you are getting an error. This error is due to the function returning failure. the mgGetCoord3d function returns four items, the first is a status. You should check this first to make sure everything is as expected. It just so happens that this is not the function you want to call anyway. Take a look FAQ in the OpenFlight API Reference entitled: How do I get the matrix (transformation) from a node?


I went ahead and modified your script and added some comments. It does what you asked for, but I took the liberty of moving all xforms from the parent to the child rather than just the translation. If this is not what you are looking for, you can test the xform as you examine them and decide what to move using mgGetXformType


def fltGroupN(db, parent, rec, i):

if(mgGetCode(rec) == fltGroup): # These tests insure we

testXref = mgGetChild (rec) # only apply to groups

if (mgGetCode (testXref) == fltXref): # that are above Xrefs

if (mgHasXform (rec)):

xformList = [] # we shouldn't modify the

xForm = mgGetXform (rec) # xform as we are looping

while (xForm != None): # because it will change

xformList.append (xForm) # our loop, instead we

xForm = mgGetNext (xForm) # need to push into a list

for xfrm in xformList:

mgDetach (xfrm) # then we simply move all

mgAppend(testXref, xfrm) # xforms in our list

return MG_TRUE


db = mgGetCurrentDb()

mgWalk (db, fltGroupN, None, None, MWALK_NOREADONLY)

Original Post by: Mon Sep 21 11:24:04 2015


Hi,


I got it working with the following script I wrote but there are few issues I'm facing. Can somebody please correct the script and help me out!!!


import sys

import decimal

from mgapilib import *


def fltGroupN(db, parent, rec, i):

db = mgGetCurrentDb()

a=mgGetChild(db)

ac=mgCountChild(db)

b=mgGetChild(a)

ab=mgCountChild(a)

for k in range(0,ac):

if(mgGetCode(a)== fltGroup):

Groupname = mgGetName(a)

tDelta = mgGetCoord3d (a,fltXmTranslateDelta)

gTrans = mgNewRec (fltXmTranslate)

mgSetCoord3d (gTrans, fltXmTranslateDelta, tDelta[1], tDelta[2], tDelta[3])

xform=mgGetXform(a)

mgAttach(b,gTrans)

mgDelete(xform)

a=mgGetNext(a)

mgWalk (db, fltGroupN, None, None, MWALK_MASTER | MWALK_MASTERALL)


Here the issues i'm facing are :


1) Only the first external node is getting the values, if its more than one all values of other group nodes are also coming in to the external node which is in first position.


2) This error is appearing :


E: Traceback (most recent call last):

E: File "<string>", line 1, in <module>

E: File "<string>", line 18, in fltGroupN

E: TypeError: in method 'mgSetCoord3d', argument 3 of type 'double'

Login to post a comment