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.
How to get the "Part_Number" with FeatureScript?
sebastian_glanzner
Member, Developers Posts: 423 PRO
Hello Everyone,
I need to name my configurations parts automatically.
The "Part_Name" should be "Part_Number" + "Part_Description"
The reason is when I export the part as a STEP-File it should contain the Number and Description in the File Name.
I managed to automatically create the "Part_Description", but I can't request the actual "Part_Number".
The number is assigned with Configured Part Properties. But I only get "PART_NUMBER" and not the actual number
Does anyone know a solution? Thanks in advance!
I need to name my configurations parts automatically.
The "Part_Name" should be "Part_Number" + "Part_Description"
The reason is when I export the part as a STEP-File it should contain the Number and Description in the File Name.
I managed to automatically create the "Part_Description", but I can't request the actual "Part_Number".
The number is assigned with Configured Part Properties. But I only get "PART_NUMBER" and not the actual number
Does anyone know a solution? Thanks in advance!
FeatureScript 782;
import(path : "onshape/std/geometry.fs", version : "782.0");
annotation { "Feature Type Name" : "Set Name" }
export const setName = defineFeature(function(context is Context, id is Id, definition is map)
precondition
{
annotation { "Name" : "Part", "Filter" : EntityType.BODY, "MaxNumberOfPicks" : 1 }
definition.myPart is Query;
annotation { "Name" : "Prefix" }
definition.prefix is string;
annotation { "Name" : "Segment 1" }
definition.segment1 is string;
annotation { "Name" : "Segment 2" }
definition.segment2 is string;
annotation { "Name" : "Segment 3" }
definition.segment3 is string;
}
{
var partDescription is string = definition.prefix;
for (var i = 1; i <= 3; i += 1)
{
partDescription ~= toString(" ");
partDescription ~= toString(definition["segment" ~ i]);
}
setProperty(context, {
"entities" : definition.myPart,
"propertyType" : PropertyType.DESCRIPTION,
"value" : partDescription
});
var partNumber is string = PropertyType.PART_NUMBER;
var partName is string = partNumber;
partName ~= toString(" ");
partName ~= toString(partDescription);
setProperty(context, {
"entities" : definition.myPart,
"propertyType" : PropertyType.NAME,
"value" : partName
});
});
1
Comments
Conceptually, part properties are applied by several sources. The FeatureScript properties are applied first (during regeneration). Then, on the fully created parts, properties set through the properties dialog are applied. Finally, properties in the "Configured Part Properties" table are applied to specific configurations.
This means that the "context" passed into your feature is in a rolled back state which does not have the part properties.
For your case I see two possibilities:
- If you need this done programmatically right now, the right solution is the Onshape API. You can create a private app which will use the "Get Part Metadata" endpoint to get the part number and descriptions, and use the "Update Metadata" endpoint to set the part number based on that.
- You can submit an improvement request for a non-programming way to set part properties based on other part properties in a Part Studio
Let me know if you have further questions!Or combine all this in one feature which should have tho configured fields for part number and part descr. and then evaluate part name internally and assign it to the corresponding property. Sounds bulky but this is the only way of such automation which works on part studio level.
@sebastian_glanzner If you go that route, make sure to delete your Configured Part Properties table, since the values in that table will override anything set with FeatureScript.
You can verify the property values are being set by switching to a configuration, right clicking a part in the parts list, and selecting properties. All the part properties will be listed there. However, be sure to be careful in that dialog – if you change property values through the dialog and save the changes, those values will be permanently set, and as I mentioned above, they will override any values set in FeatureScript. Unlike configured part properties, there is currently no way to undo this. You can change the value to something else, but right now, the only way to completely unset those values is to contact Onshape support.