00001
00002
00003
00004 import FreeCAD, Part, Drawing
00005
00006
00007 Part.show(Part.makeBox(100,100,100).cut(Part.makeCylinder(80,100)).cut(Part.makeBox(90,40,100)).cut(Part.makeBox(20,85,100)))
00008
00009
00010 Shape = App.ActiveDocument.Shape.Shape
00011 [visiblyG0,visiblyG1,hiddenG0,hiddenG1] = Drawing.project(Shape)
00012 print "visible edges:", len(visiblyG0.Edges)
00013 print "hidden edges:", len(hiddenG0.Edges)
00014
00015 print "Bnd Box shape: X=",Shape.BoundBox.XLength," Y=",Shape.BoundBox.YLength," Z=",Shape.BoundBox.ZLength
00016 print "Bnd Box project: X=",visiblyG0.BoundBox.XLength," Y=",visiblyG0.BoundBox.YLength," Z=",visiblyG0.BoundBox.ZLength
00017
00018
00019 [visiblyG0,visiblyG1,hiddenG0,hiddenG1] = Drawing.project(Shape,Base.Vector(1,1,1))
00020
00021
00022 resultSVG = Drawing.projectToSVG(Shape,App.Vector(1,1,1))
00023 print resultSVG
00024
00025
00026
00027
00028 App.activeDocument().addObject('Drawing::FeaturePage','Page')
00029 App.activeDocument().Page.Template = App.ConfigGet('AppHomePath')+'Mod/Drawing/Templates/A3_Landscape.svg'
00030
00031
00032 App.activeDocument().addObject('Drawing::FeatureViewPart','View')
00033 App.activeDocument().View.Source = App.activeDocument().Shape
00034 App.activeDocument().View.Direction = (0.0,0.0,1.0)
00035 App.activeDocument().View.X = 10.0
00036 App.activeDocument().View.Y = 10.0
00037 App.activeDocument().Page.addObject(App.activeDocument().View)
00038
00039
00040
00041 App.activeDocument().addObject('Drawing::FeatureViewPart','ViewRot')
00042 App.activeDocument().ViewRot.Source = App.activeDocument().Shape
00043 App.activeDocument().ViewRot.Direction = (0.0,0.0,1.0)
00044 App.activeDocument().ViewRot.X = 290.0
00045 App.activeDocument().ViewRot.Y = 30.0
00046 App.activeDocument().ViewRot.Scale = 1.0
00047 App.activeDocument().ViewRot.Rotation = 90.0
00048 App.activeDocument().Page.addObject(App.activeDocument().ViewRot)
00049
00050
00051
00052
00053 App.activeDocument().addObject('Drawing::FeatureViewPart','ViewIso')
00054 App.activeDocument().ViewIso.Source = App.activeDocument().Shape
00055 App.activeDocument().ViewIso.Direction = (1.0,1.0,1.0)
00056 App.activeDocument().ViewIso.X = 335.0
00057 App.activeDocument().ViewIso.Y = 140.0
00058 App.activeDocument().ViewIso.ShowHiddenLines = True
00059 App.activeDocument().Page.addObject(App.activeDocument().ViewIso)
00060
00061
00062
00063 App.activeDocument().View.X = 30.0
00064 App.activeDocument().View.Y = 30.0
00065 App.activeDocument().View.Scale = 1.5
00066 App.activeDocument().recompute()
00067
00068
00069
00070 ViewSVG = App.activeDocument().View.ViewResult
00071 print ViewSVG
00072
00073
00074 print "Resulting SVG document: ",App.activeDocument().Page.PageResult
00075 file = open(App.activeDocument().Page.PageResult,"r")
00076 print "Result page is ",len(file.readlines())," lines long"
00077
00078 del file
00079
00080
00081 App.activeDocument().addObject('Drawing::FeatureView','ViewSelf')
00082 App.activeDocument().ViewSelf.ViewResult = """<g id="ViewSelf"
00083 stroke="rgb(0, 0, 0)"
00084 stroke-width="0.35"
00085 stroke-linecap="butt"
00086 stroke-linejoin="miter"
00087 transform="translate(30,30)"
00088 fill="#00cc00"
00089 >
00090
00091 <ellipse cx="40" cy="40" rx="30" ry="15"/>
00092 </g>
00093 """
00094 App.activeDocument().Page.addObject(App.activeDocument().ViewSelf)
00095
00096 App.activeDocument().recompute()
00097
00098 del Shape,ViewSVG, resultSVG
00099