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

HuguesLessardWRI
HuguesLessardWRI Member Posts: 14 ✭✭
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

  • EvanReese
    EvanReese Member, Mentor Posts: 3,102 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
    The Onsherpa | Reach peak Onshape productivity
    www.theonsherpa.com
  • NeilCooke
    NeilCooke Moderator, Onshape Employees Posts: 6,126 image
    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, EMEA

Answers

  • NeilCooke
    NeilCooke Moderator, Onshape Employees Posts: 6,126 image
    evMateConnector returns a CoordSystem which has values as shown here: 
    https://cad.onshape.com/FsDoc/library.html#CoordSystem
    Senior Director, Technical Services, EMEA
  • EvanReese
    EvanReese Member, Mentor Posts: 3,102 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
    The Onsherpa | Reach peak Onshape productivity
    www.theonsherpa.com
  • HuguesLessardWRI
    HuguesLessardWRI Member Posts: 14 ✭✭
    @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

  • NeilCooke
    NeilCooke Moderator, Onshape Employees Posts: 6,126 image
    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, EMEA
  • HuguesLessardWRI
    HuguesLessardWRI Member Posts: 14 ✭✭
    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