Can the RGB colour of a BRepBody be set?

Can the RGB colour of a BRepBody be set?

Anonymous
Not applicable
1,844 Views
8 Replies
Message 1 of 9

Can the RGB colour of a BRepBody be set?

Anonymous
Not applicable

Can the RGB colour of a BRepBody be set to a user specified value using the API (in C++).

 

I've been tracing through the API and it looks like the material (texture, colour, etc) can only be set

from the existing materials library. I would like to specify "plastic" (from the library) but give it my

own RGB values.

 

If it can be done, how? I can't find a create function for a Ptr<Appearance>.

0 Likes
Accepted solutions (1)
1,845 Views
8 Replies
Replies (8)
Message 2 of 9

MichaelT_123
Advisor
Advisor

dig around ... color = adsk.core.Color.create( int(_r), int(_g), int(_b), opacity) # create(red, green, blue, opacity)

MichaelT
0 Likes
Message 3 of 9

Anonymous
Not applicable

Yes, I found that, but how do you set a Ptr<PRebBody>  with a Ptr<Color>? I can't find any

modify functions for a Ptr<Apearence>, I can only find functions to copy them about, i.e

from the materials library. Once I set a Ptr<Appearence> with a Ptr<Color> I can set the

Ptr<PRepBody> with the Ptr<Appearance>

0 Likes
Message 4 of 9

BrianEkins
Mentor
Mentor
Accepted solution

Hopefully, this will help.

https://ekinssolutions.com/setting-colors-in-fusion-360/

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 5 of 9

MichaelT_123
Advisor
Advisor

(int(Excellence ** Magnificence))!

 

MichaelT
0 Likes
Message 6 of 9

Anonymous
Not applicable

Thanks Brian.

0 Likes
Message 7 of 9

MichaelT_123
Advisor
Advisor

Hi, Mr Ekinks

 

I think I have share ... it with you!!!

 

As you presented your wonderful response ...  giving your customer ... 'the fish' ...

I have looked at your code and mine I laboured some time ago ...

 

Let's have a look:

Your sample:

"

colorProp = adsk.core.ColorProperty.cast(prop)

val = colorProp.value

if val:

result += ' Value: ' + (str(val.red) + ',' +

str(val.green) + ',' +

str(val.blue) + ',' +

str(val.opacity) + '\n')

else:

result += ' Value: Undefined\n'

elif prop.objectType == adsk.core.StringProperty.classType():

strProp = adsk.core.StringProperty.cast(prop)

result += ' Value: ' + strProp.value + '\n'

elif prop.objectType == adsk.core.FloatProperty.classType():

floatProp = adsk.core.FloatProperty.cast(prop)

result += ' Value: ' + str(floatProp.value) + '\n'

elif prop.objectType == adsk.core.BooleanProperty.classType():

boolProp = adsk.core.BooleanProperty.cast(prop)

result += ' Value: ' + str(boolProp.value) + '\n'

elif prop.objectType == adsk.core.ChoiceProperty.classType():

choiceProp = adsk.core.ChoiceProperty.cast(prop)

result += ' Value: ' + str(choiceProp.value) + '\n'

(returnValue, names, choices) = choiceProp.getChoices()

"

Mine sample:

"

for a in range( _propAppear.count 😞

aP = _propAppear.item(a)

apName = aP.name

apROnly = aP.isReadOnly

if ( apROnly == True 😞

apROnly = '<R>'

else:

apROnly = ''

apName = apName + apROnly

apType = aP.objectType

if ( apType == adsk.core.ColorProperty.classType() 😞

apColor = aP.value

if ( apColor == None 😞

maValue = 'Texture'

else:

maValue = '[{:d},{:d},{:d},{:d}]'.format( apColor.red, apColor.green, apColor.blue, apColor.opacity )

elif( apType == adsk.core.StringProperty.classType() 😞

apValue = aP.value

elif( apType == adsk.core.IntegerProperty.classType() 😞

apValue = aP.value

elif( apType == adsk.core.FloatProperty.classType() 😞

apValue = aP.value

elif( apType == adsk.core.ChoiceProperty.classType() 😞

apValue = aP.value

elif( apType == adsk.core.BooleanProperty.classType() 😞

apValue = aP.value

else:

try:

apValue = aP.value

except:

apValue = None

if ( apValue != None 😞

#propRecord.append( apType )

propRecord.append( apName )

propRecord.append( apValue )

"

I was so amazed! ... and no I am not saying that we copied from each other ...

but we certainly have had  copied from somebody/something else Smiley Wink

 

Best Regards

MichaelT

 

 

 

 

 

 

 

MichaelT
0 Likes
Message 8 of 9

adminTCYL2
Enthusiast
Enthusiast

Hi Brian, 
The link that is given by you for a solution of this posting does not work anymore: 
https://ekinssolutions.com/setting-colors-in-fusion-360/
... so the posting got no solution right now. 

0 Likes
Message 9 of 9

BrianEkins
Mentor
Mentor

Thanks for letting me know about the problem on my website.  I'll work on getting it fixed but it may be a few days before I can get to it.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes