This commit is contained in:
benj5378
2022-01-24 22:20:02 +01:00
committed by WandererFan
parent 8d7c92ece4
commit 96b8a6e87b
8 changed files with 196 additions and 164 deletions

View File

@@ -7,41 +7,41 @@
from __future__ import print_function
import FreeCAD
import os
def DHatchTest():
path = os.path.dirname(os.path.abspath(__file__))
print ('TDHatch path: ' + path)
templateFileSpec = path+'/TestTemplate.svg'
hatchFileSpec = path + '/TestHatch.svg'
print("TDHatch path: " + path)
templateFileSpec = path + "/TestTemplate.svg"
hatchFileSpec = path + "/TestHatch.svg"
FreeCAD.newDocument("TDHatch")
FreeCAD.setActiveDocument("TDHatch")
FreeCAD.ActiveDocument=FreeCAD.getDocument("TDHatch")
FreeCAD.ActiveDocument = FreeCAD.getDocument("TDHatch")
#make source feature
box = FreeCAD.ActiveDocument.addObject("Part::Box","Box")
# make source feature
box = FreeCAD.ActiveDocument.addObject("Part::Box", "Box")
#make a page
page = FreeCAD.ActiveDocument.addObject('TechDraw::DrawPage','Page')
FreeCAD.ActiveDocument.addObject('TechDraw::DrawSVGTemplate','Template')
# make a page
page = FreeCAD.ActiveDocument.addObject("TechDraw::DrawPage", "Page")
FreeCAD.ActiveDocument.addObject("TechDraw::DrawSVGTemplate", "Template")
FreeCAD.ActiveDocument.Template.Template = templateFileSpec
FreeCAD.ActiveDocument.Page.Template = FreeCAD.ActiveDocument.Template
page.Scale = 5.0
# page.ViewObject.show() #unit tests run in console mode
# page.ViewObject.show() #unit tests run in console mode
#make Views
view1 = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewPart','View')
# make Views
view1 = FreeCAD.ActiveDocument.addObject("TechDraw::DrawViewPart", "View")
FreeCAD.ActiveDocument.View.Source = [box]
page.addView(view1)
FreeCAD.ActiveDocument.recompute()
#make hatch
# make hatch
print("making hatch")
hatch = FreeCAD.ActiveDocument.addObject('TechDraw::DrawHatch','Hatch')
hatch.Source = (view1,["Face0"])
hatch.HatchPattern = hatchFileSpec #comment out to use default from preferences
hatch = FreeCAD.ActiveDocument.addObject("TechDraw::DrawHatch", "Hatch")
hatch.Source = (view1, ["Face0"])
hatch.HatchPattern = hatchFileSpec # comment out to use default from preferences
print("adding hatch to page")
page.addView(hatch)
print("finished hatch")
@@ -49,10 +49,12 @@ def DHatchTest():
FreeCAD.ActiveDocument.recompute()
rc = False
if ("Up-to-date" in hatch.State):
if "Up-to-date" in hatch.State:
rc = True
FreeCAD.closeDocument("TDHatch")
return rc
if __name__ == '__main__':
if __name__ == "__main__":
DHatchTest()

View File

