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.

Transform Help Request

owen_sparksowen_sparks Member, Developers Posts: 2,660 PRO
edited April 2019 in FeatureScript
Hi folks.

Another newbie FS request.  Please can I have some help with a transform?  I'll admit I'm finding the "help" hard to deal with.  It's a bit like Microsoft's help in that you need to be proficient in the subject to understand the help in which case you wouldn't be reading it in the first place...  Actually that's a bit unkind, if you think of it as a technical reference for looking up parameters then it fits that use case well but if you're a newbie it's a whole different story.  I've got this far mostly with help from OS staff and helpful forum users. (Thanks for that BTW.)

Background:-
Feature is a part of my company specific standard content widget.

Desired functionality is to select a sketch point or mate connector and the feature will derive in a desired part and optionally create the appropriate void for it to fit into.  In this example we're using a type of bolt often used in furniture making. 


We have a configurable PS to build the bolt for us, and a solid model of the void we require for that series of parts. 


The void is modeled in a separate PS around the origin.
By controlling where this "void part" is placed we can allow the bolt to be positioned on the surface of the target part or to have it recessed such that it is flush with the surface.








It's this additional "flush" transform I'm stuck on, the rest is working as intended.  I have an initial transform to take the part from the source studio and move it to the target sketch point or MC. 

 try silent //Build Transform as if target is Mate Connector
                            {
                                transform  = toWorld(evMateConnector(context, {
                                    "mateConnector" : TargetPoints[i]       
                                    }));
                               
                                if (definition.isFlipped)
                                            {
                                               
                                            }
                                   
                                debug(context, "LoopCounter:- " ~ i);
                                debug(context, "is a Mate Connector");
                            }              
                           
                            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;
                                            }
                               
                                transform  = toWorld(coordSystem(skPlane));
                               
                                debug(context, "LoopCounter:- " ~ i);
                                debug(context, "is a Sketch Vertex");
                            }

Later:-

//Add void if selected<br>                        if (definition.AddConnectorBoltVoid)<br>                        {<br>                            const instantiatorVoid = newInstantiator(id + i + "instantiateVoid");<br>                            addInstance(instantiatorVoid, ConnectorBoltVoid2::build, {  "transform" : transform} );<br>                <br>                            instantiate(context, instantiatorVoid);<br>                    <br>                                //Boolean remove Void from TargetPart<br>                    <br>                                opBoolean(context, id + i + "booleanVoid", {<br>                                "tools" : qCreatedBy(id + i + "instantiateVoid", EntityType.BODY),<br>                                "targets" : definition.TargetPart,<br>                                "operationType" : BooleanOperationType.SUBTRACTION<br>                                });  <br>                        }<br>                        
So my question is how do I apply an additional transform to my part before the boolean?  I have a variable defined but I'm at a loss as to what to do with it. 

var FlushTransformDistance is ValueWithUnits = 2.25*millimeter;
I understand we can perform multiple transforms by multiplying them together, and we can build one with a vector but that's about it.  How to build this?  How do we have it apply to local space?   

Have tried for a while and am at tearing hair out stage so am asking here before I break something expensive...

Thanks all,

Owen S.

Business Systems and Configuration Controller
HWM-Water Ltd
Tagged:

Best Answers

  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    edited April 2019 Answer ✓
    the general idea is if you need some additional transform (the moovement of the tool body) you can make it before the main transform and the resulting transform would be a composition of 2, in OS it wil be a product of 2 transforms:
    if (definition.AddConnectorBoltVoid)
    {
    transform =  transform * transform(vector(0,0,-0.005)*meter)
    ...
    }
    note that it is not a good idea to name a variable as a builtin function so i would name your transform variable as tr
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,204
    Answer ✓
    To be clear, variables shadowing functions is correct behavior -- in most c-like programming languages, variables declared in inner scopes shadow symbols in outer scopes.  It's also desirable because it lets a library writer add new functions to the library without worrying about breaking a function in code that uses that library that happens to use a local variable name that matches the new function name.  I'm not sure warning about shadowed symbols will provide more noise or signal; would need to think about that.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc

Answers

  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    edited April 2019 Answer ✓
    the general idea is if you need some additional transform (the moovement of the tool body) you can make it before the main transform and the resulting transform would be a composition of 2, in OS it wil be a product of 2 transforms:
    if (definition.AddConnectorBoltVoid)
    {
    transform =  transform * transform(vector(0,0,-0.005)*meter)
    ...
    }
    note that it is not a good idea to name a variable as a builtin function so i would name your transform variable as tr
  • owen_sparksowen_sparks Member, Developers Posts: 2,660 PRO
    edited April 2019
    Hi @konstantin_shiriazdanov and thanks for your help, it's appreciated. :+1:

    I swear I tried exactly that right at the beginning, and all seemed well.  The featurestudio accepted the code, but it fell over as soon as it was run.  Your "note" on "builtins" is of course the culprit, as soon as the code was changed to
    Mytransform =  Mytransform * transform(vector(0,0,-2.25)*millimeter);
    it all worked as expected.

     Can we beat up Onshape on this point?

    It would be nice if the IDE rejected variable names that are reserved!

    Cheers all,
    Owen S.

    Business Systems and Configuration Controller
    HWM-Water Ltd
  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646
    @owen_sparks

    Good find.  Our standard practice is to say 'const xform = toWorld(...)'

    I'll write up a bug.
    Jake Rosenfeld - Modeling Team
  • owen_sparksowen_sparks Member, Developers Posts: 2,660 PRO
    @owen_sparks

    Good find.  Our standard practice is to say 'const xform = toWorld(...)'

    I'll write up a bug.
    Thanks Jake, Onshape's commitment to address even small niggles like this is impressive.
    Owen S.
    Business Systems and Configuration Controller
    HWM-Water Ltd
  • mortezaPourmohamadimortezaPourmohamadi Member Posts: 9
    @Jake_Rosenfeld

    How is the bug fix going? 

    I just wasted a whole morning struggling to define a simple translate transform with no luck.

    Then I found this post by @owen_sparks and realised that the bug is still in there. 



  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646
    @mortezaPourmohamadi

    Fell through the cracks, thanks for the reminder.  I've reprioritized and added you to the ticket.
    Jake Rosenfeld - Modeling Team
  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646
    FYI it will be a lot easier to fix the documentation to not make this error than to fix the root issue that variables are allowed to shadow function names etc.  We cannot get rid of that behavior because it would break numerous feature studios.  We could warn for shadowed variables, but it is a lot of work, and we would need to find time for it.  I will write up an improvement for that too.
    Jake Rosenfeld - Modeling Team
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,204
    Answer ✓
    To be clear, variables shadowing functions is correct behavior -- in most c-like programming languages, variables declared in inner scopes shadow symbols in outer scopes.  It's also desirable because it lets a library writer add new functions to the library without worrying about breaking a function in code that uses that library that happens to use a local variable name that matches the new function name.  I'm not sure warning about shadowed symbols will provide more noise or signal; would need to think about that.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
Sign In or Register to comment.