2

I am having difficulty changing the color of 3d object (Metal detector) using .setColor(materialname,color) method. I am unable to get specific material of object of which I want to change colour.

I have tried .setColor(materialname,color) method

detector.setColor(Material_(2)_Surf,blue);

Swapnil Patil
  • 613
  • 6
  • 23

1 Answers1

0

Update: As for the current version of AnyLogic (8.7.7), the modification of the AnyLogic 3D-objects by code does not seem to work (reliably) anymore, even with the procedure described below.

Original Answer:

You need to fix two problems:

  1. Add apostroph symbols for String definition: detector.setColor("Material_(4)_Surf",blue);

  2. Change one (doesn`t matter which one) of the colors in the editor to any other colour (just not default). Otherwise AnyLogic doesnt allow you to modify any colour of this 3D model by code. You need this step to "unlock" the setColor-Code:

Detector setup

If you don't like to keep that color you can then just modify it again at model startup with your detector.setColor(....) method.

Florian
  • 962
  • 1
  • 5
  • 17
  • I cannot get this to work either, even with the suggested instructions. – geoscience123 Dec 04 '20 at 15:04
  • @geoscience123 Currently color ist only changed dealing with the 3D Model. Maybe this is the reason why this fix does not "work". In the anylogic editor it says, that it will be fixed in future versions. – Lennart S. Oct 14 '21 at 08:32
  • I just checked with version 8.7.7. It is true that it does not work anymore reliably as described in my answer above. Sometimes however it still does work, try with the AnyLogic 3D object "locomotive", for this object the command locomotive.setColor("Material_Surf", red) works, but the command locomotive.setColor("Material_2_Surf", red) does not. – Florian Oct 21 '21 at 09:14