Draft: added getShapes() function to DXF import
You can now use importDXF.getShapes(filename) to get a list of shapes from a DXF file
This commit is contained in:
parent
00d3a5d619
commit
4e656dd5d5
|
@ -966,7 +966,7 @@ def addToBlock(obj,layer):
|
||||||
else:
|
else:
|
||||||
layerBlocks[layer] = [obj]
|
layerBlocks[layer] = [obj]
|
||||||
|
|
||||||
def processdxf(document,filename):
|
def processdxf(document,filename,getShapes=False):
|
||||||
"this does the translation of the dxf contents into FreeCAD Part objects"
|
"this does the translation of the dxf contents into FreeCAD Part objects"
|
||||||
global drawing # for debugging - so drawing is still accessible to python after the script ran
|
global drawing # for debugging - so drawing is still accessible to python after the script ran
|
||||||
FreeCAD.Console.PrintMessage("opening "+filename+"...\n")
|
FreeCAD.Console.PrintMessage("opening "+filename+"...\n")
|
||||||
|
@ -1003,7 +1003,7 @@ def processdxf(document,filename):
|
||||||
sketch = shape
|
sketch = shape
|
||||||
else:
|
else:
|
||||||
shape = Draft.makeSketch(shape,autoconstraints=True)
|
shape = Draft.makeSketch(shape,autoconstraints=True)
|
||||||
elif dxfJoin:
|
elif dxfJoin or getShapes:
|
||||||
if isinstance(shape,Part.Shape):
|
if isinstance(shape,Part.Shape):
|
||||||
shapes.append(shape)
|
shapes.append(shape)
|
||||||
else:
|
else:
|
||||||
|
@ -1048,7 +1048,7 @@ def processdxf(document,filename):
|
||||||
sketch = shape
|
sketch = shape
|
||||||
else:
|
else:
|
||||||
shape = Draft.makeSketch(shape,autoconstraints=True)
|
shape = Draft.makeSketch(shape,autoconstraints=True)
|
||||||
elif dxfJoin:
|
elif dxfJoin or getShapes:
|
||||||
if isinstance(shape,Part.Shape):
|
if isinstance(shape,Part.Shape):
|
||||||
shapes.append(shape)
|
shapes.append(shape)
|
||||||
else:
|
else:
|
||||||
|
@ -1077,7 +1077,7 @@ def processdxf(document,filename):
|
||||||
sketch = shape
|
sketch = shape
|
||||||
else:
|
else:
|
||||||
shape = Draft.makeSketch(shape,autoconstraints=True)
|
shape = Draft.makeSketch(shape,autoconstraints=True)
|
||||||
elif dxfJoin:
|
elif dxfJoin or getShapes:
|
||||||
if isinstance(shape,Part.Shape):
|
if isinstance(shape,Part.Shape):
|
||||||
shapes.append(shape)
|
shapes.append(shape)
|
||||||
else:
|
else:
|
||||||
|
@ -1118,6 +1118,11 @@ def processdxf(document,filename):
|
||||||
shape = Draft.makeSketch(shape,autoconstraints=True)
|
shape = Draft.makeSketch(shape,autoconstraints=True)
|
||||||
elif dxfMakeBlocks:
|
elif dxfMakeBlocks:
|
||||||
addToBlock(shape,circle.layer)
|
addToBlock(shape,circle.layer)
|
||||||
|
elif getShapes:
|
||||||
|
if isinstance(shape,Part.Shape):
|
||||||
|
shapes.append(shape)
|
||||||
|
else:
|
||||||
|
shapes.append(shape.Shape)
|
||||||
else:
|
else:
|
||||||
newob = addObject(shape,"Circle",circle.layer)
|
newob = addObject(shape,"Circle",circle.layer)
|
||||||
if gui: formatObject(newob,circle)
|
if gui: formatObject(newob,circle)
|
||||||
|
@ -1133,6 +1138,11 @@ def processdxf(document,filename):
|
||||||
if shape:
|
if shape:
|
||||||
if dxfMakeBlocks:
|
if dxfMakeBlocks:
|
||||||
addToBlock(shape,lay)
|
addToBlock(shape,lay)
|
||||||
|
elif getShapes:
|
||||||
|
if isinstance(shape,Part.Shape):
|
||||||
|
shapes.append(shape)
|
||||||
|
else:
|
||||||
|
shapes.append(shape.Shape)
|
||||||
else:
|
else:
|
||||||
newob = addObject(shape,"Solid",lay)
|
newob = addObject(shape,"Solid",lay)
|
||||||
if gui: formatObject(newob,solid)
|
if gui: formatObject(newob,solid)
|
||||||
|
@ -1148,6 +1158,11 @@ def processdxf(document,filename):
|
||||||
if shape:
|
if shape:
|
||||||
if dxfMakeBlocks:
|
if dxfMakeBlocks:
|
||||||
addToBlock(shape,lay)
|
addToBlock(shape,lay)
|
||||||
|
elif getShapes:
|
||||||
|
if isinstance(shape,Part.Shape):
|
||||||
|
shapes.append(shape)
|
||||||
|
else:
|
||||||
|
shapes.append(shape.Shape)
|
||||||
else:
|
else:
|
||||||
newob = addObject(shape,"Spline",lay)
|
newob = addObject(shape,"Spline",lay)
|
||||||
if gui: formatObject(newob,spline)
|
if gui: formatObject(newob,spline)
|
||||||
|
@ -1163,6 +1178,11 @@ def processdxf(document,filename):
|
||||||
if shape:
|
if shape:
|
||||||
if dxfMakeBlocks:
|
if dxfMakeBlocks:
|
||||||
addToBlock(shape,lay)
|
addToBlock(shape,lay)
|
||||||
|
elif getShapes:
|
||||||
|
if isinstance(shape,Part.Shape):
|
||||||
|
shapes.append(shape)
|
||||||
|
else:
|
||||||
|
shapes.append(shape.Shape)
|
||||||
else:
|
else:
|
||||||
newob = addObject(shape,"Ellipse",lay)
|
newob = addObject(shape,"Ellipse",lay)
|
||||||
if gui: formatObject(newob,ellipse)
|
if gui: formatObject(newob,ellipse)
|
||||||
|
@ -1187,8 +1207,14 @@ def processdxf(document,filename):
|
||||||
for face3d in faces3d:
|
for face3d in faces3d:
|
||||||
shape = drawFace(face3d)
|
shape = drawFace(face3d)
|
||||||
if shape:
|
if shape:
|
||||||
newob = addObject(shape,"Face",face3d.layer)
|
if getShapes:
|
||||||
if gui: formatObject(newob,face3d)
|
if isinstance(shape,Part.Shape):
|
||||||
|
shapes.append(shape)
|
||||||
|
else:
|
||||||
|
shapes.append(shape.Shape)
|
||||||
|
else:
|
||||||
|
newob = addObject(shape,"Face",face3d.layer)
|
||||||
|
if gui: formatObject(newob,face3d)
|
||||||
if meshes: FreeCAD.Console.PrintMessage("drawing "+str(len(meshes))+" 3dmeshes...\n")
|
if meshes: FreeCAD.Console.PrintMessage("drawing "+str(len(meshes))+" 3dmeshes...\n")
|
||||||
for mesh in meshes:
|
for mesh in meshes:
|
||||||
me = drawMesh(mesh)
|
me = drawMesh(mesh)
|
||||||
|
@ -1199,6 +1225,11 @@ def processdxf(document,filename):
|
||||||
newob.Mesh = me
|
newob.Mesh = me
|
||||||
if gui: formatObject(newob,mesh)
|
if gui: formatObject(newob,mesh)
|
||||||
|
|
||||||
|
# end of shape-based objects, return if we are just getting shapes
|
||||||
|
|
||||||
|
if getShapes and shapes:
|
||||||
|
return(shapes)
|
||||||
|
|
||||||
# drawing dims
|
# drawing dims
|
||||||
|
|
||||||
if dxfImportTexts:
|
if dxfImportTexts:
|
||||||
|
@ -1420,6 +1451,11 @@ def insert(filename,docname):
|
||||||
for l in layers:
|
for l in layers:
|
||||||
importgroup.addObject(l)
|
importgroup.addObject(l)
|
||||||
|
|
||||||
|
def getShapes(filename):
|
||||||
|
"reads a dxf file and returns a list of shapes from its contents"
|
||||||
|
if dxfReader:
|
||||||
|
return processdxf(None,filename,getShapes=True)
|
||||||
|
|
||||||
|
|
||||||
# EXPORT ########################################################################
|
# EXPORT ########################################################################
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user