Transform.ArrayData - Cannot apply indexing?
-
- Posts: 26
- Joined: Wed Jul 21, 2021 3:20 pm
- x 6
- x 2
Transform.ArrayData - Cannot apply indexing?
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?
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?
What is to the left of Transform1 in the code above? Can you post the complete lines?
-
- Posts: 26
- Joined: Wed Jul 21, 2021 3:20 pm
- x 6
- x 2
Re: Transform.ArrayData - Cannot apply indexing?
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?
Just a shot in the dark, but you may have to create an intermediate line similar to:
Then replace all instances of with
Code: Select all
double[] t1ArrayData = (double[])Transform1.ArrayData
Code: Select all
Transform1.ArrayData[n]
Code: Select all
t1ArrayData[n]
Re: Transform.ArrayData - Cannot apply indexing?
That is exactly what the help example shows.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:
Then replace all instances ofCode: Select all
double[] t1ArrayData = (double[])Transform1.ArrayData
withCode: Select all
Transform1.ArrayData[n]
Code: Select all
t1ArrayData[n]
Re: Transform.ArrayData - Cannot apply indexing?
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...
-
- Posts: 26
- Joined: Wed Jul 21, 2021 3:20 pm
- x 6
- x 2
Re: Transform.ArrayData - Cannot apply indexing?
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.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:
Then replace all instances ofCode: Select all
double[] t1ArrayData = (double[])Transform1.ArrayData
withCode: Select all
Transform1.ArrayData[n]
Code: Select all
t1ArrayData[n]
-
- Posts: 26
- Joined: Wed Jul 21, 2021 3:20 pm
- x 6
- x 2
Re: Transform.ArrayData - Cannot apply indexing?
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?
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?
Your cylinder params already give you a vector. Why not just multiply that vector by whatever transform using mathVector.MultiplyTransform?
-
- Posts: 26
- Joined: Wed Jul 21, 2021 3:20 pm
- x 6
- x 2
Re: Transform.ArrayData - Cannot apply indexing?
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.
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?
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.
.Normalize will normalize a MathVector.