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.
Code in variable definition line
ben_partouch
Member, csevp Posts: 135 PRO
Hello,
I want a configurable part to have a dimension driven by a variable in the document it's derived to.
However, until it's derived to that doc' it needs a default value.
What should I type in the definition line that will tell the part to use a variable name "depth" and if it's not existing use a default number of 600mm?
I hope I make any sense at all.
Thank you
I want a configurable part to have a dimension driven by a variable in the document it's derived to.
However, until it's derived to that doc' it needs a default value.
What should I type in the definition line that will tell the part to use a variable name "depth" and if it's not existing use a default number of 600mm?
I hope I make any sense at all.
Thank you
0
Comments
I'm not 100% if the above is the correct answer. Another way could be to have more than one variable I would say something like the below so you would essentially have three variables?
variable 1: configDepth = currently linked to config variable// linked to part - will turn into the derived variable
variable 2: standardDepth = 600mm
variable 3: depth = ((configDepth <= 0) ? standardDepth ; configDepth)
https://cad.onshape.com/documents/a77252951090311b449a810f/w/52c8aaca092ce6b6b227b2bd/e/775912e49d659ac70e4036ae
if you update the configuration depth value it will auto-change the depth variable otherwise if it is 0 it will default at 600mm
I need the code to try and use a variable that will only exist in other doc's and when it's not, it will use default.
So in my original configuration there is not variable available. Maybe not possible?
This approach will look in the current studio, but not other studios.
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴
Can you write this into a definition line in the part studio? I can't use a custom feature for this action.
Also, instead of a warning I want to default to a pre-set dimension.
Eventually when import this configured part into a new part studio it will automatically find the variable or go to default. That way I don't need to manually type the variable name everytime in the configuration menu when deriving the part.
Thank you,
Can you provide more info why you don't want to use a custom feature? To me, this seems like the perfect scenario for a custom feature.
You can have a custom feature that will derive and check for a local variable. Part studios do not interact with the studio they are being derived to unless you specifically type in a value in a configuration in the derived input boxes, or you use a custom feature.
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴
How would you use custom feature in this case?
I just thought it's much simpler without custom feature.
When will I activate it? Will it be a part of the configured part?
Thank you for your time Michael, I really appreciate it.
Notice how when the variable "myVariable" is suppressed, the feature automatically uses the default 600mm that was set in the featurescript. This feature would allow the user to pick which part studio they wanted to derive. However, you could permanently set this to a specific studio if you were always deriving the same studio over and over again.
If this is for your company, consider using CADSharp to automate your workflow. We write custom features and API to save tons of time for part studios, assemblies, and entire document libraries. I've seen some tasks so automated that the user simply presses a button and watches their assembly build.
Custom Derived Featurescript Test - Onshape Link
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴
I have quite a few variable to "automate" this way so I assume I'll need a separate feature for each one..
Thank you very much Michael!
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴
Took me a while to implement this but it's great. Thank you!
@ben_partouch, nice! The first time is the most difficult. FeatureScript is a language, it gets easier the more you use it.
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