Part.Cross_sections Object type

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
mermaldad
Posts: 29
Joined: Mon Feb 24, 2014 11:16 pm

Part.Cross_sections Object type

Post by mermaldad »

I have a question about the type associated with the output of the cross-sections operation on the Part Workbench. I am working with them in a script, and I have found that if I create cross-sections on a fusion, the resulting object is a Part.Feature. However, if I create cross-sections of a simple object, like a pad, the resulting object is of type NoneType. My workaround is to fuse two pads, one contained within the other, but I'd like to know if there is a more elegant way to handle this. For example, can the NoneType cross-sections be converted to something that has a Shape?

OS: Ubuntu 16.04.4 LTS
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.16.6712 (Git)
Build type: None
Branch: releases/FreeCAD-0-16
Hash: da2d364457257a7a8c6fb2137cea12c45becd71a
Python version: 2.7.12
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 6.8.0.oce-0.17
ulrich1a
Veteran
Posts: 1957
Joined: Sun Jul 07, 2013 12:08 pm

Re: Part.Cross_sections Object type

Post by ulrich1a »

Can you supply a sample script, that shows the behavior? It makes it easier to answer.

Ulrich
mermaldad
Posts: 29
Joined: Mon Feb 24, 2014 11:16 pm

Re: Part.Cross_sections Object type

Post by mermaldad »

Here it is. In trying to create it, I discovered an interesting clue: Originally I created and sliced the plain figure, then the compound figure. It worked. Both "_cs" objects were of type "Part:Feature". If, however, I reverse the order as in the code below, the "_cs" object for the plain figure is of type "NoneType".

Code: Select all

# Step 1: Create a new document
App.newDocument("Unnamed")
# Step 5: Use Part:Box to create another cube
App.ActiveDocument.addObject("Part::Box","Box")
App.ActiveDocument.ActiveObject.Label = "Cube"
App.ActiveDocument.recompute()
# Step 6: Use Part:Cylinder to create a cylinder
App.ActiveDocument.addObject("Part::Cylinder","Cylinder")
App.ActiveDocument.ActiveObject.Label = "Cylinder"
App.ActiveDocument.recompute()
# Step 7: Move to cylinder to enclose it within the second cube
App.getDocument("Unnamed").Cylinder.Placement=App.Placement(App.Vector(2.54,2.54,0), App.Rotation(App.Vector(0,0,1),0), App.Vector(0,0,0))
# Step 8: Use Part:Union to fuse the second cube and cylinder together
App.activeDocument().addObject("Part::MultiFuse","Fusion")
App.activeDocument().Fusion.Shapes = [App.activeDocument().Box,App.activeDocument().Cylinder,]
App.ActiveDocument.recompute()
# Step 9: Use Part:Cross Section to create a cross-section object (again auto-generated code)
from FreeCAD import Base
wires=list()
shape=FreeCAD.getDocument("Unnamed").Fusion.Shape
for i in shape.slice(Base.Vector(0,0,1),4.99999):
    wires.append(i)
comp=Part.Compound(wires)
slice=FreeCAD.getDocument("Unnamed").addObject("Part::Feature","Fusion_cs")
slice.Shape=comp
slice.purgeTouched()
del slice,comp,wires,shape

# Step 2: Use Part:Box to create a cube
App.ActiveDocument.addObject("Part::Box","Box")
App.ActiveDocument.ActiveObject.Label = "Cube"
App.ActiveDocument.recompute()
# Step 3: move it from the origin
App.getDocument("Unnamed").Box.Placement=App.Placement(App.Vector(0,25.4,0), App.Rotation(App.Vector(0,0,1),0), App.Vector(0,0,0))
# Step 4: Use Part:Cross Sections to create a cross section object; note that the code here was auto-generated
from FreeCAD import Base
wires=list()
shape=FreeCAD.getDocument("Unnamed").Box.Shape
for i in shape.slice(Base.Vector(0,0,1),4.99999):
    wires.append(i)
comp=Part.Compound(wires)
slice=FreeCAD.getDocument("Unnamed").addObject("Part::Feature","Box_cs")
slice.Shape=comp
slice.purgeTouched()
del slice,comp,wires,shape

# Step 10: Examine objects in model
ob = FreeCAD.getDocument("Unnamed").getObject("Fusion")
print("type(Fusion): ",type(ob))
ob = FreeCAD.getDocument("Unnamed").getObject("Fusion_cs")
print('type(Fusion_cs): ', type(ob))
ob = FreeCAD.getDocument("Unnamed").getObject("Box001")
print("type(Box001): ",type(ob))
ob = FreeCAD.getDocument("Unnamed").getObject("Box001_cs")
print('type(Box001_cs): ', type(ob))
with output:
('type(Fusion): ', <type 'Part.Feature'>)
('type(Fusion_cs): ', <type 'Part.Feature'>)
('type(Box001): ', <type 'Part.Feature'>)
('type(Box001_cs): ', <type 'NoneType'>)
Post Reply