Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- 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.
Can Featurescript pull sketches from other documents?
Michael_Ursuliak
Member Posts: 14 ✭
I am trying to write a Featurescript that can make extrusions of predefined shapes centered on points defined by the user.
I would like to have a document full of sketch profiles that can be selected from, but i don't know how to cross reference documents and I haven't found anything in the documentation yet.
How can I get a sketch from one document and use it in a Featurescript for another?
I would like to have a document full of sketch profiles that can be selected from, but i don't know how to cross reference documents and I haven't found anything in the documentation yet.
How can I get a sketch from one document and use it in a Featurescript for another?
0
Best Answers
-
chadstoltzfus Member, Developers, csevp Posts: 146 PROThere's a couple of ways to do this, and it depends on how you want the user to interact with the feature. Two of the primary ways of cross referencing documents is either with Reference parameters or Imports.
If you want to have the user be able to select the sketch by selecting a Part Studio (let's say each Part Studio contains a single sketch) you could use Reference parameters, which will have a similar UI/UX to Derive. Onshape has provided an example document of working with reference params here.
If you want the the user to select from a drop down and have the feature find the sketch, then you will need to use Imports. From here you can just set up some if/else statements (or a case statement) to pick which import to derive based on the user's selection from the drop down. If you are using this option, it would be simpler to have it so each sketch is in its own Part Studio, though there are some clever workarounds for this. If you happen to have all of the sketches in one Part Studio, you will need to have some way of letting your custom feature find which sketch to import, this can be accomplished with Attributes.
I'm happy to go into more detail on either of these approaches if you are able to let me know which approach you would prefer.Applications Developer at Premier Custom Built
chadstoltzfus@premiercb.com2 -
MichaelPascoe Member Posts: 2,033 PROYes, however they will not behave exactly the same as sketches created by the sketch feature. For example, you can't import these into the assembly or drawings. You can use them for extrudes and for getting queries.
You can either hard code the part studios into your feature like this so that the user doesn't have to derive, or you can have the user derive like this:FeatureScript 1993; import(path : "onshape/std/common.fs", version : "1993.0"); annotation { "Feature Type Name" : "Instantiate Test" } export const instantiateTest = defineFeature(function(context is Context, id is Id, definition is map) precondition { annotation { "Name" : "Derived" } definition.derived is PartStudioData; annotation { "Name" : "Location", "Filter" : BodyType.MATE_CONNECTOR, "MaxNumberOfPicks" : 1 } definition.location is Query; } { const instantiator = newInstantiator(id + "inst", {}); const toPlane = evMateConnector(context, { "mateConnector" : definition.location })->plane(); const instance = addInstance(instantiator, definition.derived, { "configuration" : {}, "transform" : transform(XY_PLANE, toPlane)}); instantiate(context, instantiator); const instantiatedFaces = qCreatedBy(id + "inst", EntityType.FACE); debug(context, instantiatedFaces, DebugColor.GREEN); });
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴2
Answers
If you want to have the user be able to select the sketch by selecting a Part Studio (let's say each Part Studio contains a single sketch) you could use Reference parameters, which will have a similar UI/UX to Derive. Onshape has provided an example document of working with reference params here.
If you want the the user to select from a drop down and have the feature find the sketch, then you will need to use Imports. From here you can just set up some if/else statements (or a case statement) to pick which import to derive based on the user's selection from the drop down. If you are using this option, it would be simpler to have it so each sketch is in its own Part Studio, though there are some clever workarounds for this. If you happen to have all of the sketches in one Part Studio, you will need to have some way of letting your custom feature find which sketch to import, this can be accomplished with Attributes.
I'm happy to go into more detail on either of these approaches if you are able to let me know which approach you would prefer.
chadstoltzfus@premiercb.com
You can either hard code the part studios into your feature like this so that the user doesn't have to derive, or you can have the user derive like this:
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴
lol my page refreshed and it looks like @chadstoltzfus beat me to it!
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