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.

Flip Normal in Transform Using Mate Connector?

owen_sparksowen_sparks Member, Developers Posts: 2,660 PRO
Hi folks.
I'm after some help with flipping a normal in a transform.  I'm using either a sketch point or a MC as an input, and then the UIHint.OPPOSITE_DIRECTION driving definition.isFlipped

For the sketch point we have this code working just fine (thanks previous helpers):-
try silent //Build Transform as if target is Sketch Point
   {
     var skPlane = evOwnerSketchPlane(context, {
         "entity" : TargetPoints[i]
         });
                               
     skPlane.origin = evVertexPoint(context, {
          "vertex" : TargetPoints[i]
         });
                               
     if (definition.isFlipped)
          {
              skPlane.normal *= -1;
              skPlane.x *= -1;
          }
      skPlane.x = rotationAround(line(skPlane.origin, skPlane.normal), (-definition.rotation)).linear * skPlane.x;
      Mytransform  = toWorld(coordSystem(skPlane));
                               
      debug(context, "LoopCounter:- " ~ i);
      debug(context, "is a Sketch Vertex");
   }

Now I'd like to do the same thing for the MC version:-
Try silent //Build Transform as if target is Mate Connector
   {
      Mytransform  = toWorld(evMateConnector(context, {
         "mateConnector" : TargetPoints[i]       
         }));
                               
      if (definition.isFlipped)
         {
            //<> WHAT GOES HERE?
          }
                                   
      debug(context, "LoopCounter:- " ~ i);
      debug(context, "is a Mate Connector");
   }
Thanks,
Owen.

Business Systems and Configuration Controller
HWM-Water Ltd

Best Answers

  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    Answer ✓
    evMateConnector returns coordSystem, isn't it? And after it is evaluated it is the right moment to flip it's zAxis.
  • owen_sparksowen_sparks Member, Developers Posts: 2,660 PRO
    Answer ✓
    Ah-ha, you're right. 
    Eventually found this in the documentation:-
    So this works exactly as needed:-

    var cSys is CoordSystem = evMateConnector(context, {
             "mateConnector" : TargetPoints[i]       
              });
                                       
          if (definition.isFlipped)
             {
                cSys.zAxis*=-1;
             }
                                   
          Mytransform  = toWorld(cSys);

    Thanks for taking the time to help the neewbies :+1:
    Cheers,
    Owen S.


    Business Systems and Configuration Controller
    HWM-Water Ltd

Answers

  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    You should flip zAxis of coord system before constructing transform.
    cSys.zAxis*=-1;
  • owen_sparksowen_sparks Member, Developers Posts: 2,660 PRO
    Thanks for the help. 
    At the moment I don't even create a coordinate system, the transform is used as a parameter for the instantiator.
    var instantiator = newInstantiator(id + i + "instantiate");
                            
                                        //addInstance(instantiator, HeatsertVoidForM3x5_4mmx8mm::build, {  "transform" : toWorld(coordSystem(skPlane))} );
                                        const shapeInstance = addInstance(instantiator, imports[toString( definition.MiscSelected)], {  "transform" : Mytransform} );
                           
                            instantiate(context, instantiator);
    So as it stands I don't belive I have anything to flip?
    Owen S.

    Business Systems and Configuration Controller
    HWM-Water Ltd
  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    edited December 2019
    Anyway you pass some coord system to transform, its z axis should be flipped earlier
    You have coord sys here:
    {  "transform" : toWorld(coordSystem(skPlane))} );

  • owen_sparksowen_sparks Member, Developers Posts: 2,660 PRO
    Anyway you pass some coord system to transform, its z axis should be flipped earlier
    You have coord sys here:
    {  "transform" : toWorld(coordSystem(skPlane))} );


    Hi again.  Sorry to be a pain. I knew I should have posted the full code. :(:)   The coordsystem above is in the part of the code that accepts sketch points.  If the user selects a MC then that part of the code will never run and we go straight from evaluating the mate connector to instancing a part.  So in summary this is all we have to work with so far.:-

    Mytransform  = toWorld(evMateConnector(context, {
                                        "mateConnector" : TargetPoints[i]       
                                        }));

    var instantiator = newInstantiator(id + i + "instantiate");
                            
    const shapeInstance = addInstance(instantiator, imports[toString( definition.LoggerInputSelected)], {  "transform" : Mytransform} );
                           
    instantiate(context, instantiator);
    So I'm clueless as to how to achieve the desired flip.
    Owen S.


    Business Systems and Configuration Controller
    HWM-Water Ltd
  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    Answer ✓
    evMateConnector returns coordSystem, isn't it? And after it is evaluated it is the right moment to flip it's zAxis.
  • owen_sparksowen_sparks Member, Developers Posts: 2,660 PRO
    Answer ✓
    Ah-ha, you're right. 
    Eventually found this in the documentation:-
    So this works exactly as needed:-

    var cSys is CoordSystem = evMateConnector(context, {
             "mateConnector" : TargetPoints[i]       
              });
                                       
          if (definition.isFlipped)
             {
                cSys.zAxis*=-1;
             }
                                   
          Mytransform  = toWorld(cSys);

    Thanks for taking the time to help the neewbies :+1:
    Cheers,
    Owen S.


    Business Systems and Configuration Controller
    HWM-Water Ltd
Sign In or Register to comment.