Page 1 of 1
Transform.ArrayData - Cannot apply indexing?
Posted: Fri Jan 06, 2023 11:35 am
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?
Re: Transform.ArrayData - Cannot apply indexing?
Posted: Fri Jan 06, 2023 11:44 am
by JSculley
What is to the left of Transform1 in the code above? Can you post the complete lines?
Re: Transform.ArrayData - Cannot apply indexing?
Posted: Fri Jan 06, 2023 11:57 am
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.
Re: Transform.ArrayData - Cannot apply indexing?
Posted: Fri Jan 06, 2023 1:07 pm
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
with
Re: Transform.ArrayData - Cannot apply indexing?
Posted: Fri Jan 06, 2023 1:19 pm
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
with
That is exactly what the help example shows.
Re: Transform.ArrayData - Cannot apply indexing?
Posted: Fri Jan 06, 2023 1:51 pm
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...
Re: Transform.ArrayData - Cannot apply indexing?
Posted: Fri Jan 06, 2023 2:08 pm
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
with
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.
Re: Transform.ArrayData - Cannot apply indexing?
Posted: Fri Jan 06, 2023 2:19 pm
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...
Re: Transform.ArrayData - Cannot apply indexing?
Posted: Fri Jan 06, 2023 2:39 pm
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?
Re: Transform.ArrayData - Cannot apply indexing?
Posted: Fri Jan 06, 2023 2:49 pm
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.
Re: Transform.ArrayData - Cannot apply indexing?
Posted: Fri Jan 06, 2023 3:01 pm
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.