How do I create a solid from ruled surfaces and faces?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
more11
Posts: 124
Joined: Sun Sep 28, 2014 11:03 am
Contact:

How do I create a solid from ruled surfaces and faces?

Post by more11 »

I have created ruled surfaces and faces in python. Now I want to create a solid from these.

First step was to create a shell, but that didn't work.

Code: Select all

shell = Part.makeShell(surfaces)
Part.show(shell)
This are the functions I use to populate surfaces:

Code: Select all

surface = Part.makeRuledSurface(wire, wire_1)
surfaces.append(surface)

Code: Select all

face = Part.Face(w)
surfaces.append(face)
Point taken :-)
ulrich1a
Veteran
Posts: 1957
Joined: Sun Jul 07, 2013 12:08 pm

Re: How do I create a solid from ruled surfaces and faces?

Post by ulrich1a »

more11 wrote:First step was to create a shell, but that didn't work.
It is difficult to say, what went wrong with the given information.
I would do: Part.show(surface) in the script or in the python console. And do the same with the other faces to. Typically you will see, what problem is there. It could be, that a face is not created due to problems in the underlaying geometry. It could be wrong orientation of wires, or different number of vertices in the wires or other problems.
You may have to further debug with Part.show(wire) and Part.show(wire_1)
If all faces do show up, try to make the shell with the gui commands.
I had cases, where it was possible to make the shell with the gui, but not with the script. I had to tune the script in this case.

Ulrich
more11
Posts: 124
Joined: Sun Sep 28, 2014 11:03 am
Contact:

Re: How do I create a solid from ruled surfaces and faces?

Post by more11 »

The problem seems to be the ruled surfaces. I cannot make shells from them in the Gui.

Image

The cad file
Point taken :-)
User avatar
NormandC
Veteran
Posts: 18589
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: How do I create a solid from ruled surfaces and faces?

Post by NormandC »

Your file has an insanely high number of faces to join. Maybe that's the problem?

Can't you extrapolate a BSpline curve rather than having so many little straight segments to create faces from?
more11
Posts: 124
Joined: Sun Sep 28, 2014 11:03 am
Contact:

Re: How do I create a solid from ruled surfaces and faces?

Post by more11 »

The problem is that the ruled suface is made from a Part.wire. The half circle Shape006 has few edges, and it cannot be added to a shell.

The Draft.BSpline is much better than both Draft.Dwire and Part.wire since the ruled surface is creted to the end. Making a ruled surface of a BSpline is much faster as well.

Thanks normandc!
Point taken :-)
more11
Posts: 124
Joined: Sun Sep 28, 2014 11:03 am
Contact:

Re: How do I create a solid from ruled surfaces and faces?

Post by more11 »

Now it looks like this with BSplines instead of dwires:

Image

It is possible to create a shell in the gui, but not in code.

The drawing

I have created a small script which tries to create a shell from the objects in the file. I have also tried to reuse the code from the gui when creating the shell in the gui.

This is the script:

Code: Select all

import FreeCAD,Draft
import Part

surfaces = []
doc = FreeCAD.ActiveDocument
objs = doc.Objects
 
for obj in objs:
	surfaces.append(obj)
	a = obj.Name     # list the Name  of the object  (not modifiable)
	b = obj.Label      # list the Label of the object  (modifiable)
	try:
		c = obj.LabelText     # list the LabeText of the text (modifiable)
		print str(a) +" "+ str(b) +" "+ str(c)  # Displays the Name the Label and the text
	except:
		print str(a) +" "+ str(b)  # Displays the Name and the Label of the object

shell = Part.makeShell(surfaces)
Part.show(shell)
#shell = Part.Shell(surfaces)
#App.ActiveDocument.addObject('Part::Feature','Shell').Shape=shell.removeSplitter()
Gui.updateGui()
Point taken :-)
User avatar
shoogen
Veteran
Posts: 2823
Joined: Thu Dec 01, 2011 5:24 pm

Re: How do I create a solid from ruled surfaces and faces?

Post by shoogen »

Your shell is not closed. You need to add a top and a bottom face. You can create those faces by using something like

Code: Select all