@@ -10,12 +10,12 @@ from __future__ import print_function
import FreeCAD
import os
def DLeaderTest():
path = os.path.dirname(os.path.abspath(__file__))
print ('TDLead path: ' + path)
templateFileSpec = path + '/TestTemplate.svg'
myHTMLText = \
"""<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
print("TDLead path: " + path)
templateFileSpec = path + "/TestTemplate.svg"
myHTMLText = """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
p, li { white-space: pre-wrap; }
</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;">
@@ -23,35 +23,37 @@ p, li { white-space: pre-wrap; }
FreeCAD.newDocument("TDLead")
FreeCAD.setActiveDocument("TDLead")
FreeCAD.ActiveDocument=FreeCAD.getDocument("TDLead")
FreeCAD.ActiveDocument = FreeCAD.getDocument("TDLead")
#make source feature
FreeCAD.ActiveDocument.addObject("Part::Box","Box")
# make source feature
FreeCAD.ActiveDocument.addObject("Part::Box", "Box")
#make a page
page = FreeCAD.ActiveDocument.addObject('TechDraw::DrawPage','Page')
FreeCAD.ActiveDocument.addObject('TechDraw::DrawSVGTemplate','Template')
# make a page
page = FreeCAD.ActiveDocument.addObject("TechDraw::DrawPage", "Page")
FreeCAD.ActiveDocument.addObject("TechDraw::DrawSVGTemplate", "Template")
FreeCAD.ActiveDocument.Template.Template = templateFileSpec
FreeCAD.ActiveDocument.Page.Template = FreeCAD.ActiveDocument.Template
page.Scale = 5.0
# page.ViewObject.show() # unit tests run in console mode
# page.ViewObject.show() # unit tests run in console mode
#make Views
view1 = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewPart','View')
# make Views
view1 = FreeCAD.ActiveDocument.addObject("TechDraw::DrawViewPart", "View")
FreeCAD.ActiveDocument.View.Source = [FreeCAD.ActiveDocument.Box]
rc = page.addView(view1)
view1.X = 148
view1.Y = 105
FreeCAD.ActiveDocument.recompute()
#make leader
# make leader
print("making leader")
leaderObj = FreeCAD.ActiveDocument.addObject('TechDraw::DrawLeaderLine','DrawLeaderLine')
leaderObj = FreeCAD.ActiveDocument.addObject(
"TechDraw::DrawLeaderLine", "DrawLeaderLine"
)
leaderObj.LeaderParent = view1
p0 = FreeCAD.Vector(0.0,0.0,0.0);
p1 = FreeCAD.Vector(100.0,-100.0,0.0);
p2 = FreeCAD.Vector(500.0,-100.0,0.0);
leaderObj.WayPoints = [p0,p1,p2]
p0 = FreeCAD.Vector(0.0, 0.0, 0.0)
p1 = FreeCAD.Vector(100.0, -100.0, 0.0)
p2 = FreeCAD.Vector(500.0, -100.0, 0.0)
leaderObj.WayPoints = [p0, p1, p2]
leaderObj.StartSymbol = 0
leaderObj.EndSymbol = 4
print("adding leader to page")
@@ -60,9 +62,11 @@ p, li { white-space: pre-wrap; }
leaderObj.Y = 5
print("finished leader")
#make RTA
# make RTA
print("making RTA")
blockObj = FreeCAD.ActiveDocument.addObject('TechDraw::DrawRichAnno','DrawRichAnno')
blockObj = FreeCAD.ActiveDocument.addObject(
"TechDraw::DrawRichAnno", "DrawRichAnno"
)
page.addView(blockObj)
blockObj.AnnoParent = leaderObj
blockObj.X = 5
@@ -74,8 +78,10 @@ p, li { white-space: pre-wrap; }
rc = False
if ("Up-to-date" in leaderObj.State) and ("Up-to-date" in blockObj.State):
rc = True
FreeCAD.closeDocument("TDLead")
return rc
if __name__ == '__main__':
if __name__ == "__main__":
DLeaderTest()

View File

