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.
Evan Reese
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.
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴
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).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);
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
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...