is there objects inspection tool?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
dprojects
Posts: 721
Joined: Mon Mar 06, 2017 6:02 pm
Location: Poland
Contact:

is there objects inspection tool?

Post by dprojects »

I set color to face for the Cube object and I want to get the color.

For this:

Code: Select all

dir(FreeCAD.ActiveDocument.getObjectsByLabel("MyCube")[0].Shape.Face4)
I have:

Code: Select all

['Area', 'BoundBox', 'CenterOfMass', 'CompSolids', 'Compounds', 'Content', 'Edges', 'Faces', 'Length', 'Mass', 'Matrix', 'MatrixOfInertia', 'MemSize', 'Module', 'Orientation', 'OuterWire', 'ParameterRange', 'Placement', 'PrincipalProperties', 'ShapeType', 'Shells', 'Solids', 'StaticMoments', 'SubShapes', 'Surface', 'Tag', 'Tolerance', 'TypeId', 'Vertexes', 'Volume', 'Wire', 'Wires', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', 'addWire', 'ancestorsOfType', 'check', 'childShapes', 'cleaned', 'common', 'complement', 'copy', 'countElement', 'curvatureAt', 'curveOnSurface', 'cut', 'cutHoles', 'defeaturing', 'derivative1At', 'derivative2At', 'distToShape', 'dumpContent', 'dumpToString', 'exportBinary', 'exportBrep', 'exportBrepToString', 'exportIges', 'exportStep', 'exportStl', 'extrude', 'findPlane', 'fix', 'fixTolerance', 'fuse', 'generalFuse', 'getAllDerivedFrom', 'getElement', 'getFacesFromSubelement', 'getTolerance', 'getUVNodes', 'globalTolerance', 'hashCode', 'importBinary', 'importBrep', 'importBrepFromString', 'inTolerance', 'isClosed', 'isCoplanar', 'isDerivedFrom', 'isEqual', 'isInfinite', 'isInside', 'isNull', 'isPartOfDomain', 'isPartner', 'isSame', 'isValid', 'limitTolerance', 'makeChamfer', 'makeFillet', 'makeHalfSpace', 'makeOffset', 'makeOffset2D', 'makeOffsetShape', 'makeParallelProjection', 'makePerspectiveProjection', 'makeShapeFromMesh', 'makeThickness', 'makeWires', 'mirror', 'multiFuse', 'normalAt', 'nullify', 'oldFuse', 'optimalBoundingBox', 'overTolerance', 'project', 'proximity', 'read', 'reflectLines', 'removeInternalWires', 'removeShape', 'removeSplitter', 'replaceShape', 'restoreContent', 'reverse', 'reversed', 'revolve', 'rotate', 'rotated', 'scale', 'scaled', 'section', 'sewShape', 'slice', 'slices', 'tangentAt', 'tessellate', 'toNurbs', 'transformGeometry', 'transformShape', 'transformed', 'translate', 'translated', 'validate', 'valueAt', 'writeInventor']
Is there any tool to see the content for each item? Something like code, development or objects inspector for XML?
You click the tree item and You see what is there inside?

I want to get color but I also looking for something useful and this is the most annoying part of coding at FreeCAD.


EDIT:

I made one here: https://github.com/dprojects/scanObjects
Last edited by dprojects on Mon Feb 07, 2022 7:37 pm, edited 1 time in total.

Thanks
Darek
github.com/dprojects

workbench for woodworking is available at: github.com/dprojects/Woodworking
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: is there objects inspection tool?

Post by onekk »

color is usually stored in ViewObject component of an object, as a solid has no color, colors are assigned by the "visualization part" of FreeCAD.

Maybe this post will help.

https://forum.freecadweb.org/viewtopic. ... 75#p490375

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
mario52
Veteran
Posts: 4673
Joined: Wed May 16, 2012 2:13 pm

Re: is there objects inspection tool?

Post by mario52 »

Hi

see Couleur différentes sur les faces

Code: Select all

sel = Gui.Selection.getSelection()  # object
print(sel[0].ViewObject.ShapeColor) # shape
print(sel[0].ViewObject.LineColor)  # lines (edge)
print(sel[0].ViewObject.PointColor) # points
print(sel[0].ViewObject.Transparency) # transparence
print(sel[0].ViewObject.DiffuseColor) # all faces of object (RVBT)

Oupss onekk

the decode colors soon in FCInfo ...

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: is there objects inspection tool?

Post by onekk »

This code will work.

Code: Select all

obj = DOC.addObject("Part::Feature", "object")
obj.Shape = Part.makeBox(10,20,10)

color1 = (0.5, 0.5, 0.5)

colors = []
for i in range(0, len(obj.Shape.Faces)):
    colors.append(color1)


colors[5] = (0.1, 0.5, 0.5)

obj.ViewObject.DiffuseColor = colors

DOC.recompute()

print(colors)

print(obj.ViewObject.DiffuseColor)

DOC.recompute()
But you have to guess what face is the number 5 (with a cube is easy as the faces are numbered in a predictable way)

maybe there is a way to obtain the face "name" and then use the name to obtain the index to alter the created DiffuseColor list?

But declaring this a "simple" method is slightly a cheat.

Ideally when creating a solid DiffuseColor "has to be" populated with "one color per face" so modifying a single face will be better.

Or maybe a dictionary with a mapping of colors and face will be exposed.

maybe in getElementColor[fce_index] and getElementColors to obtain all the colors of the faces.

But maybe this is not a great way, as TNP will came into the game.

I wonder how others CADs have solved the question or maybe not CADs but 3d Graphics programs, like Blender, not to copy other programs, but reuse "good practices"

But this is a more "general discussion" and "Feature Request" argument so here is clearly OT.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
mario52
Veteran
Posts: 4673
Joined: Wed May 16, 2012 2:13 pm

Re: is there objects inspection tool?

Post by mario52 »

Hi

@onekk see this macro Couleur différentes sur les faces

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: is there objects inspection tool?

Post by TheMarkster »

Have a look at the Colorize macro. It has code to get the color of the first selected edge, face, or vertex.
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: is there objects inspection tool?

Post by onekk »

@mario532 and @TheMarkster Thanks, I've seen the code in the post linked.

It is not clear if the OP would have the color as a python variable and how he want to utilize it.

I was supposing that he wanted to obtain the color in a "more automated way" than selecting the face with the Gui and running a Macro.

But maybe I was supposing wrong. :D

I have clearly stated the OffTopic of some of my consideration and I don't want to pollute too much this post.

But this argument is very interesting, maybe another Topic would be more appropriate, or maybe continuing in another existing Topic.

Many thanks to all and Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
User avatar
dprojects
Posts: 721
Joined: Mon Mar 06, 2017 6:02 pm
Location: Poland
Contact:

Re: is there objects inspection tool?

Post by dprojects »

I want to get color for object without selection this object. However, I will test all the examples and see if this will be working for my purposes.
Also I was looking for inspecting tool, to not checking all the properties manually. I didn't come across such thing at FreeCAD, anyone?

Thanks
Darek
github.com/dprojects

workbench for woodworking is available at: github.com/dprojects/Woodworking
User avatar
dprojects
Posts: 721
Joined: Mon Mar 06, 2017 6:02 pm
Location: Poland
Contact:

Re: is there objects inspection tool?

Post by dprojects »

This might be useful:

Code: Select all

FreeCAD.ActiveDocument.getObjectsByLabel("MyCube")[0].ViewObject.DiffuseColor
It returns array of tuples I guess in order:

Code: Select all

[
(0.800000011920929, 0.800000011920929, 0.800000011920929, 0.0), 
(0.800000011920929, 0.800000011920929, 0.800000011920929, 0.0), 
(0.800000011920929, 0.800000011920929, 0.800000011920929, 0.0), 
(0.3960784375667572, 0.26274511218070984, 0.12941177189350128, 0.0), 
(0.800000011920929, 0.800000011920929, 0.800000011920929, 0.0), 
(0.800000011920929, 0.800000011920929, 0.800000011920929, 0.0)
]
Only the 4th one is different what means the Face4 is set and this information should be enough for me to determine if the edgeband is covered at this edge or not. OK, thanks.

However, if You know any inspecting tool, I will be interested.

Thanks
Darek
github.com/dprojects

workbench for woodworking is available at: github.com/dprojects/Woodworking
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: is there objects inspection tool?

Post by onekk »

No I don't know any, but @mario52 as said he was implementing something in one of his Macro, if I have catch his suggestion.

In theory you could even color different even edges, but maybe this is more challenging, as if it works like faces, you have to generate a color tuple for every egde and change only desired ones.

It was the center of one of my comments above.

How to have some way to colorize things without having to create the "full tuples", in other word, if the color tuples where created in the phase of the object creation and could be changed simply addressing the proper element....

But this is OT and should be discussed as a "Feature Request" in the Development section.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
Post Reply