@@ -12,54 +12,55 @@ from __future__ import print_function
import FreeCAD
import os
def DProjGroupTest():
path = os.path.dirname(os.path.abspath(__file__))
print ('TDGroup path: ' + path)
templateFileSpec = path + '/TestTemplate.svg'
print("TDGroup path: " + path)
templateFileSpec = path + "/TestTemplate.svg"
FreeCAD.newDocument("TDGroup")
FreeCAD.setActiveDocument("TDGroup")
FreeCAD.ActiveDocument=FreeCAD.getDocument("TDGroup")
FreeCAD.ActiveDocument = FreeCAD.getDocument("TDGroup")
doc = FreeCAD.ActiveDocument
print("document created")
#make Fusion feature
box = FreeCAD.ActiveDocument.addObject("Part::Box","Box")
# make Fusion feature
box = FreeCAD.ActiveDocument.addObject("Part::Box", "Box")
box.recompute()
print("box created")
sphere = FreeCAD.ActiveDocument.addObject("Part::Sphere","Sphere")
sphere = FreeCAD.ActiveDocument.addObject("Part::Sphere", "Sphere")
sphere.recompute()
print("sphere created")
fusion = FreeCAD.ActiveDocument.addObject("Part::MultiFuse","Fusion")
FreeCAD.ActiveDocument.Fusion.Shapes = [box,sphere]
fusion = FreeCAD.ActiveDocument.addObject("Part::MultiFuse", "Fusion")
FreeCAD.ActiveDocument.Fusion.Shapes = [box, sphere]
fusion.recompute()
print("Fusion created")
#make a page
# make a page
print("making a page")
page = FreeCAD.ActiveDocument.addObject('TechDraw::DrawPage','Page')
FreeCAD.ActiveDocument.addObject('TechDraw::DrawSVGTemplate','Template')
page = FreeCAD.ActiveDocument.addObject("TechDraw::DrawPage", "Page")
FreeCAD.ActiveDocument.addObject("TechDraw::DrawSVGTemplate", "Template")
FreeCAD.ActiveDocument.Template.Template = templateFileSpec
FreeCAD.ActiveDocument.Page.Template = FreeCAD.ActiveDocument.Template
# page.ViewObject.show() #for debugging. unit tests run in console mode
# page.ViewObject.show() # for debugging. unit tests run in console mode
print("Page created")
#make projection group
# make projection group
print("making a projection group")
doc.openTransaction("Create Proj Group")
groupName = 'ProjGroup'
group = FreeCAD.ActiveDocument.addObject('TechDraw::DrawProjGroup', groupName)
groupName = "ProjGroup"
group = FreeCAD.ActiveDocument.addObject("TechDraw::DrawProjGroup", groupName)
page.addView(group)
print("Group created")
group.Source = [fusion]
print("adding views")
group.addProjection("Front") ##need an Anchor
group.addProjection("Front") # need an Anchor
print("added Front")
#update group
anchorDir = FreeCAD.Vector(0.0, 0.0, 1.0);
anchorRot = FreeCAD.Vector(1.0, 0.0, 0.0);
# update group
anchorDir = FreeCAD.Vector(0.0, 0.0, 1.0)
anchorRot = FreeCAD.Vector(1.0, 0.0, 0.0)
group.Anchor.Direction = anchorDir
group.Anchor.RotationVector = anchorRot
print("Anchor values set")
@@ -79,11 +80,11 @@ def DProjGroupTest():
group.addProjection("Bottom")
print("added Bottom")
#remove a view from projection group
# remove a view from projection group
group.removeProjection("Left")
print("removed Left")
##test getItemByLabel method
# test getItemByLabel method
print("testing getItemByLabel")
label = "Top"
item = group.getItemByLabel(label)
@@ -93,14 +94,16 @@ def DProjGroupTest():
FreeCAD.ActiveDocument.recompute()
for v in group.Views:
print ("View: " + v.Label + " " + v.TypeId)
print("View: " + v.Label + " " + v.TypeId)
v.autoPosition()
rc = False
if ("Up-to-date" in group.State):
if "Up-to-date" in group.State:
rc = True
FreeCAD.closeDocument("TDGroup")
return rc
if __name__ == '__main__':
if __name__ == "__main__":
DProjGroupTest()

View File

