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.
Custom Feature: Part Color
I made a Part Color feature here. It's useful to change the appearance of a part with configurations. I know you can configure the appearance of parts in the Configured Properties, but you're limited to setting up each possible permutation of the design, which is onerous especially when using a variable configuration that could be changed to anything. I needed something like this for something I was working on, then my wheels got turning on whether I'd be able to figure out how to drive it with a hexadecimal code, and it turned into a project-based learning exercise for me. I hope it's useful to someone else too.
3

Comments
This is interesting, since changing color in the Feature List means that you can use color to represent different levels of development in the Feature List ... almost a progress bar of sorts.
Sometimes I'll use neutral (or just Onshape standard) colors for parts when they are "development", "parent" or "master model" type parts...then, when they get closer to being done (or if they are derived into a more finished part studio), I'll use colors that are closer to the real color of the finished real-world parts. This will make that easier.
Having a little trouble with an error, though: I set a color on a part using the regular "Edit appearance" method, then tried to use your FS.
I thought it was working (since I had set the color with the regular method to get a hex code from one of my custom colors), but now I realize that the FS will not change the color.
If I use your FS on a part with default Onshape color, it seems to work, unless I try "Use hex code".
When I try to use a Hex code to set the color, the feature throws an error, and doesn't do the color change:
When I deselect the Use hex code box, the error goes away.
Any ideas?
Of course, my first user finds a bug immediately, haha. I've updated it to accept upper and lower case letters, which was the issue.
I think it's like the other features that change part properties in that the part you're changing can't have been edited manually before. To get it working, right click the part in the parts list and select "properties" then pick, "reset all". after that it will work. be aware that this will REMOVE ALL PROPERTIES from your part (like name, part number, revision, etc), so if this is a part that's late in development, especially one that's been released, you'll want to watch out. It helps to plan for it. if you didn't you can always re-enter the data you need. Once you're really far into a project you may not want to do this. I believe the change can just be rolled back if you don't like it though.
The Onsherpa | Reach peak Onshape productivity
www.theonsherpa.com
The Onsherpa | Reach peak Onshape productivity
www.theonsherpa.com
RENDERCAD
rendercad.ai - Photorealistic product rendering.
▚▞▚▞▚▞▚▞▚
________________________________________________________________________
The Onsherpa | Reach peak Onshape productivity
www.theonsherpa.com
The Onsherpa | Reach peak Onshape productivity
www.theonsherpa.com
RENDERCAD
rendercad.ai - Photorealistic product rendering.
▚▞▚▞▚▞▚▞▚
________________________________________________________________________
Now if we could just get some more refined appearances (and also be able to have default appearances linked to materials)!
Don't know if there's anything you can do about it but I just noticed I can't seem to use a variable for the Hex value... I was hoping to use this to apply any random color using a configuration variable (with the Hex value) but I don't think I can make it work.
- Copying my code and making that tweak to the UI to have your own version of Part Color.
- Import the Part Color Feature Studio into your own custom Feature Studio and call my feature as a function, just doing a tiny bit of work to take an expression and convert it to a string.
I actually wanted to check my understanding of the second one and by the time I did I made this. you can see my code is super short, because it's just essentially giving you a new UI on top of the Part Color code. Note, since it's now looking for an expression as input, you have to add quotation marks around your hex code entries (or give it something that's already a string, like the config variable is doing).The Onsherpa | Reach peak Onshape productivity
www.theonsherpa.com
Thanks, I'll take a look! "importing" isn't something I've played with before so I will need to do a bit of reading.
colorPart(context, id, definition);
The Onsherpa | Reach peak Onshape productivity
www.theonsherpa.com
I had a look and from a programming perspective I understand calling a function but I don't really get how it works in FS...
I guess looking at this the main question is why won't a string input accept a string variable? And probably related why do "regular" variables don't have a "string" option... I expected it to just work so I had a plan to use it that way but it doesn't allow it!
Having to put quotes around your hex value would be annoying! I guess the only other option I can think of would require adding yet another type of input option i.e. "Variable". I gave a shot at allowing either a regular "input" hex or "variable" adding a "Hexmode" dropdown to the wrapper.
When used it basically treat it as hex and do something like this:
Before calling the Part color:
https://cad.onshape.com/documents/6bc71eac4d11d3aecd10fc74/w/01f622cee2fa8a4b64e1c3f7/e/2e5523cca33923b9f6cf2a45
I'm having an issue with a specific document where I only seem to be able to apply color to faces or features but not bodies...
It seems to work as expected when I checked a random doc (even if I apply face appearance to specific faces from the built in Onshape controls, which I thought might have been causing the issue) so I'm not sure what's going on with this specific part studio. Am I missing something obvious?
https://cad.onshape.com/documents/ecbaa424110effa81de8e4b5/w/c24d984b5be96316a749a670/e/2ff8279e857fe28ea1b50543
The Onsherpa | Reach peak Onshape productivity
www.theonsherpa.com
For some reason when I didn't have the issue on a "test" part I made but I guess I hadn't applied appearances quite the same way before...
I tore my hair out last night with the bodies in my simple model not changing colour, even if the configuration as such changed as expected. I hadn't assigned any colour manually before, so I thought I'd be safe. Ha! There were imported parts in my model, and these STEP-parts came with a colour property, which I wasn't aware of. I only thought about it this morning. When I came to the properties dialog, the reset button was not active. I first had to add random properties to the parts in order to be able to then reset them all. A bit strange. Anyway, that fixed it.
Now I have another problem. This appears the first time I have a part that needs to be differentiated in the BOM just by it's configured colour alone. It has other configured properties, such as state open/closed and the front panel thickness it is to be mounted in, but I only need the colour to make a difference in the BOM, for the shop will have to order say 10 yellow banana jacks, a red and 25 green ones, or so.
I need a path to get the colour in the BOM, resulting in a different part number or at least unique part name. It already creates a new line and quantity in the table, but I'm not sure where to begin to have the colour show up. Maybe I'm just missing the right search terms. Any hints appreciated.
@martin_kopplow you can use the Part Name custom feature to configure either the Name, PN, or both. https://cad.onshape.com/documents/f4d470584fdeef9603415532/v/7d0c0b30a8b73bbd6ed13b01/e/c2cde0fc0eb4a05cb0b32b5b
To get it working, you'll have to reset the properties again, which a pain.
As for your issue with the colored step file. Sometimes the colors they have are applied to the faces, not the entire body, in which case the assigned body color gets overridden and it looks like nothing changed. You could try using Part Color with a Query Variable to edit all of the faces of a part instead of coloring the part itself.
The Onsherpa | Reach peak Onshape productivity
www.theonsherpa.com
@EvanReese My STEP part was probably of the face coloured type. Once I knew, it was relatively simple to get rid of that, by selecting one face, go to the edit face apperance box and empty the list the edit dialog comes up with. It appears STEP can have different flavours of this, though: Overrridden body colour, all faces being coloured in one go, all faces being coloured one by one, …
I have an issue with these tools that kind of override the configurations: It appears they would not respond to downstream changes. Say a colleague changes the colour of one banana jack, to stay with the sample, from red to yellow, and it was correctly configured (or should we say assigned?) a name/number that reflects it is red, that doesn't appear to follow. It'll still be a yellow one in the BOM.
It appears it would be easier to just create a number of these things in one document, one in each colour, use that as a library and then insert what is needed as a composite part. In case the colour needs to be changed, just swap the red one for a yellow one and it's all good. If the solution is more complex than the problem, one could argue it is not actually a solution. ;0)
I'll try a bit more next time, but this thing needs to be built this week, so …