Override Transform Rotation API

Override Transform Rotation API

joseph_sarmiento
Participant Participant
868 Views
2 Replies
Message 1 of 3

Override Transform Rotation API

joseph_sarmiento
Participant
Participant

Please help me to modify my code. What I need is to change the rotation value not only one time.

 

I saw a code on youtube and I tried  to modified it according to my needs.



 

here is  my code snippet.

        public void SetRotation(Document document, ModelItemEnumerableCollection modelItems, Rotation rotation, string modelPath)
        {
            foreach (var item in modelItems)
            {

                var loc = item.BoundingBox().Center;

                var mb = new Vector3D(loc.X, loc.Y, loc.Z);
                var mo = new Vector3D(-loc.X, -loc.Y, -loc.Z);

                var transVec = Transform3D.CreateTranslation(mo);

                Autodesk.Navisworks.Api.Application.ActiveDocument.Models.OverridePermanentTransform(new List<ModelItem> { item }, transVec, true);

                var rt = new Rotation3D(new UnitVector3D(rotation.x, rotation.y, rotation.z), (((rotation.angle) * (Math.PI / 180)) / 2));
                var tr = new Transform3D(rt, mb);

                Autodesk.Navisworks.Api.Application.ActiveDocument.Models.OverridePermanentTransform(new List<ModelItem> { item }, new Transform3D(tr), true);
            }
        }

 

this works only one time when I run or click again my plugin the result is wrong.

because maybe there are wrong in the computation or matrix. 

 

Thank you!

0 Likes
Accepted solutions (1)
869 Views
2 Replies
Replies (2)
Message 2 of 3

arautio
Advocate
Advocate
Accepted solution

You are most likely adding transforms on top of previous transforms every time you run your code.

0 Likes
Message 3 of 3

joseph_sarmiento
Participant
Participant
Thank you it works.
0 Likes