@@ -8,37 +8,38 @@ from __future__ import print_function
import FreeCAD
import os
def DVAnnoSymImageTest():
path = os.path.dirname(os.path.abspath(__file__))
print ('TDTestAnno path: ' + path)
templateFileSpec = path + '/TestTemplate.svg'
symbolFileSpec = path + '/TestSymbol.svg'
imageFileSpec = path + '/TestImage.png'
print("TDTestAnno path: " + path)
templateFileSpec = path + "/TestTemplate.svg"
symbolFileSpec = path + "/TestSymbol.svg"
imageFileSpec = path + "/TestImage.png"
FreeCAD.newDocument("TDAnno")
FreeCAD.setActiveDocument("TDAnno")
FreeCAD.ActiveDocument=FreeCAD.getDocument("TDAnno")
FreeCAD.ActiveDocument = FreeCAD.getDocument("TDAnno")
page = FreeCAD.ActiveDocument.addObject('TechDraw::DrawPage','Page')
FreeCAD.ActiveDocument.addObject('TechDraw::DrawSVGTemplate','Template')
page = FreeCAD.ActiveDocument.addObject("TechDraw::DrawPage", "Page")
FreeCAD.ActiveDocument.addObject("TechDraw::DrawSVGTemplate", "Template")
FreeCAD.ActiveDocument.Template.Template = templateFileSpec
FreeCAD.ActiveDocument.Page.Template = FreeCAD.ActiveDocument.Template
# page.ViewObject.show() # unit tests run in console mode
# page.ViewObject.show() # unit tests run in console mode
#annotation
anno = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewAnnotation','TestAnno')
s = 'Different Text'
# annotation
anno = FreeCAD.ActiveDocument.addObject("TechDraw::DrawViewAnnotation", "TestAnno")
s = "Different Text"
sl = list()
sl.append(s)
anno.Text = sl
anno.TextStyle = 'Bold'
anno.TextStyle = "Bold"
page.addView(anno)
anno.X = 30.0
anno.Y = 150.0
#symbol
sym = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewSymbol','TestSymbol')
f = open(symbolFileSpec, 'r')
# symbol
sym = FreeCAD.ActiveDocument.addObject("TechDraw::DrawViewSymbol", "TestSymbol")
f = open(symbolFileSpec, "r")
svg = f.read()
f.close()
sym.Symbol = svg
@@ -46,17 +47,23 @@ def DVAnnoSymImageTest():
sym.X = 220.0
sym.Y = 150.0
#image
img = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewImage','TestImage')
# image
img = FreeCAD.ActiveDocument.addObject("TechDraw::DrawViewImage", "TestImage")
img.ImageFile = imageFileSpec
page.addView(img)
FreeCAD.ActiveDocument.recompute()
rc = False
if ("Up-to-date" in anno.State) and ("Up-to-date" in sym.State) and ("Up-to-date" in img.State):
if (
("Up-to-date" in anno.State)
and ("Up-to-date" in sym.State)
and ("Up-to-date" in img.State)
):
rc = True
FreeCAD.closeDocument("TDAnno")
return rc
if __name__ == '__main__':
if __name__ == "__main__":
DVAnnoSymImageTest()

View File

