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.

Connector pin patterning/instantiation

I am creating a model for an electrical connector which has 3,200 pins!  The connector pins are not located in a (nice) standard pattern  :/
I have all the pins and location coordinates in a spreadsheet.  I have a model for the pin and the whole connector.  Is there a way to write a FeatureScript that will instantiate the 3,200 pins into an assembly using the location coordinates?

Answers

  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646
    Hello Bill,

    Yes you can definitely do this! Featurescript understands CSV format, so if you can get your data into a CSV file and upload that into the document in question you can reference that data from featurescript.  From there you could use importDerived(...) or applyPattern(...) to place the pins in the desired locations.

    https://cad.onshape.com/FsDoc/imports.html

    @ilya_baran or @kevin_o_toole_1 May have better advice than me about the performance difference between deriving vs. patterning 3200 similar parts, or may have an entirely different suggestion.
    Jake Rosenfeld - Modeling Team
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,215
    Basically, what Jake said.  Performance-wise, you don't want to pattern the import, you want to create a pin body and use opPattern with an array of transforms (to do a giant body pattern) computed from the CSV.  If you can model your pin as just a cylinder, performance will be better.  Constructing 3200 transforms can take time in FS -- the trick to making it fast is to construct a single transform (with the identity rotation matrix) and just modify the translation coordinates.  We can help you optimize once you have a document you can share.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • Bill_Orner_EsperantoBill_Orner_Esperanto Member Posts: 5
    Thanks for your fast response, I am coming from a long history in E-CAD (Tcl, etc.) so stumbling up the learning curve on Featurescript.  I have the "shell" put together but am struggling with the constructs of the functions.  Would it be possible to do a live screen share to go through I am trying to do?

    Thanks!
  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646
    Hi Bill,

    I'd be interested in trying my hand at something like this, if not just to learn and test our FeatureScript workflows.  I don't think I can live stream, but I can try to set up something nice for you to plug-and-play your CSV and Pin. I'll let you know if I make any progress.
    Jake Rosenfeld - Modeling Team
  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646
    Hi again @Bill_Orner_Esperanto ,

    This is my first pass at what you would need:
    https://cad.onshape.com/documents/abcec3031933a947d9ab22c4/w/c6d1cfebe2198b29879a753e/e/ff7728b8b7af62b4c4f7d1cb

    Please copy the Onshape document and explore the FeatureScript and part studios. I didn't know the format of your spreadsheet, so there are comments in the FeatureScript file of what variables you may need to change depending on what the format of your sheet is.  Patterning complex geometry with 3200 instances will border on waiting for tar to drip, so I added a "Simplify pattern" option, which just patterns a box at every location in the CSV.

    In the process of doing this, I re-read your original question and think there may be better way of doing this overall.  You mention doing this in an assembly, which is actually much better for performance than patterning in the part studio (and creating 3200 separate instances of your part).  You could do this by creating some kind of extruded depression on the connector at every pin location (this could be done using the feature I provided with some small tool and then subtracting all the patterned tools from the connector), then using the assembly 'Replicate' command.
    https://cad.onshape.com/help/Content/replicate.htm
    https://www.youtube.com/watch?v=Wkdh4ja6Tkw

    Let me know if you have any questions.

    FYI @ilya_baran
    Jake Rosenfeld - Modeling Team
  • Bill_Orner_EsperantoBill_Orner_Esperanto Member Posts: 5
    Thanks Jake,

    I was able to copy your example code into my project and make the changes necessary for my file and format.  I am still working through testing.  I have a few more simple questions:

    • I don't see how to enable Featurescripts in assemblies?  I found a website called Solidsmack and from what it says I can only use Featurescript for part design?  If true then the option to instanciate the pins as an assembly is not possible.
    • I think this was your point to use Featurescript to place a simple thing at each pin and then do some kind of global replace in assembly to insert the pin.  Taking that approach is there any kind of macro capabilities like Cadence "Skill" to enable this?
    Thanks for your patience and help getting me up the learning curve.  If there are any books or other reference materials that I should be referring to please let me know.
  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646
    Hi again!

    Featurescript is used to build parts in a part studio.  Assemblies just use these built parts, and Featurescript cannot be used to define anything about the assembly itself.

    When I mentioned instancing the pin, I meant for you to only create the pin once in a part studio and use the 'Replicate' command in the assembly to instance it.

    This help document may help:
    https://cad.onshape.com/help/Content/replicate.htm

    This video gives more detail:
    https://www.youtube.com/watch?v=Wkdh4ja6Tkw


    You may want to play around with replicate with simpler cases to see what I mean before you attempt to do something more complicated with your final design.  If you share a link to your document here, it may be easier to see a good way to optimize your design.
    Jake Rosenfeld - Modeling Team
  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646
  • Bill_Orner_EsperantoBill_Orner_Esperanto Member Posts: 5
    Thanks,

    after much trial and error I have made the import script and pin placement work!  As expected the loading of the drawing is very slow due to the thousands of pins, no different than the performance with the "other" design tools with something this complex.  

    Onshape users would greatly benefit from more complete Featurescript documentation including practical examples organized in one place for easy access.  I can see a lot of capabilities in Featurescript but the learning curve is difficult.  Some challenges I had for example is that fCylinder and skCircle have different behavior for the ID.  I used a "for" loop with fCylinder to place the pins, I had to concatenate onto the fCylinder ID an incremental number from the loop counter using "id + "cylinder" + i" where "i" is a counter.  I tried and experiment to see if placing a circle instead of a cylinder would make drawings load faster but found that ID for skCircle behaves differently, couldn't figure out why.  So, some more thorough documentation would be a great benefit to users and in particular how the relationships work between the active drawing, face and the script.  You can close this as complete.

    Thanks,
    Bill 
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,215
    Yep, sketch entity ids work differently than feature ids -- that's some documentation debt...
    Have you tried the FS profiler to optimize the regeneration of your feature?  For example, I expect that creating one cylinder and doing an opPattern will go faster than a lot of fCylinder calls (assuming you need it to regen faster and the profiler tells you that's the bottleneck)...
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • david_gregorydavid_gregory Member Posts: 14 PRO
    edited January 2020
    Hi All-

    I modifed Jake Rosenfeld's Script to allow the CSV file to be selected from the GUI.  This is a feature I had been looking for, so thank you for the point in the right direction.

    It allows you to drive a 2D pattern thru a CSV set of XY points (X and Y are columns, each point is a row).


Sign In or Register to comment.