Transform.ArrayData - Cannot apply indexing?

Programming and macros
Jordan Brown
Posts: 26
Joined: Wed Jul 21, 2021 3:20 pm
Answers: 0
x 6
x 2

Transform.ArrayData - Cannot apply indexing?

Unread post by Jordan Brown »

So I have a C# add-in that was originally built in VS2019. I recently upgraded to VS2022 and it is now reporting problems with Transform.ArrayData{}. It gives the following error:

Cannot apply indexing with [] to an expression of type 'object'
'.
This code seems to imply a casting issue, but casting does not seem to help. I can take the array data, copy it to another array, manipulate it, and then copy it back, but it seems convoluted.

Anyone know why this might be happening? And how to get it to work again?
image.png
User avatar
JSculley
Posts: 641
Joined: Tue May 04, 2021 7:28 am
Answers: 55
x 9
x 874

Re: Transform.ArrayData - Cannot apply indexing?

Unread post by JSculley »

What is to the left of Transform1 in the code above? Can you post the complete lines?
Jordan Brown
Posts: 26
Joined: Wed Jul 21, 2021 3:20 pm
Answers: 0
x 6
x 2

Re: Transform.ArrayData - Cannot apply indexing?

Unread post by Jordan Brown »

I have edited the original post to show the complete lines of code. Sorry it is so small, I can't seem to figure out how to make it bigger, these high res monitors have their drawbacks.
User avatar
AlexB
Posts: 498
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 28
x 266
x 444

Re: Transform.ArrayData - Cannot apply indexing?

Unread post by AlexB »

Just a shot in the dark, but you may have to create an intermediate line similar to:

Code: Select all

double[] t1ArrayData = (double[])Transform1.ArrayData
Then replace all instances of

Code: Select all

Transform1.ArrayData[n]
with

Code: Select all

t1ArrayData[n]
User avatar
bnemec
Posts: 1943
Joined: Tue Mar 09, 2021 9:22 am
Answers: 10
Location: Wisconsin USA
x 2542
x 1398

Re: Transform.ArrayData - Cannot apply indexing?

Unread post by bnemec »

AlexB wrote: Fri Jan 06, 2023 1:07 pm Just a shot in the dark, but you may have to create an intermediate line similar to:

Code: Select all

double[] t1ArrayData = (double[])Transform1.ArrayData
Then replace all instances of

Code: Select all

Transform1.ArrayData[n]
with

Code: Select all

t1ArrayData[n]
That is exactly what the help example shows.
User avatar
josh
Posts: 293
Joined: Thu Mar 11, 2021 1:05 pm
Answers: 16
x 22
x 500

Re: Transform.ArrayData - Cannot apply indexing?

Unread post by josh »

Just curious... What are you trying to do here? It's not often you need to do direct math with the individual elements of a transform...
Jordan Brown
Posts: 26
Joined: Wed Jul 21, 2021 3:20 pm
Answers: 0
x 6
x 2

Re: Transform.ArrayData - Cannot apply indexing?

Unread post by Jordan Brown »

AlexB wrote: Fri Jan 06, 2023 1:07 pm Just a shot in the dark, but you may have to create an intermediate line similar to:

Code: Select all

double[] t1ArrayData = (double[])Transform1.ArrayData
Then replace all instances of

Code: Select all

Transform1.ArrayData[n]
with

Code: Select all

t1ArrayData[n]
Agreed, looks like this is what it will have to be. I was hoping to avoid the work since it worked a few months ago. I guess solidworks is not the only software that can cause problems when upgrading.
Jordan Brown
Posts: 26
Joined: Wed Jul 21, 2021 3:20 pm
Answers: 0
x 6
x 2

Re: Transform.ArrayData - Cannot apply indexing?

Unread post by Jordan Brown »

josh wrote: Fri Jan 06, 2023 1:51 pm Just curious... What are you trying to do here? It's not often you need to do direct math with the individual elements of a transform...
The idea is to get the unit vector of the axis of a cylindrical face.

1. Get CylinderParams
2. Make transform
a. Values correspond to 0, 4, 8, 9, 10, 11, and 12 in a full transform
matrix
3. Transform to ASM space
4. Create unit vector from new transform

Looking back I could possibly have made the unit vector before transforming everything, but this way I get to transfer all of the surface data with a single transform to ASM space.

If anyone has a better way of doing things I am open to suggestions...
User avatar
josh
Posts: 293
Joined: Thu Mar 11, 2021 1:05 pm
Answers: 16
x 22
x 500

Re: Transform.ArrayData - Cannot apply indexing?

Unread post by josh »

I don't understand what the math is supposed to be doing... For an arbitrary transformation matrix there's nothing there that keeps you from trying to take the sqrt of a negative number, which of course returns an error.

Your cylinder params already give you a vector. Why not just multiply that vector by whatever transform using mathVector.MultiplyTransform?
Jordan Brown
Posts: 26
Joined: Wed Jul 21, 2021 3:20 pm
Answers: 0
x 6
x 2

Re: Transform.ArrayData - Cannot apply indexing?

Unread post by Jordan Brown »

My issue is that I need a vector that points in the same direction as the cylinder params, but that has a unit length of 1 (a normalized vector). Unless I am wrong, it is merely a questions of when to do the normalization, before or after the transform. Either way, I need to manipulate the values in the vector/matrix, unless the MathUtililty can do it for me and I am just missing it somewhere.

Doing the normalization math afterwards let's me keep the point and vector data all in one matrix and only run the transform once. My guess would be that this order of operations is quicker for the processor to calculate rather than transforming the original data and the unit vector separately (since I am doing thousands of these), but that is just a guess.
User avatar
josh
Posts: 293
Joined: Thu Mar 11, 2021 1:05 pm
Answers: 16
x 22
x 500

Re: Transform.ArrayData - Cannot apply indexing?

Unread post by josh »

I still don't see what you're doing with the direct math on the transform elements. You're taking the sqrt of an expression that could be negative.

.Normalize will normalize a MathVector.
Post Reply