topface=Part.Face(topwire)
ulrich1a
Veteran
Posts: 1957
Joined: Sun Jul 07, 2013 12:08 pm

Re: How do I create a solid from ruled surfaces and faces?

Post by ulrich1a »

more11 wrote:for obj in objs:
surfaces.append(obj)
The following code works for me:

Code: Select all

for obj in objs:
   for s_faces in obj.Shape.Faces:
      surfaces.append(s_faces)
Ulrich
more11
Posts: 124
Joined: Sun Sep 28, 2014 11:03 am
Contact:

Re: How do I create a solid from ruled surfaces and faces?

Post by more11 »

Thanks shoogen and Ulrich!

The only shape I still have problems with is ruled surface with bspline. I have made a script to make this:

Image

Only the end faces are included in the shell.

Code: Select all

import math
import Draft
import Part
import FreeCAD

def frange(x, y, jump):
  while x < y:
    yield x
    x += jump

doc = FreeCAD.newDocument()
Gui.activeDocument().activeView().viewAxometric()
circle_1 = None
radius = 50
center = (0, 100.0, 0.0)
surfaces = []
for angle_i in frange(0.0, 95.0, 15.0):
	circle_points = []
	for circ_angle in frange(15.0, 360.0, 15.0):
		point = (center[0] + math.sin(math.radians(circ_angle)) * radius, center[1] + math.cos(math.radians(circ_angle)) * radius, center[2])
		circle_point = FreeCAD.Vector(point[0], point[1], point[2])
		circle_points.append(circle_point)
	circle = Draft.makeBSpline(circle_points, closed=True, face=False)
	if circle_1 != None:
		Draft.rotate(circle, angle_i, axis = FreeCAD.Vector(1.0, 0.0, 0.0))
		FreeCAD.ActiveDocument.addObject('Part::RuledSurface', 'Ruled Surface')
		circle_surface = FreeCAD.ActiveDocument.ActiveObject
		circle_surface.Curve1=(circle,[''])
		circle_surface.Curve2=(circle_1,[''])
		for f in circle_surface.Shape.Faces:
			surfaces.append(f) # not working
	if angle_i == 0.0 or angle_i == 90.0:
		end = Part.makeFilledFace([circle.Shape.Edge1])
		surfaces.append(end) # this works
	doc.recompute()
	Gui.SendMsgToActiveView("ViewFit")
	Gui.updateGui()
	circle_1 = circle
	
shell = Part.makeShell(surfaces)
Part.show(shell)
Point taken :-)
ulrich1a
Veteran
Posts: 1957
Joined: Sun Jul 07, 2013 12:08 pm

Re: How do I create a solid from ruled surfaces and faces?

Post by ulrich1a »

This works for me:

Code: Select all

import math
import Draft
import Part
import FreeCAD

def frange(x, y, jump):
  while x < y:
    yield x
    x += jump

doc = FreeCAD.newDocument()
Gui.activeDocument().activeView().viewAxometric()
circle_1 = None
radius = 50
center = (0, 100.0, 0.0)
surfaces = []
for angle_i in frange(0.0, 95.0, 15.0):
   circle_points = []
   for circ_angle in frange(15.0, 360.0, 15.0):
      point = (center[0] + math.sin(math.radians(circ_angle)) * radius, center[1] + math.cos(math.radians(circ_angle)) * radius, center[2])
      circle_point = FreeCAD.Vector(point[0], point[1], point[2])
      circle_points.append(circle_point)
   circle = Draft.makeBSpline(circle_points, closed=True, face=False)
   if circle_1 != None:
      Draft.rotate(circle, angle_i, axis = FreeCAD.Vector(1.0, 0.0, 0.0))
      sector = Part.makeRuledSurface (circle.Shape, circle_1.Shape)
      for f in sector.Faces:
         surfaces.append(f) # now it works
   if angle_i == 0.0 or angle_i == 90.0:
      end = Part.makeFilledFace([circle.Shape.Edge1])
      surfaces.append(end) # this works
   doc.recompute()
   Gui.SendMsgToActiveView("ViewFit")
   Gui.updateGui()
   circle_1 = circle
   
shell = Part.makeShell(surfaces)
Part.show(shell)

Ulrich
Post Reply