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.

Options

How do you get individual axes from a mate connector in featurescript?

HuguesLessardWRIHuguesLessardWRI Member Posts: 14 PRO
As part of my featurescript, I would need to rotate a mate connector around one of its axis to reorient it. For instance, how do I get the vector representing the X-axis of a mate connector? I have used the evMateConnector, but I do not see how to extract only one of the vector.
Hugues Lessard
Ingénieur de produits / Product Engineer
Waste Robotics Inc. / www.wasterobotic.com

Best Answers

  • Options
    Evan_ReeseEvan_Reese Member Posts: 2,066 PRO
    edited December 2019 Answer ✓
    @HuguesLessardWRI
    to add on to Neil's answer. evMateConnector gets you the CoordSystem, which is a map that contains the origin, zAxis, and xAxis. To get at the stuff inside a map, you use dot notation and the name of the thing you want from the map. I did something similar recently and it looked like this:
    <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var myMateConnector = definition.myMateConnector;
    
    </div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var mateCoord = evMateConnector(context, {
    
    </div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "mateConnector" : myMateConnector
    
    </div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });
    
    </div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var origin = mateCoord.origin;</div><div>
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var zDirection = mateCoord.zAxis;</div><div>
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var xDirection = mateCoord.xAxis;</div><div>
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var yDirection = yAxis(mateCoord);</div>
    Evan Reese / Principal and Industrial Designer with Ovyl
    Website: ovyl.io
  • Options
    NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,406
    Answer ✓
    This will do it:
        precondition
        {
            annotation { "Name" : "Mate Connector", "Filter" : BodyType.MATE_CONNECTOR, "MaxNumberOfPicks" : 1 }
            definition.mc is Query;
            
            annotation { "Name" : "Angle" }
            isAngle(definition.angle, ANGLE_360_BOUNDS);
        }
        {
            var mc = evMateConnector(context, { "mateConnector" : definition.mc });
    
            opTransform(context, id + "transform1", {
                        "bodies" : qOwnerBody(definition.mc),
                        "transform" : rotationAround(line(mc.origin, mc.xAxis), definition.angle) });
        });

    Senior Director, Technical Services, EMEAI

Answers

  • Options
    NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,406
    evMateConnector returns a CoordSystem which has values as shown here: 
    https://cad.onshape.com/FsDoc/library.html#CoordSystem
    Senior Director, Technical Services, EMEAI
  • Options
    Evan_ReeseEvan_Reese Member Posts: 2,066 PRO
    edited December 2019 Answer ✓
    @HuguesLessardWRI
    to add on to Neil's answer. evMateConnector gets you the CoordSystem, which is a map that contains the origin, zAxis, and xAxis. To get at the stuff inside a map, you use dot notation and the name of the thing you want from the map. I did something similar recently and it looked like this:
    <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var myMateConnector = definition.myMateConnector;
    
    </div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var mateCoord = evMateConnector(context, {
    
    </div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "mateConnector" : myMateConnector
    
    </div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });
    
    </div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var origin = mateCoord.origin;</div><div>
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var zDirection = mateCoord.zAxis;</div><div>
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var xDirection = mateCoord.xAxis;</div><div>
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var yDirection = yAxis(mateCoord);</div>
    Evan Reese / Principal and Industrial Designer with Ovyl
    Website: ovyl.io
  • Options
    HuguesLessardWRIHuguesLessardWRI Member Posts: 14 PRO
    @NeilCooke, I understand about the evMateConnector and then I might be using the wrong way around to get what I need. Do you have any hint for me on how I could "rotate" the mate connector around it's X-axis. I first thought I would get the vector representing the X-axis itself and transform the mate connector with opTransform using this vector as the "line" argument for the opTransform. Again, there might be a more efficient or elegant way to do it. I am still a complete noob in FS coding so any hint would be appreciated.
    Hugues Lessard
    Ingénieur de produits / Product Engineer
    Waste Robotics Inc. / www.wasterobotic.com

  • Options
    NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,406
    Answer ✓
    This will do it:
        precondition
        {
            annotation { "Name" : "Mate Connector", "Filter" : BodyType.MATE_CONNECTOR, "MaxNumberOfPicks" : 1 }
            definition.mc is Query;
            
            annotation { "Name" : "Angle" }
            isAngle(definition.angle, ANGLE_360_BOUNDS);
        }
        {
            var mc = evMateConnector(context, { "mateConnector" : definition.mc });
    
            opTransform(context, id + "transform1", {
                        "bodies" : qOwnerBody(definition.mc),
                        "transform" : rotationAround(line(mc.origin, mc.xAxis), definition.angle) });
        });

    Senior Director, Technical Services, EMEAI
  • Options
    HuguesLessardWRIHuguesLessardWRI Member Posts: 14 PRO
    Thank you @NeilCooke and @Evan_Reese. That was exactly what I was looking for
    Hugues Lessard
    Ingénieur de produits / Product Engineer
    Waste Robotics Inc. / www.wasterobotic.com

Sign In or Register to comment.