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.

Using Feature Script

billy2billy2 Member, OS Professional, Mentor, Developers, User Group Leader Posts: 2,068 PRO
edited May 2016 in FeatureScript
So I bought an occipital structure sensor and I've been writing feature scripts to upload data into OS. I just wanted to share the program structure, hopefully it'll help others construct some code.

occipital scanner mounted to my ipad:


The biggest tip is to keep all functions inside one FS:

Below I've folded all the code to show all the feature script functions in one file. I use 5 functions:


This makes it easy to copy a feature script from one document to another.


When starting a new feature script in a new document:


I create a new feature script in the document and then insert the body of the code into a new feature script. This gives me the latest version of feature script.

So with one feature script, I get all my functions:


The 1st thing I do is read in data and pack an array:

There's over 55,000 points available in the obj file created by the scanner, I parse out over 13,000 points and add them to an array. I pass the array around to different functions using:

sets array in functions that modify the array ie... objData creates the array, objCenter offsets the array:
        setVariable(context, 'billysVectors', vectors);
        setVariable(context, 'billysArrayCnt', arrayCnt);


read array in every function, every function needs access to the data:

        var arrayCnt = getVariable(context, 'billysArrayCnt');
        var vectors = getVariable(context, 'billysVectors');


Every function reads the array, some actually re-write the array if I'm making any modifications. For instance, the objCenter routine computes an offset vector and translates the entire dataset by this distance. So after objCenter computes, the data is centered for all remaining functions.


I center the data, occipital does great with orientation, but blows it on location. After centering, I have a function that displays the array. For performance reasons, I limit the display to 500 points:


I create a surface and ask for the points that are a certain distance from that surface:



I create a solid and ask for points inside the volume further reducing the dataset:


From the point cloud, I create some geometry:



So what is this?


It's the buddy peg mount on a motorcycle. I'm replacing the buddy pegs with turns signals. When designing the turn signal, I know what the mounting bracket looks like.

I typically design fenders, shrouds and fender eliminator kits. Usually more organic shapes than a simple bracket.  I've also been scanning humans to get body details for medical devices. It's becoming a useful tool.



It's a great way to take organic shapes and bring them into the CAD world.







Comments

  • traveler_hauptmantraveler_hauptman Member, OS Professional, Mentor, Developers Posts: 419 PRO
    Very cool. Very nicely illustrated as well.

    I have not hit FS version issues yet. I'll have to remember that...
  • billy2billy2 Member, OS Professional, Mentor, Developers, User Group Leader Posts: 2,068 PRO
    thanks traveler,

    I've been reading your posts and learning a lot from your experiences.


  • fastwayjimfastwayjim Member, OS Professional, Mentor Posts: 220 PRO
    Billy, this is really awesome stuff! Thanks for sharing! I hope to be digging deeper into FS in a few weeks, I need to catch up to you guys, haha!

    This is hands down my favorite part of OS right now. No limits.
  • billy2billy2 Member, OS Professional, Mentor, Developers, User Group Leader Posts: 2,068 PRO
    fastwayjim-

    Thanks, if you come up with something, please share.


Sign In or Register to comment.