Need help, or want to share a macro? Post here!
keithsloan52
Veteran
Posts: 2764 Joined: Mon Feb 27, 2012 5:31 pm
Post
by keithsloan52 » Fri Aug 12, 2022 10:37 am
I have some code that tries to make a single object from a number of Shapes.
Code: Select all
shapes = []
for obj in FreeCAD.ActiveDocument.Objects:
print(obj.Name)
print(obj.Shape)
shapes.append(obj.Shape)
print(f'Shapes {shapes}')
# FreeCAD.closeDocument(docSVG.Name)
FreeCAD.ActiveDocument=doc
obj=doc.addObject('Part::Feature',fname)
# obj.Shape=Part.Compound(shapes)
obj.Shape=Part.makeCompound(shapes)
return obj
This does not seem to work. in all circumstances. i.e. works for 2d shapes like circle but not a series of wires
Don't understand the difference between Part.Compound and Part.makeCompound
With this active document 2d shapes it works
With this active document with wires it fails
Syres
Veteran
Posts: 2902 Joined: Thu Aug 09, 2018 11:14 am
Post
by Syres » Fri Aug 12, 2022 11:06 am
Tested your 'wires only' on three builds with both
Part.Compound and
Part.makeCompound and not a single failure so an actual error message and your full FC info may assist.
Code: Select all
OS: Windows 7
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.4 (GitTag)
Build type: Release
Branch: releases/FreeCAD-0-18
Hash: 980bf9060e28555fecd9e3462f68ca74007b70f8
Python version: 3.6.6
Qt version: 5.6.2
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedKingdom (en_GB)
Code: Select all
OS: Windows 7 Version 6.1 (Build 7601: SP 1)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.24267 +148 (Git)
Build type: Release
Branch: Branch_0.19.4
Hash: 476ecf091941bead59b14e44afa6064d5a66afa3
Python version: 3.8.6+
Qt version: 5.15.2
Coin version: 4.0.1
OCC version: 7.5.3
Locale: English/United Kingdom (en_GB)
Code: Select all
OS: Windows 7 Version 6.1 (Build 7601: SP 1)
Word size of FreeCAD: 64-bit
Version: 0.20.1.29410 (Git)
Build type: Release
Branch: releases/FreeCAD-0-20
Hash: f5d13554ecc7a456fb6e970568ae5c74ba727563
Python 3.8.10, Qt 5.15.2, Coin 4.0.1, Vtk 8.2.0, OCC 7.6.3
Locale: English/United Kingdom (en_GB)
Installed mods:
* A2plus 0.4.56a
* Assembly3 0.11.3
* CfdOF 1.17.7
* Curves 0.5.4
* fasteners 0.3.51
* fcgear 1.0.0
* freecad.xray 2022.4.17
* Manipulator 1.4.9
* Plot 2022.4.17
* sheetmetal 0.2.56
* Silk 1.0.0
heron
Posts: 307 Joined: Mon Apr 20, 2020 5:32 pm
Post
by heron » Fri Aug 12, 2022 11:36 am
It works fine on my side too
Code: Select all
OS: Windows 10 Version 2009
Word size of FreeCAD: 64-bit
Version: 0.21.29936 (Git)
Build type: Release
Branch: master
Hash: 3db79c907cd7ef2f75597efdd82ae288ac23ad01
Python 3.10.5, Qt 5.15.4, Coin 4.0.0, Vtk 9.1.0, OCC 7.6.2
Locale: Spanish/Spain (es_ES)
It is not relationed, but i had to change FreeCAD.ActiveDocument=doc by doc=FreeCAD.ActiveDocument and fname by "fname"
Code: Select all
def shaping():
shapes = []
for obj in FreeCAD.ActiveDocument.Objects:
print(obj.Name)
print(obj.Shape)
shapes.append(obj.Shape)
print(f'Shapes {shapes}')
# FreeCAD.closeDocument(docSVG.Name)
doc = FreeCAD.ActiveDocument
obj = doc.addObject('Part::Feature', 'fname')
#obj.Shape=Part.Compound(shapes)
obj.Shape=Part.makeCompound(shapes)
return obj
shaping()
The error messages you got also may assist.
keithsloan52
Veteran
Posts: 2764 Joined: Mon Feb 27, 2012 5:31 pm
Post
by keithsloan52 » Fri Aug 12, 2022 12:41 pm
Code: Select all
OS: macOS 10.16
Word size of FreeCAD: 64-bit
Version: 0.20.29177 (Git)
Build type: Release
Branch: (HEAD detached at 0.20)
Hash: 68e337670e227889217652ddac593c93b5e8dc94
Python 3.9.13, Qt 5.12.9, Coin 4.0.0, Vtk 9.1.0, OCC 7.5.3
Locale: C/Default (C)
Installed mods:
* GDML 2.0.0
@herons comment on doc, problem with extracting just part of code
Is part of
Code: Select all
def processSVG(fname, ext):
from importSVG import svgHandler
print("SVG Handler")
doc = FreeCAD.ActiveDocument
docSVG = FreeCAD.newDocument(fname+'_tmp')
FreeCAD.ActiveDocument = docSVG
# Set up the parser
parser = xml.sax.make_parser()
parser.setFeature(xml.sax.handler.feature_external_ges, False)
parser.setContentHandler(svgHandler())
parser._cont_handler.doc = docSVG
# pathName is a Global
filename = os.path.join(pathName,fname+'.'+ext)
# Use the native Python open which was saved as `pythonopen`
parser.parse(pythonopen(filename))
# combine SVG objects into one
print('Combining SVG Objects')
shapes = []
for obj in FreeCAD.ActiveDocument.Objects:
print(obj.Name)
print(obj.Shape)
shapes.append(obj.Shape)
# compoundSVG = Part.makeCompound(shapes)
# compoundSVG = Draft.join(objects)
print(f'Shapes {shapes}')
# FreeCAD.closeDocument(docSVG.Name)
FreeCAD.ActiveDocument=doc
obj=doc.addObject('Part::Feature',fname)
# obj.Shape=Part.Compound(shapes)
obj.Shape=Part.makeCompound(shapes)
return obj