Need help scripting Part.makeCompound with ViewObject

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
Mark Szlazak
Posts: 439
Joined: Tue Apr 04, 2017 6:06 pm
Location: SF Bay Area, California

Need help scripting Part.makeCompound with ViewObject

Post by Mark Szlazak »

I would like to combine a group of edges of certain thickness and colour with spheres that represent intersection points of these edges. The code i used is:

Code: Select all

s1 = doc.addObject("Part::Feature", "s1")
s1.Shape = Part.makeCompound([Part.Shape([Part.Line(dts2[0], dts2[1]),
              Part.Line(e3.Shape.Vertexes[0].Point, e3.Shape.Vertexes[1].Point),
              Part.Line(e6.Shape.Vertexes[0].Point, e6.Shape.Vertexes[1].Point)]),
              Part.makeSphere(mediumPointRadius, dts2[0]),
              Part.makeSphere(mediumPointRadius, dts2[1])])
s1.ViewObject.LineWidth = width2
s1.ViewObject.DisplayMode = 'Shaded'
The problem is with using s1.ViewObject.DisplayMode = 'Shaded'
This causes all the edges to disappear and just leaves the sphere visible in this display mode.
How should i go about making this kind of structure?
User avatar
Chris_G
Veteran
Posts: 2579
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Need help scripting Part.makeCompound with ViewObject

Post by Chris_G »

Hi,
You need to create your own featurePython object (and its viewprovider) to make your own custom displaymode (see here)
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: Need help scripting Part.makeCompound with ViewObject

Post by ickby »

Shaded is a display mode that only presents faces. Lines are not shown in this mode (as they have no surface). Hence you just need to change the display mode to something else and everything will reaper, or just don't set it at all, as the default will show the lines too.
Mark Szlazak
Posts: 439
Joined: Tue Apr 04, 2017 6:06 pm
Location: SF Bay Area, California

Re: Need help scripting Part.makeCompound with ViewObject

Post by Mark Szlazak »

Thanks for the help Chris and the explanation Ickby. If i use black for everything then that gives me the desired but colour restricted effect. To bad there isn't an easier way.
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Need help scripting Part.makeCompound with ViewObject

Post by DeepSOIC »

You can create two objects, one with spheres and other with edges ;)
Mark Szlazak
Posts: 439
Joined: Tue Apr 04, 2017 6:06 pm
Location: SF Bay Area, California

Re: Need help scripting Part.makeCompound with ViewObject

Post by Mark Szlazak »

Thanks Deep but one object would be preferable.
Post Reply