Drawing Extraction

Info about new community or project announcements, implemented features, classes, modules or APIs. Might get technical!
PLEASE DO NOT POST HELP REQUESTS OR OTHER DISCUSSIONS HERE!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
jriegel
Founder
Posts: 3369
Joined: Sun Feb 15, 2009 5:29 pm
Location: Ulm, Germany
Contact:

Drawing Extraction

Post by jriegel »

Hi,
on my vacation I finaly got time to finish the technology preview of the Drawing Extraction.
Its located in the Drawing workbench, here a picture of how it works:

http://sourceforge.net/apps/mediawiki/f ... Extraction

its available in V0.9 since Revision 2376

It mainly shows the way to get from a 3D CAD part to a SVG Drawing. The extraction is parametric
and associative, that means if you change the Part the drawing get updated. At the moment I've
implemented a Page feature and a PartView feature. The PartView feature hav propties to control
the scale and the position of the Part view. The Page feature has propties to control the drawing
frame and the page size.

The result is a SVG file which can be further use in e.g. Incscape.

Be aware, its a technology preview and aimed to show whats possible within FreeCAD and with SVG.
Its so far not intended for End-user.

have fun!

Jürgen
Stop whining - start coding!
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Drawing Extraction

Post by yorik »

I just compiled this morning, congrats Jürgen, it's excellent! Already far better than I was hoping!
Some ideas, for the future:

- how does the part -> svg conversion work? It would be nice if somehow the outputted svg code was accessible before going to the drawing sheet. I already imagine all kinds of regexp operations that would add some cool styling to the output... Now that I learned a bit of regex :) You could for example easily change some filled areas with custom hatching, things like that, all from python...

- If you have a model made of many parts, maybe the drawing would become big to manage, with many views inside? In another hand, this is very handy if for example you want to insert different parts at different scales. Maybe if it was possible to produce one view from several selected part objects?
User avatar
jriegel
Founder
Posts: 3369
Joined: Sun Feb 15, 2009 5:29 pm
Location: Ulm, Germany
Contact:

Re: Drawing Extraction

Post by jriegel »

yorikvanhavre wrote: - how does the part -> svg conversion work? It would be nice if somehow the outputted svg code was accessible before going to the drawing sheet. I already imagine all kinds of regexp operations that would add some cool styling to the output... Now that I learned a bit of regex :) You could for example easily change some filled areas with custom hatching, things like that, all from python...
Thought you would like it! ;)

In the Drawing module is a methode project which project a TopoShape and delivers you a result Shape list of visible and hidden edges.
Thise you can iterate and transfer to a SVG. You can then create a view object and insert the SVG fragment.

yorikvanhavre wrote: - If you have a model made of many parts, maybe the drawing would become big to manage, with many views inside? In another hand, this is very handy if for example you want to insert different parts at different scales. Maybe if it was possible to produce one view from several selected part objects?
You can insert some Shapes in a compound shape. And you can insert more then one view into a page, each with different position and scale.
I give you some scripting examples when Im home again.