@@ -11,61 +11,62 @@ import FreeCAD
from FreeCAD import Units
import os
def DVBalloonTest():
path = os.path.dirname(os.path.abspath(__file__))
print ('TDBalloon path: ' + path)
templateFileSpec = path + '/TestTemplate.svg'
print("TDBalloon path: " + path)
templateFileSpec = path + "/TestTemplate.svg"
FreeCAD.newDocument("TDBalloon")
FreeCAD.setActiveDocument("TDBalloon")
FreeCAD.ActiveDocument=FreeCAD.getDocument("TDBalloon")
FreeCAD.ActiveDocument = FreeCAD.getDocument("TDBalloon")
#make source feature
FreeCAD.ActiveDocument.addObject("Part::Box","Box")
FreeCAD.ActiveDocument.addObject("Part::Sphere","Sphere")
# make source feature
FreeCAD.ActiveDocument.addObject("Part::Box", "Box")
FreeCAD.ActiveDocument.addObject("Part::Sphere", "Sphere")
#make a page
page = FreeCAD.ActiveDocument.addObject('TechDraw::DrawPage','Page')
FreeCAD.ActiveDocument.addObject('TechDraw::DrawSVGTemplate','Template')
# make a page
page = FreeCAD.ActiveDocument.addObject("TechDraw::DrawPage", "Page")
FreeCAD.ActiveDocument.addObject("TechDraw::DrawSVGTemplate", "Template")
FreeCAD.ActiveDocument.Template.Template = templateFileSpec
FreeCAD.ActiveDocument.Page.Template = FreeCAD.ActiveDocument.Template
page.Scale = 5.0
# page.ViewObject.show() # unit tests run in console mode
# page.ViewObject.show() # unit tests run in console mode
#make Views
view1 = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewPart','View')
# make Views
view1 = FreeCAD.ActiveDocument.addObject("TechDraw::DrawViewPart", "View")
FreeCAD.ActiveDocument.View.Source = [FreeCAD.ActiveDocument.Box]
page.addView(view1)
view1.X = Units.Quantity(30.0,Units.Length)
view1.Y = Units.Quantity(150.0,Units.Length)
view2 = FreeCAD.activeDocument().addObject('TechDraw::DrawViewPart','View001')
view1.X = Units.Quantity(30.0, Units.Length)
view1.Y = Units.Quantity(150.0, Units.Length)
view2 = FreeCAD.activeDocument().addObject("TechDraw::DrawViewPart", "View001")
FreeCAD.activeDocument().View001.Source = [FreeCAD.activeDocument().Sphere]
page.addView(view2)
view2.X = Units.Quantity(220.0,Units.Length)
view2.Y = Units.Quantity(150.0,Units.Length)
view2.X = Units.Quantity(220.0, Units.Length)
view2.Y = Units.Quantity(150.0, Units.Length)
FreeCAD.ActiveDocument.recompute()
print("Place balloon")
balloon1 = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewBalloon','Balloon1')
balloon1.SourceView=view1
# balloon1.OriginIsSet=1 ##OriginIsSet property removed March 2020
balloon1.OriginX=view1.X + Units.Quantity(20.0,Units.Length)
balloon1.OriginY=view1.Y + Units.Quantity(20.0,Units.Length)
balloon1.Text="1"
balloon1.Y=balloon1.OriginX + Units.Quantity(20.0,Units.Length)
balloon1.X=balloon1.OriginY + Units.Quantity(20.0,Units.Length)
balloon1 = FreeCAD.ActiveDocument.addObject("TechDraw::DrawViewBalloon", "Balloon1")
balloon1.SourceView = view1
# balloon1.OriginIsSet = 1 # OriginIsSet property removed March 2020
balloon1.OriginX = view1.X + Units.Quantity(20.0, Units.Length)
balloon1.OriginY = view1.Y + Units.Quantity(20.0, Units.Length)
balloon1.Text = "1"
balloon1.Y = balloon1.OriginX + Units.Quantity(20.0, Units.Length)
balloon1.X = balloon1.OriginY + Units.Quantity(20.0, Units.Length)
print("adding balloon1 to page")
page.addView(balloon1)
balloon2 = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewBalloon','Balloon2')
balloon2.SourceView=view2
# balloon2.OriginIsSet=1
balloon2.OriginX=view2.X + Units.Quantity(20.0,Units.Length)
balloon2.OriginY=view2.Y + Units.Quantity(20.0,Units.Length)
balloon2.Text="2"
balloon2.Y=balloon2.OriginX + Units.Quantity(20.0,Units.Length)
balloon2.X=balloon2.OriginY + Units.Quantity(20.0,Units.Length)
balloon2 = FreeCAD.ActiveDocument.addObject("TechDraw::DrawViewBalloon", "Balloon2")
balloon2.SourceView = view2
# balloon2.OriginIsSet = 1
balloon2.OriginX = view2.X + Units.Quantity(20.0, Units.Length)
balloon2.OriginY = view2.Y + Units.Quantity(20.0, Units.Length)
balloon2.Text = "2"
balloon2.Y = balloon2.OriginX + Units.Quantity(20.0, Units.Length)
balloon2.X = balloon2.OriginY + Units.Quantity(20.0, Units.Length)
print("adding balloon2 to page")
page.addView(balloon2)
@@ -75,8 +76,10 @@ def DVBalloonTest():
rc = False
if ("Up-to-date" in balloon1.State) and ("Up-to-date" in balloon2.State):
rc = True
FreeCAD.closeDocument("TDBalloon")
return rc
if __name__ == '__main__':
if __name__ == "__main__":
DVBalloonTest()

View File

