Fast way to import external face geometry into sketch?
Forum rules
and Helpful information
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help
Also, be nice to others! Read the FreeCAD code of conduct!
Also, be nice to others! Read the FreeCAD code of conduct!
Fast way to import external face geometry into sketch?
my workflow:
1. create shape
2. shapebinder faces i want to unfold
3. convert shapebinder to mesh
4. unfold mesh
5. padd unfolded mesh to get a part (1mm)
6. Create sketch on unfolded part
7. Import all the edges of the unfolded part <-- this is REALLY slow because you can only import one line at a time. is there a faster way to do this?
8. Add extra geometry for foam cutting process.
9. Export sketch to SVG
10. layout plans for cutting.
I have tried doing draft -> sketch but when you do that, it all comes in unconstrained and when you start adding extra geometry everything goes sideways. Importing external geometry ensures that everything stays where it should be.
This workflow works, but wow is it slow. All i really need is "import external geometry with chaining" so all lines connected to the imported line also get imported.
anyway, I've attached the file if anyone has a suggestion for how to improve my workflow.
Thanks,
1. create shape
2. shapebinder faces i want to unfold
3. convert shapebinder to mesh
4. unfold mesh
5. padd unfolded mesh to get a part (1mm)
6. Create sketch on unfolded part
7. Import all the edges of the unfolded part <-- this is REALLY slow because you can only import one line at a time. is there a faster way to do this?
8. Add extra geometry for foam cutting process.
9. Export sketch to SVG
10. layout plans for cutting.
I have tried doing draft -> sketch but when you do that, it all comes in unconstrained and when you start adding extra geometry everything goes sideways. Importing external geometry ensures that everything stays where it should be.
This workflow works, but wow is it slow. All i really need is "import external geometry with chaining" so all lines connected to the imported line also get imported.
anyway, I've attached the file if anyone has a suggestion for how to improve my workflow.
Thanks,
- Attachments
-
- FoamBoardFloats.FCStd
- (107.74 KiB) Downloaded 38 times
-
- Veteran
- Posts: 5505
- Joined: Thu Apr 05, 2018 1:53 am
Re: Fast way to import external face geometry into sketch?
This macro might help you.
Code: Select all
# -*- coding: utf-8 -*-
# sketcher_add_subobjects_as_external.FCMacro, 2021 by <TheMarkster>
# add as external links to selected sketch all selected subobjects if subojects selected
# else add all edges of selected object to selected sketch
# if 2 or more sketches are selected the first selected gets the external links added to it
# using visible edges (non external and non constructive) from 2nd sketch and any other additional objects selected
sketch = None
subobjects = []
def addSubs(selobj,subs):
if not selobj.HasSubObjects:
#assumption: user wants to add all edges of selected object to the sketch
ii = 1
for edge in selobj.Object.Shape.Edges:
subs.append((selobj.Object.Name,"Edge"+str(ii)))
ii += 1
else: #user has selected some subobjects, so we will add all selected edges and vertices (but not faces)
for sen in selobj.SubElementNames:
if "Edge" in sen or "Vertex" in sen:
subs.append((selobj.Object.Name,sen))
sel = FreeCADGui.Selection.getSelectionEx()
for s in sel:
if s.Object.TypeId == "Sketcher::SketchObject":
if sketch:
addSubs(s,subobjects) #assumption: user wants to add edges from 2nd sketch as external links in first sketch
else:
sketch = s.Object
continue
else:
addSubs(s,subobjects)
if sketch and len(subobjects) != 0:
for sub in subobjects:
FreeCAD.Console.PrintMessage("Adding "+sub[0]+"."+sub[1]+" as external geometry to "+sketch.Label)
try:
sketch.addExternal(sub[0], sub[1])
FreeCAD.Console.PrintMessage("...success\n")
except:
FreeCAD.Console.PrintError("...failure\n")
elif sketch:
FreeCAD.Console.PrintError("No subobjects to add.\n")
else:
FreeCAD.Console.PrintError("No sketch selected.\n")
- thomas-neemann
- Veteran
- Posts: 11801
- Joined: Wed Jan 22, 2020 6:03 pm
- Location: Osnabrück DE 🇩🇪
- Contact:
Re: Fast way to import external face geometry into sketch?
it could be that "defining edge" from the realthunder version does your job quickly and automatically. seen here
https://www.youtube.com/watch?v=oQklf1mP_j8
Re: Fast way to import external face geometry into sketch?
Thanks, reading the macro this seems to do exactly what I wanted which would be "import external edge - chained select"
I'll give it a try tonight.
I'll give it a try tonight.
-
- Veteran
- Posts: 5505
- Joined: Thu Apr 05, 2018 1:53 am
Re: Fast way to import external face geometry into sketch?
I have revised the macro slightly to allow for faces to also be selected and added. I'm not sure the sketcher really works well with faces, but it does work. When I tried it on a cube the external lines extended far beyond the boundary of the selected faces. Edge selection will probably work better, but will also be more tedious.
Code: Select all
# -*- coding: utf-8 -*-
# sketcher_add_subobjects_as_external.FCMacro, 2021 by <TheMarkster>
# add as external links to selected sketch all selected subobjects if subojects selected
# else add all edges of selected object to selected sketch
# if 2 or more sketches are selected the first selected gets the external links added to it
# using visible edges (non external and non constructive) from 2nd sketch and any other additional objects selected
sketch = None
subobjects = []
def addSubs(selobj,subs):
if not selobj.HasSubObjects:
#assumption: user wants to add all edges of selected object to the sketch
ii = 1
for edge in selobj.Object.Shape.Edges:
subs.append((selobj.Object.Name,"Edge"+str(ii)))
ii += 1
else: #user has selected some subobjects, so we will add all selected edges and vertices and faces
for sen in selobj.SubElementNames:
subs.append((selobj.Object.Name,sen))
sel = FreeCADGui.Selection.getSelectionEx()
for s in sel:
if s.Object.TypeId == "Sketcher::SketchObject":
if sketch:
addSubs(s,subobjects) #assumption: user wants to add edges from 2nd sketch as external links in first sketch
else:
sketch = s.Object
continue
else:
addSubs(s,subobjects)
if sketch and len(subobjects) != 0:
for sub in subobjects:
FreeCAD.Console.PrintMessage("Adding "+sub[0]+"."+sub[1]+" as external geometry to "+sketch.Label)
try:
sketch.addExternal(sub[0], sub[1])
FreeCAD.Console.PrintMessage("...success\n")
except:
FreeCAD.Console.PrintError("...failure\n")
elif sketch:
FreeCAD.Console.PrintError("No subobjects to add.\n")
else:
FreeCAD.Console.PrintError("No sketch selected.\n")
Re: Fast way to import external face geometry into sketch?
Okay i finally got a chance to try this. but I can't seem to get it to do anything. What would be the correct order of operations to use it? I can't select a face (or an edge) and select the sketch at the same time. Could you give a quick how to?
-
- Veteran
- Posts: 5505
- Joined: Thu Apr 05, 2018 1:53 am
Re: Fast way to import external face geometry into sketch?
Hold down Ctrl key to multiple select. Select the edges/faces/vertices in the 3d view and the sketch in the tree view.
Re: Fast way to import external face geometry into sketch?
Once again, thank you for the help. But for the life of me I cannot get the script to work. I'm getting:
"import_Chained.FCMacro", line 40, in <module>
sketch.addExternal(sub[0],sub[1])
<class 'ValueError'>: Expect either document object or tuple(obj, subname)"
I'm running LinkStage3 if that could make a difference.
Thanks.
"import_Chained.FCMacro", line 40, in <module>
sketch.addExternal(sub[0],sub[1])
<class 'ValueError'>: Expect either document object or tuple(obj, subname)"
I'm running LinkStage3 if that could make a difference.
Thanks.
-
- Veteran
- Posts: 5505
- Joined: Thu Apr 05, 2018 1:53 am
Re: Fast way to import external face geometry into sketch?
It might not be compatible for some reason with linkstage3. I have revised it. You can try and see if it works.
Code: Select all
# -*- coding: utf-8 -*-
# sketcher_add_subobjects_as_external.FCMacro, 2021 by <TheMarkster>
# add as external links to selected sketch all selected subobjects if subojects selected
# else add all edges of selected object to selected sketch
# if 2 or more sketches are selected the first selected gets the external links added to it
# using visible edges (non external and non constructive) from 2nd sketch and any other additional objects selected
sketch = None
subobjects = []
def addSubs(selobj,subs):
if not selobj.HasSubObjects:
#assumption: user wants to add all edges of selected object to the sketch
ii = 1
for edge in selobj.Object.Shape.Edges:
subs.append((selobj.Object,"Edge"+str(ii)))
ii += 1
else: #user has selected some subobjects, so we will add all selected edges and vertices and faces
for sen in selobj.SubElementNames:
subs.append((selobj.Object,sen))
sel = FreeCADGui.Selection.getSelectionEx()
for s in sel:
if s.Object.TypeId == "Sketcher::SketchObject":
if sketch:
addSubs(s,subobjects) #assumption: user wants to add edges from 2nd sketch as external links in first sketch
else:
sketch = s.Object
continue
else:
addSubs(s,subobjects)
if sketch and len(subobjects) != 0:
for sub in subobjects:
FreeCAD.Console.PrintMessage("Adding "+sub[0].Name+"."+sub[1]+" as external geometry to "+sketch.Label)
try:
sketch.addExternal(sub[0], sub[1])
FreeCAD.Console.PrintMessage("...success\n")
except:
try:
sketch.addExternal(sub[0].Name, sub[1])
FreeCAD.Console.PrintMessage("...success\n")
except:
FreeCAD.Console.PrintError("...failure\n")
elif sketch:
FreeCAD.Console.PrintError("No subobjects to add.\n")
else:
FreeCAD.Console.PrintError("No sketch selected.\n")
Re: Fast way to import external face geometry into sketch?
Still fails. error below. I'm chosing just one edge from Extrude001 along the top face of the extrude and trying to import that into Sketch 002.
Again thank you for the assistance.
Again thank you for the assistance.
Code: Select all
# -*- coding: utf-8 -*-
20:22:47 Adding Extrude001.Edge1251 as external geometry to Sketch002<Sketch> Import_Chained3.FCMacro(37)|SketchObject.cpp(7433): Unknown type of geometry in FoamBoardFloats#Sketch002: Extrude001.
20:22:47 ...failure