How do I add Translation to an Alignment

How do I add Translation to an Alignment

huyc2GQZL
Contributor Contributor
1,995 Views
5 Replies
Message 1 of 6

How do I add Translation to an Alignment

huyc2GQZL
Contributor
Contributor

I just got into PowerInspect development
As shown below

huyc2GQZL_0-1678442541422.pnghuyc2GQZL_1-1678442651439.pnghuyc2GQZL_2-1678442657081.png

 

I want to automatically create a user-defined Alignment
Then create a Translation with default values
Now I don't know how to write my code next, can anyone help me?
Here is my current code snippet

power_inspect.Documents.Add();
ISequenceItem newAlignment = active_document.SequenceItems.AddAlignment(PWI_AlignmentType.pwi_alg_UserDefined);
newAlignment.Name = "G54";

 

Thanks!

 

Accepted solutions (1)
1,996 Views
5 Replies
Replies (5)
Message 2 of 6

dmitriy.dolgikh
Autodesk
Autodesk
Accepted solution

Here is a snipped that hopefully will help. It does more than you need, but it is easy to cut it down 🙂

// Set up a matrix to be used for the alignment
var mtb = pi.CreateLocalObject("PWIMathBox.MathToolbox");
var vector = pi.CreateLocalObject("PWIMathBox.Vector");
vector.SetCoordinates(0,0,1);
var matrix1 = pi.CreateLocalObject("PWIMathBox.Transform");
matrix1.CreateRotation(vector, 45);

var matrix2 = pi.CreateLocalObject("PWIMathBox.Transform");
vector.SetCoordinates(10,20,30);
matrix2.CreateTranslation(vector);
var matrix_final = mtb.MultiplyTransform(matrix1, matrix2);

// Create an alignment item with the matrix as transform
var alg = pi.ActiveDocument.SequenceItems.AddItem(pwi_alg_UserDefined_);
alg.ParameterTransformation.Matrix.Transform.CreateCopy(matrix_final);
alg.Refresh();

 

Thanks,

Dmitriy

0 Likes
Message 3 of 6

huyc2GQZL
Contributor
Contributor

Hi Dmitriy:

Thank you very much for your reply

I Can't run your code directly, probably because I'm using the latest PI2023 library
But it still helps me

Also ask, for beginners, PowerInspect secondary development is there more introductory materials to learn?

I now have the API Manual and Autodesk's Open Source PowerInspect project
But it's still hard to understand.
Please excuse my English, this is machine translation

Thank you

0 Likes
Message 4 of 6

dmitriy.dolgikh
Autodesk
Autodesk

Sorry, no additional learning content is available. Autodesk's Open Source PowerInspect project is probably the best source of examples. Feel free to post your questions here on forum though.

 

Thanks,

Dmitriy

0 Likes
Message 5 of 6

villanjohain
Explorer
Explorer

Thanks its work 

0 Likes
Message 6 of 6

huyc2GQZL
Contributor
Contributor

Thank you very much for your reply

0 Likes