Override Transform Rotation API

Override Transform Rotation API

joseph_sarmiento
Participant Participant
1,223 Views
3 Replies
Message 1 of 4

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!

Accepted solutions (1)
1,224 Views
3 Replies
Replies (3)
Message 2 of 4

arautio
Advocate
Advocate
Accepted solution

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

Message 3 of 4

joseph_sarmiento
Participant
Participant
Thank you it works.
Message 4 of 4

mikhail_khrushchev
Contributor
Contributor

Just to let you guys know - this topic is a reference answer for such questions in Microsoft AI, 

0 Likes