There are some limitations at the moment. The scaling not working properly (I have got today my SVG bool from O'Raily) I have to tweak the resulting
SVG. The hidden lines are not shown at the moment. Also the circle segments are polygons at the moment - thought SVG is cabable of real circle segments.
You see - still work to do.

But I will surly provide a good python interface to allow people produce any kind of additional SVG output into a page...

Cheers Jürgen
Stop whining - start coding!
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Drawing Extraction

Post by yorik »

It's cool when you are on vacation! :D
User avatar
jriegel
Founder
Posts: 3369
Joined: Sun Feb 15, 2009 5:29 pm
Location: Ulm, Germany
Contact:

Re: Drawing Extraction

Post by jriegel »

Hi,
I put some doc for the Drawing in the Wiki:

https://sourceforge.net/apps/mediawiki/ ... ing_Module

its mainly that scritpt which explains nearly all:

Code: Select all

import Part, Drawing

# create a small sample part
Part.show(Part.makeBox(100,100,100).cut(Part.makeCylinder(80,100)).cut(Part.makeBox(90,40,100)).cut(Part.makeBox(20,85,100)))

# direct projection
Shape = App.ActiveDocument.Shape.Shape
[visibly,hidden] = Drawing.project(Shape)
print "visible edges:", len(visibly.Edges)
print "hidden edges:", len(hidden.Edges)
# all was projected on the Z-plane:
print "Bnd Box shape: X=",Shape.BoundBox.XLength," Y=",Shape.BoundBox.YLength," Z=",Shape.BoundBox.ZLength
print "Bnd Box project: X=",visibly.BoundBox.XLength," Y=",visibly.BoundBox.YLength," Z=",visibly.BoundBox.ZLength

# And now the parametric way:

# insert a Page object and assign a template
App.activeDocument().addObject('Drawing::FeaturePage','Page')
App.activeDocument().Page.Template = 'C:/_SW-Projects/Privat/FreeCAD/FreeCAD_0.9_VC8/Mod/Drawing/Templates/A3_Landscape.svg'

# create a view on the "Shape" object, define the position and scale and assign it to a Page
App.activeDocument().addObject('Drawing::FeatureViewPart','View')
App.activeDocument().View.Source = App.activeDocument().Shape
App.activeDocument().View.Direction = (0.0,0.0,1.0)
App.activeDocument().View.X = 10.0
App.activeDocument().View.Y = 10.0
App.activeDocument().View.Scale = 1.0
App.activeDocument().Page.addObject(App.activeDocument().View)

# creat a second view on the same object:
App.activeDocument().addObject('Drawing::FeatureViewPart','View1')
App.activeDocument().View1.Source = App.activeDocument().Shape
App.activeDocument().View1.Direction = (0.0,0.0,1.0)
App.activeDocument().View1.X = 190.0
App.activeDocument().View1.Y = 30.0
App.activeDocument().View1.Scale = 1.0
App.activeDocument().Page.addObject(App.activeDocument().View1)

App.activeDocument().recompute()

# change something and update:
App.activeDocument().View.X = 30.0
App.activeDocument().View.Y = 30.0
App.activeDocument().View.Scale = 1.5

App.activeDocument().recompute()

# Accessing the bits and peaces:
# get the SVG fragment of a single view
ViewSVG = App.activeDocument().View.ViewResult
print ViewSVG

# get the hole result page (its a file in the document temp dir, only read allowed)
print "Resulting SVG document: ",App.activeDocument().Page.PageResult
file = open(App.activeDocument().Page.PageResult,"r")
print "Result page is ",len(file.readlines())," lines long"
# important, give free the file!
del file

# insert a view with your own content:
App.activeDocument().addObject('Drawing::FeatureView','View2')
App.activeDocument().View2.ViewResult = """<g id="View2"
   stroke="rgb(0, 0, 0)"
   stroke-width="0.35"
   stroke-linecap="butt"
   stroke-linejoin="miter"
   transform="translate(30,30)"
   fill="#00cc00"
  >

 <ellipse cx="40" cy="40" rx="30" ry="15"/>
</g>
"""
App.activeDocument().Page.addObject(App.activeDocument().View2)

App.activeDocument().recompute()

del Shape


results in:

Image
Stop whining - start coding!
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Drawing Extraction

Post by yorik »

This is WICKED!!! Extremely powerful!
rockstar1707
Posts: 5
Joined: Mon Aug 24, 2009 6:15 am

Re: Drawing Extraction

Post by rockstar1707 »

This is absolutely amazing :)

Can it extract only views or cross sections as well? If not, is this maybe planned for the future?
User avatar
jriegel
Founder
Posts: 3369
Joined: Sun Feb 15, 2009 5:29 pm
Location: Ulm, Germany
Contact:

Re: Drawing Extraction

Post by jriegel »

Section is not implemented jet, but is easy, need only a section operation bevor drawing extraction.
I put that on the list!
Stop whining - start coding!
Post Reply