Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. Be respectful, on topic and if you see a problem, Flag it.

If you would like to contact our Community Manager personally, feel free to send a private message or an email.

accessing one coordinate of a vector?

EvanReese
EvanReese Member, Mentor Posts: 3,059 PRO
I'm trying to use a triad manipulator to set 3 different length parameters (XY and Z coordinates). Since the base and offset of the triad are both simple vectors I'm not sure how to send the x value to the X length parameter. Is there a way to get one of the values out of a vector? Am I asking the right question? Manipulators in general are new to me too, so any info helps.
Evan Reese
The Onsherpa | Reach peak Onshape productivity
www.theonsherpa.com

Best Answers

  • MBartlett21
    MBartlett21 Member, OS Professional, Developers Posts: 2,064 ✭✭✭✭✭
    Answer ✓
    @Evan_Reese

    3d vectors in Onshape are just a simple array of three ValueWithUnits, meaning that you can get the x, y and z dimensions with vec[0], vec[1], and vec[2], respectively.
    mb - draftsman - also FS author: View FeatureScripts
    IR for AS/NZS 1100
  • jon_sorrells
    jon_sorrells Onshape Employees Posts: 52 image
    Answer ✓
    You can access the vector as an array to get the x, y, and z components.  Like myVector[0] to get the x component.
    The Transform feature uses a triad manipulator, you can take a look at the transformManipulatorChange method in transformCopy.fs in the standard library.  I've copied the relevant portion here:
            const offset = input[TRANSLATION].offset;
            output.dx = offset[0];
            output.dy = offset[1];
            output.dz = offset[2];
    You can also use the dot product, like dot(myVector, (vector(1, 0, 0))), which would get the x component of myVector.





Answers

  • MBartlett21
    MBartlett21 Member, OS Professional, Developers Posts: 2,064 ✭✭✭✭✭
    Answer ✓
    @Evan_Reese

    3d vectors in Onshape are just a simple array of three ValueWithUnits, meaning that you can get the x, y and z dimensions with vec[0], vec[1], and vec[2], respectively.
    mb - draftsman - also FS author: View FeatureScripts
    IR for AS/NZS 1100
  • jon_sorrells
    jon_sorrells Onshape Employees Posts: 52 image
    Answer ✓
    You can access the vector as an array to get the x, y, and z components.  Like myVector[0] to get the x component.
    The Transform feature uses a triad manipulator, you can take a look at the transformManipulatorChange method in transformCopy.fs in the standard library.  I've copied the relevant portion here:
            const offset = input[TRANSLATION].offset;
            output.dx = offset[0];
            output.dy = offset[1];
            output.dz = offset[2];
    You can also use the dot product, like dot(myVector, (vector(1, 0, 0))), which would get the x component of myVector.





  • EvanReese
    EvanReese Member, Mentor Posts: 3,059 PRO
    I'm really glad it's that simple. I thought that's what I'd tried but I must have not had it quite right. I've got it working now.
    Evan Reese
    The Onsherpa | Reach peak Onshape productivity
    www.theonsherpa.com