@@ -10,59 +10,62 @@ from __future__ import print_function
import FreeCAD
import os
def DVDimensionTest():
path = os.path.dirname(os.path.abspath(__file__))
print ('TDDim path: ' + path)
templateFileSpec = path + '/TestTemplate.svg'
print("TDDim path: " + path)
templateFileSpec = path + "/TestTemplate.svg"
FreeCAD.newDocument("TDDim")
FreeCAD.setActiveDocument("TDDim")
FreeCAD.ActiveDocument=FreeCAD.getDocument("TDDim")
FreeCAD.ActiveDocument = FreeCAD.getDocument("TDDim")
#make source feature
FreeCAD.ActiveDocument.addObject("Part::Box","Box")
FreeCAD.ActiveDocument.addObject("Part::Sphere","Sphere")
# make source feature
FreeCAD.ActiveDocument.addObject("Part::Box", "Box")
FreeCAD.ActiveDocument.addObject("Part::Sphere", "Sphere")
#make a page
page = FreeCAD.ActiveDocument.addObject('TechDraw::DrawPage','Page')
FreeCAD.ActiveDocument.addObject('TechDraw::DrawSVGTemplate','Template')
# make a page
page = FreeCAD.ActiveDocument.addObject("TechDraw::DrawPage", "Page")
FreeCAD.ActiveDocument.addObject("TechDraw::DrawSVGTemplate", "Template")
FreeCAD.ActiveDocument.Template.Template = templateFileSpec
FreeCAD.ActiveDocument.Page.Template = FreeCAD.ActiveDocument.Template
page.Scale = 5.0
# page.ViewObject.show() # unit tests run in console mode
# page.ViewObject.show() # unit tests run in console mode
#make Views
view1 = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewPart','View')
# make Views
view1 = FreeCAD.ActiveDocument.addObject("TechDraw::DrawViewPart", "View")
FreeCAD.ActiveDocument.View.Source = [FreeCAD.ActiveDocument.Box]
page.addView(view1)
view1.X = 30
view1.Y = 150
view2 = FreeCAD.activeDocument().addObject('TechDraw::DrawViewPart','View001')
view2 = FreeCAD.activeDocument().addObject("TechDraw::DrawViewPart", "View001")
FreeCAD.activeDocument().View001.Source = [FreeCAD.activeDocument().Sphere]
page.addView(view2)
view2.X = 220
view2.Y = 150
FreeCAD.ActiveDocument.recompute()
#make length dimension
# make length dimension
print("making length dimension")
dim1 = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewDimension','Dimension')
dim1 = FreeCAD.ActiveDocument.addObject("TechDraw::DrawViewDimension", "Dimension")
dim1.Type = "Distance"
objs = list()
objs.append(view1)
subObjs = list()
subObjs.append("Edge1")
dim1.References2D=[(view1, 'Edge1')]
dim1.References2D = [(view1, "Edge1")]
print("adding dim1 to page")
page.addView(dim1)
print("finished length dimension")
#make radius dimension
# make radius dimension
print("making radius dimension")
dim2 = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewDimension','Dimension001')
dim2 = FreeCAD.ActiveDocument.addObject(
"TechDraw::DrawViewDimension", "Dimension001"
)
dim2.Type = "Radius"
dim2.MeasureType = "Projected"
dim2.References2D=[(view2, 'Edge0')]
dim2.References2D = [(view2, "Edge0")]
page.addView(dim2)
FreeCAD.ActiveDocument.recompute()
@@ -70,8 +73,10 @@ def DVDimensionTest():
rc = False
if ("Up-to-date" in dim1.State) and ("Up-to-date" in dim2.State):
rc = True
FreeCAD.closeDocument("TDDim")
return rc
if __name__ == '__main__':
if __name__ == "__main__":
DVDimensionTest()

View File

