Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. 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

EvanReeseEvanReese Member, Mentor Posts: 2,867 PRO
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
The Onsherpa | Reach peak Onshape productivity
www.theonsherpa.com

Comments

  • romeograhamromeograham Member, csevp Posts: 748 PRO
    edited May 2020
    Nice work @Evan_Reese

    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?

  • EvanReeseEvanReese Member, Mentor Posts: 2,867 PRO
    edited May 2020
    ooh that's an interesting use I'd not thought of. could be handy.

    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.

    Evan Reese
    The Onsherpa | Reach peak Onshape productivity
    www.theonsherpa.com
  • AlexPittAlexPitt Member Posts: 22 ✭✭
    A nice development @Evan_Reese! Great little icon too! I copied, liked it and had a play, setting up a config table as with Neil's.  As you say, just need to remember to not use the OS native colour picker which overrides the FS (as per any feature script affecting properties).  The ability to use hex code is great for quickly pasting colour refs in from the web.
  • Cache_River_MillCache_River_Mill Member Posts: 225 PRO
    Legit!
  • EvanReeseEvanReese Member, Mentor Posts: 2,867 PRO
    The feature accepts face selections now too
    Evan Reese
    The Onsherpa | Reach peak Onshape productivity
    www.theonsherpa.com
  • MichaelPascoeMichaelPascoe Member Posts: 2,814 PRO
    I was about to request a "color all" button but its already there!



    RENDERCAD
    rendercad.ai - Photorealistic product rendering.

    ▚▞▚▞▚▞▚▞▚
    ________________________________________________________________________
  • EvanReeseEvanReese Member, Mentor Posts: 2,867 PRO
    I was about to request a "color all" button but its already there!


    nice! I'm glad I'm not the only one. I was working recently on a design for a new shed I want to build and got annoyed with always trying to make it look like wood or leaving it all different colors
    Evan Reese
    The Onsherpa | Reach peak Onshape productivity
    www.theonsherpa.com
  • EvanReeseEvanReese Member, Mentor Posts: 2,867 PRO
    I just pushed a V14 update to this feature giving it some preset palettes to make it easier to just slap some color on without having to fiddle with numbers.  Check it out and let me know what you think.



    Evan Reese
    The Onsherpa | Reach peak Onshape productivity
    www.theonsherpa.com
  • MichaelPascoeMichaelPascoe Member Posts: 2,814 PRO
    Legit, thanks!

    RENDERCAD
    rendercad.ai - Photorealistic product rendering.

    ▚▞▚▞▚▞▚▞▚
    ________________________________________________________________________
  • eric_pestyeric_pesty Member, pcbaevp Posts: 2,611 PRO
    Nice! Wish the standard appearance tool had this too!
    Now if we could just get some more refined appearances (and also be able to have default appearances linked to materials)!
  • eric_pestyeric_pesty Member, pcbaevp Posts: 2,611 PRO
    edited March 2022
    @Evan_Reese
    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.
  • EvanReeseEvanReese Member, Mentor Posts: 2,867 PRO
    edited March 2022
    @Evan_Reese
    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.
    I think I'd have to add a "Use expression" checkbox or something and make it go to a different UI parameter that accepts anything, not just strings. Since it seems like a niche use-case, I don't think I'm going to add it, but I know you know some FS so you could probably knock it out one of two ways.
    1. Copying my code and making that tweak to the UI to have your own version of Part Color.
    2. 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).
    Evan Reese
    The Onsherpa | Reach peak Onshape productivity
    www.theonsherpa.com
  • eric_pestyeric_pesty Member, pcbaevp Posts: 2,611 PRO
    @Evan_Reese
    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.
  • EvanReeseEvanReese Member, Mentor Posts: 2,867 PRO
    edited March 2022
    I haven't much either, but you know how if you want to extrude something in FS you can either use opExtrude() or extrude()? opExtrude is just the basic function to extrude some geometry, but extrude() is the actual extrude feature with drafts, surface mode, sheet metal capability, and a merge scope. I'm calling the entire Part Color feature as a function here via colorPart(), and since my UI inputs are named the same things as the ones Part Color is looking for I can just pass the whole definition map in and it works. Like this:

    colorPart(context, id, definition);

    I did have to set definition.colorMode = ColorMode.Hexadecimal; since leaving it undefined caused a failure. I could have also done this, but I didn't need to because the names of the map keys match anyway:

    colorPart(context, id, {
    "colorMode" : ColorMode.Hexadecimal,
    "parts" : definition.parts,
    "faces" : definition.faces,
    "features" : definition.features,
    "invertParts" : definition.invertParts,
    "alpha" : definition.alpha,
    "hexCode" : definition.hexCode
    });
    Evan Reese
    The Onsherpa | Reach peak Onshape productivity
    www.theonsherpa.com
  • eric_pestyeric_pesty Member, pcbaevp Posts: 2,611 PRO
    Right,
    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:

           if (definition.Hexmode == Hexmode.Variable)
           { definition.hexCode = definition.hexCodeVar;
           } 

    Before calling the Part color: 
    https://cad.onshape.com/documents/6bc71eac4d11d3aecd10fc74/w/01f622cee2fa8a4b64e1c3f7/e/2e5523cca33923b9f6cf2a45

  • eric_pestyeric_pesty Member, pcbaevp Posts: 2,611 PRO
    @Evan_Reese
    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
  • EvanReeseEvanReese Member, Mentor Posts: 2,867 PRO
    edited March 2022
    Open the part properties and hit "Reset all" (note, this will get rid of all part metadata like name and part number unfortunately). If you've set the color manually at some point, it won't work. I'm not really sure why that's how it works, but I'm pretty sure its beyond the scope of FS to solve it. It would have to be changed by Onshape. I've considered adding a checkbox so that you can override it by selecting a body, but actually coloring the faces of the body.
    Evan Reese
    The Onsherpa | Reach peak Onshape productivity
    www.theonsherpa.com
  • eric_pestyeric_pesty Member, pcbaevp Posts: 2,611 PRO
    Thanks, that solved it...
    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...
  • martin_kopplowmartin_kopplow Member Posts: 1,306 PRO
    edited March 1

    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.

    grafik.png

    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_kopplowmartin_kopplow Member Posts: 1,306 PRO
  • EvanReeseEvanReese Member, Mentor Posts: 2,867 PRO

    @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.

    Evan Reese
    The Onsherpa | Reach peak Onshape productivity
    www.theonsherpa.com
  • martin_kopplowmartin_kopplow Member Posts: 1,306 PRO

    @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 …

Sign In or Register to comment.