Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] DiffuseColor not properly applied to Part::FeaturePython objects #8340

Closed
2 tasks done
Roy-043 opened this issue Feb 3, 2023 · 2 comments
Closed
2 tasks done
Labels
Bug This issue or PR is related to a bug Coding: Python Coding issue related to Python Color Regarding the color handling Core Issue or PR touches core sections (App, Gui, Base) of FreeCAD WB Part Related to the Part Workbench

Comments

@Roy-043
Copy link
Contributor

Roy-043 commented Feb 3, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Forums discussion

https://forum.freecad.org/viewtopic.php?p=656201#p656201

Version

0.21 (Development)

Full version info

OS: Windows 8.1 Version 6.3 (Build 9600)
Word size of FreeCAD: 64-bit
Version: 0.21.0.31709 (Git)
Build type: Release
Branch: master
Hash: e188802ca6997d2564e7570ab648462e6a059f87
Python 3.10.8, Qt 5.15.6, Coin 4.0.0, Vtk 9.1.0, OCC 7.6.3
Locale: Dutch/Netherlands (nl_NL)
Installed mods:

Subproject(s) affected?

Part

Issue description

Part::FeaturePython objects do not display the DiffuseColor assigned via Python code. You have to use a workaround to update the ViewObject.

  1. Paste the code below in the Python console.
  2. Notice that the box does not show the DiffuseColor.
  3. Workaround: paste my_box.ViewObject.DiffuseColor = my_box.ViewObject.DiffuseColor in the Python console.
# Code based on https://wiki.freecad.org/Create_a_FeaturePython_object_part_II

import FreeCAD as App
import Part

def create(obj_name):
    obj = App.ActiveDocument.addObject('Part::FeaturePython', obj_name)
    box(obj)
    ViewProviderBox(obj.ViewObject)
    obj.ViewObject.DiffuseColor = [(1.0, 0.0, 0.0, 0.0),
                                   (0.0, 1.0, 0.0, 0.0),
                                   (0.0, 0.0, 1.0, 0.0),
                                   (1.0, 1.0, 0.0, 0.0),
                                   (0.0, 1.0, 1.0, 0.0),
                                   (1.0, 0.0, 1.0, 0.0)]
    App.ActiveDocument.recompute()
    return obj

class box():

    def __init__(self, obj):
        obj.Proxy = self
        obj.addProperty('App::PropertyString', 'Description', 'Base', 'Box description').Description = ""
        obj.addProperty('App::PropertyLength', 'Length', 'Dimensions', 'Box length').Length = 10.0
        obj.addProperty('App::PropertyLength', 'Width', 'Dimensions', 'Box width').Width = 10.0
        obj.addProperty('App::PropertyLength', 'Height', 'Dimensions', 'Box height').Height = 10.0

    def execute(self, obj):
        obj.Shape = Part.makeBox(obj.Length, obj.Width, obj.Height)

class ViewProviderBox:

    def __init__(self, obj):
        obj.Proxy = self

    def getDefaultDisplayMode(self):
        return "Flat Lines"

my_box = create("my_box")

# my_box.ViewObject.DiffuseColor = my_box.ViewObject.DiffuseColor

Anything else?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@Roy-043 Roy-043 added Core Issue or PR touches core sections (App, Gui, Base) of FreeCAD WB Part Related to the Part Workbench Coding: Python Coding issue related to Python Color Regarding the color handling Bug This issue or PR is related to a bug labels Feb 3, 2023
@Roy-043
Copy link
Contributor Author

Roy-043 commented Feb 10, 2023

This problem is probably related to #8016. When the DiffuseColor is applied the object still has a null shape and therefore fewer faces than the length of the DiffuseColor list.

@Roy-043
Copy link
Contributor Author

Roy-043 commented Jan 10, 2024

This issue has meanwhile been fixed.

OS: Windows 8 build 9600
Word size of FreeCAD: 64-bit
Version: 0.22.0dev.35554 (Git)
Build type: Release
Branch: main
Hash: 8e2ab9f76888ac4da971f9d5069cec7bcc2b572f
Python 3.10.13, Qt 5.15.8, Coin 4.0.2, Vtk 9.2.6, OCC 7.6.3
Locale: Dutch/Netherlands (nl_NL)
Installed mods:

@Roy-043 Roy-043 closed this as completed Jan 10, 2024
Roy-043 added a commit to Roy-043/FreeCAD that referenced this issue Jan 10, 2024
The function would trigger the creation of duplicate Draft Polar Arrays (only on Linux and only if the Fuse option is selected and the Link Array option deselected).
Forum topic:
https://forum.freecad.org/viewtopic.php?t=84090

The reapply_diffuse_color function is no longer required anyway as Issue FreeCAD#8340 has been fixed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This issue or PR is related to a bug Coding: Python Coding issue related to Python Color Regarding the color handling Core Issue or PR touches core sections (App, Gui, Base) of FreeCAD WB Part Related to the Part Workbench
Projects
None yet
Development

No branches or pull requests

1 participant