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.

Trying to translate loft() to opLoft() in FeatureScript

brian_guanbrian_guan Member Posts: 13 ✭✭
Hi featurescript experts,

I am trying to loft 2 organic shapes together using Featurescript opLoft() but I am just unable to get it to work, though I am able to achieve the result I want using the user interface which generates code using loft() instead of opLoft().

Here's the link to my test model https://cad.onshape.com/documents/4e48bb736c8527acdb63fb73/w/7d1ce53ca3a862a186b9bfdc/e/b642fb834c7a068eccafa01c

This is the desired outcome achieved with UI which calls loft().



But I just can't get it to look all smooth using opLoft(), which looks like this (notice the sharp edges):


I think I need to use derivativeInfo in opLoft() somehow to specify the End conditions but I am not sure how. The documentation on opLoft() parameters is quite lacking to say the least. 

Can someone help point me in the right direction? (Even better show me working code?)



Another minor annoyance is that the new solid is not merged with the 2 parts to be lofted, and I can't figure out whether opLoft() can do it or I have to explicitly Boolean Union them myself. 

Many thanks in advance,

Brian.

Comments

  • Jacob_CorderJacob_Corder Member Posts: 137 PRO
    edited September 2023
    opLoft does not merge bodies.

    First thing you need to do is read the loft feature code and see how onshape converts loft to opLoft. then you should be able to backwards figure it out.
     

    Instead, just call loft(context,id,definition) and change your opLoft code to loft.  


    for opLoft derivatives, hopefully this can be used to help

    var index = 0;//change to size(definition.profileSubqueries)-1 for the last section and size(definition.guideSubqueries)-1 for guides
        var profileAdjacentFaces = makeRobustQuery(context,qAdjacent(definition.guideSubqueries[index],AdjacencyType.EDGE,EntityType.FACE));
        var guideAdjacentFaces = makeRobustQuery(context,qAdjacent(definition.guideSubqueries[index],AdjacencyType.EDGE,EntityType.FACE));
        var derivatives = [];
        //this provides tangent to some faces for profileAdjacentFaces same as Start Profile Condition set to Match Tangent in loft()
        derivatives = append(derivatives,{"profileIndex": index,"adjacentFaces":profileAdjacentFaces ,"matchCurvature":false,"magnitude":1} );
        
        //this provides tangent to guideAdjacentFaces same as Continuity set to Match Tangent in loft()
        derivatives = append(derivatives,{"profileIndex": index,"adjacentFaces":guideAdjacentFaces ,"matchCurvature":false,"magnitude":1,"forGuide":true});
        
        //for derivatives of normal to profile 
        //this provides normal to profile  Start Profile Condition set to Normal To Profile in loft()
        var dir = extractDirection(context,definition.profileSubqueries[index]);
        // you can also specifiy a vector in any other way to use here. 
        derivatives = append(derivatives,{"profileIndex": index,"vector":dir ,"magnitude":1} );
  • brian_guanbrian_guan Member Posts: 13 ✭✭
    Thank you Jacob for your response. I would love to see how loft() translates to opLoft() under the cover but I don't know how to uncover the code.  Using Show Code in Part Studio to see the loft() operation I can see the call, but I can't drill down to see how loft() is implemented under the cover. If I can see how featurescript internally implement loft() to opLoft() it will answer a lot of my questions.  Can you provide a link to the underlying code if you have access? 

    Trying your 2nd suggestion by cutting and pasting from Part Studio Show Code and changing my feature script code to use loft() instead of opLoft() gives me an error "Function loft() with 3 arguments not found." Seems like loft() cannot be called inside my custom feature script? This seems like a NOOB issue that I have never had to solve, please point me to the right direction if possible.

    Trying your 3rd suggestion by using your code to programmatically specify the derivativeInfo I was unable to get far as I frankly don't understand what the code is trying to do. For example it is referencing "guideSubqueries" but I didn't need to specify in my manual loft. So I am unsure what to put there.

    (As for the opLoft() not doing merge, luckily that is something I know how to do via featurescript, so not a problem, just wanted to make sure it is not already implemented, thats all.)
     

    Thank you in advance for your help.
  • _anton_anton Member, Onshape Employees Posts: 413
    I would love to see how loft() translates to opLoft() under the cover but I don't know how to uncover the code.
    Behold! https://cad.onshape.com/documents/12312312345abcabcabcdeff/w/a855e4161c814f2e9ab3698a/e/0aef2b1033d14885b0266e73
  • brian_guanbrian_guan Member Posts: 13 ✭✭
    _anton said:
    I would love to see how loft() translates to opLoft() under the cover but I don't know how to uncover the code.
    Behold! https://cad.onshape.com/documents/12312312345abcabcabcdeff/w/a855e4161c814f2e9ab3698a/e/0aef2b1033d14885b0266e73
    Thank you Anton!  Part of my problems is I don't know what's even available, like "loft.fs". Now I get it, I just had to add import loft.fs at start of script to have the loft() function!
  • _anton_anton Member, Onshape Employees Posts: 413
    So new Feature Studios are created with the common.fs import, which gets almost everything FS authors need. If you want more out of the standard library (that document is the entire std), then yeah, you'll need to import it manually.
Sign In or Register to comment.