Need help scripting Part.makeCompound with ViewObject

Need help, or want to share a macro? Post here!
Mark Szlazak
Posts: 30
Joined: Tue Apr 04, 2017 6:06 pm

Need help scripting Part.makeCompound with ViewObject

Postby Mark Szlazak » Fri Apr 21, 2017 5:29 am

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
Posts: 387
Joined: Tue Dec 31, 2013 4:10 pm
Location: France

Re: Need help scripting Part.makeCompound with ViewObject

Postby Chris_G » Fri Apr 21, 2017 8:19 am

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

Re: Need help scripting Part.makeCompound with ViewObject

Postby ickby » Fri Apr 21, 2017 10:34 am

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: 30
Joined: Tue Apr 04, 2017 6:06 pm

Re: Need help scripting Part.makeCompound with ViewObject

Postby Mark Szlazak » Fri Apr 21, 2017 2:19 pm

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.
DeepSOIC
Posts: 4699
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

Re: Need help scripting Part.makeCompound with ViewObject

Postby DeepSOIC » Fri Apr 21, 2017 10:15 pm

You can create two objects, one with spheres and other with edges ;)
Mark Szlazak
Posts: 30
Joined: Tue Apr 04, 2017 6:06 pm

Re: Need help scripting Part.makeCompound with ViewObject

Postby Mark Szlazak » Sat Apr 22, 2017 5:52 am

Thanks Deep but one object would be preferable.