@@ -8,26 +8,27 @@ from __future__ import print_function
import FreeCAD
import os
def DVPartTest():
path = os.path.dirname(os.path.abspath(__file__))
print ('TDPart path: ' + path)
templateFileSpec = path + '/TestTemplate.svg'
print("TDPart path: " + path)
templateFileSpec = path + "/TestTemplate.svg"
FreeCAD.newDocument("TDPart")
FreeCAD.setActiveDocument("TDPart")
FreeCAD.ActiveDocument=FreeCAD.getDocument("TDPart")
FreeCAD.ActiveDocument = FreeCAD.getDocument("TDPart")
FreeCAD.ActiveDocument.addObject("Part::Box","Box")
FreeCAD.ActiveDocument.addObject("Part::Box", "Box")
page = FreeCAD.ActiveDocument.addObject('TechDraw::DrawPage','Page')
FreeCAD.ActiveDocument.addObject('TechDraw::DrawSVGTemplate','Template')
page = FreeCAD.ActiveDocument.addObject("TechDraw::DrawPage", "Page")
FreeCAD.ActiveDocument.addObject("TechDraw::DrawSVGTemplate", "Template")
FreeCAD.ActiveDocument.Template.Template = templateFileSpec
FreeCAD.ActiveDocument.Page.Template = FreeCAD.ActiveDocument.Template
page.Scale = 5.0
# page.ViewObject.show() # unit tests run in console mode
# page.ViewObject.show() # unit tests run in console mode
print("page created")
view = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewPart','View')
view = FreeCAD.ActiveDocument.addObject("TechDraw::DrawViewPart", "View")
page.addView(view)
FreeCAD.ActiveDocument.View.Source = [FreeCAD.ActiveDocument.Box]
@@ -35,10 +36,12 @@ def DVPartTest():
FreeCAD.ActiveDocument.recompute()
rc = False
if ("Up-to-date" in view.State):
if "Up-to-date" in view.State:
rc = True
FreeCAD.closeDocument("TDPart")
return rc
if __name__ == '__main__':
if __name__ == "__main__":
DVPartTest()

View File

@@ -8,41 +8,42 @@ from __future__ import print_function
import FreeCAD
import os
def DVSectionTest():
path = os.path.dirname(os.path.abspath(__file__))
print ('TDSection path: ' + path)
templateFileSpec = path + '/TestTemplate.svg'
print("TDSection path: " + path)
templateFileSpec = path + "/TestTemplate.svg"
FreeCAD.newDocument("TDSection")
FreeCAD.setActiveDocument("TDSection")
FreeCAD.ActiveDocument=FreeCAD.getDocument("TDSection")
FreeCAD.ActiveDocument = FreeCAD.getDocument("TDSection")
box = FreeCAD.ActiveDocument.addObject("Part::Box","Box")
box = FreeCAD.ActiveDocument.addObject("Part::Box", "Box")
page = FreeCAD.ActiveDocument.addObject('TechDraw::DrawPage','Page')
FreeCAD.ActiveDocument.addObject('TechDraw::DrawSVGTemplate','Template')
page = FreeCAD.ActiveDocument.addObject("TechDraw::DrawPage", "Page")
FreeCAD.ActiveDocument.addObject("TechDraw::DrawSVGTemplate", "Template")
FreeCAD.ActiveDocument.Template.Template = templateFileSpec
FreeCAD.ActiveDocument.Page.Template = FreeCAD.ActiveDocument.Template
page.Scale = 5.0
# page.ViewObject.show() # unit tests run in console mode
# page.ViewObject.show() # unit tests run in console mode
print("page created")
view = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewPart','View')
view = FreeCAD.ActiveDocument.addObject("TechDraw::DrawViewPart", "View")
rc = page.addView(view)
view.Source = [box]
view.Direction = (0.0,0.0,1.0)
view.Direction = (0.0, 0.0, 1.0)
view.Rotation = 0.0
view.X = 30.0
view.Y = 150.0
print("view created")
section = FreeCAD.ActiveDocument.addObject('TechDraw::DrawViewSection','Section')
section = FreeCAD.ActiveDocument.addObject("TechDraw::DrawViewSection", "Section")
rc = page.addView(section)
section.Source = [box]
section.BaseView = view
section.Direction = (0.0,1.0,0.0)
section.SectionNormal = (0.0,1.0,0.0)
section.SectionOrigin = (5.0,5.0,5.0)
section.Direction = (0.0, 1.0, 0.0)
section.SectionNormal = (0.0, 1.0, 0.0)
section.SectionOrigin = (5.0, 5.0, 5.0)
view.touch()
print("section created")
@@ -50,8 +51,10 @@ def DVSectionTest():
rc = False
if ("Up-to-date" in view.State) and ("Up-to-date" in section.State):
rc = True
FreeCAD.closeDocument("TDSection")
return rc
if __name__ == '__main__':
if __name__ == "__main__":
DVSectionTest()