From d49a1942799e134a63319940ae70b800330c0ea0 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Tue, 8 May 2018 16:07:55 -0300 Subject: [PATCH] Arch/Draft: Make sure an active doc exists before creating objects --- src/Mod/Arch/ArchAxis.py | 3 ++ src/Mod/Arch/ArchBuilding.py | 3 ++ src/Mod/Arch/ArchCommands.py | 3 ++ src/Mod/Arch/ArchEquipment.py | 3 ++ src/Mod/Arch/ArchFloor.py | 3 ++ src/Mod/Arch/ArchFrame.py | 3 ++ src/Mod/Arch/ArchMaterial.py | 3 ++ src/Mod/Arch/ArchPanel.py | 3 ++ src/Mod/Arch/ArchPipe.py | 6 +++ src/Mod/Arch/ArchProfile.py | 3 ++ src/Mod/Arch/ArchRebar.py | 3 ++ src/Mod/Arch/ArchRoof.py | 3 ++ src/Mod/Arch/ArchSectionPlane.py | 3 ++ src/Mod/Arch/ArchSite.py | 3 ++ src/Mod/Arch/ArchSpace.py | 3 ++ src/Mod/Arch/ArchStairs.py | 3 ++ src/Mod/Arch/ArchStructure.py | 6 +++ src/Mod/Arch/ArchWall.py | 3 ++ src/Mod/Arch/ArchWindow.py | 7 +++ src/Mod/Draft/Draft.py | 73 ++++++++++++++++++++++++++++++++ 20 files changed, 140 insertions(+) diff --git a/src/Mod/Arch/ArchAxis.py b/src/Mod/Arch/ArchAxis.py index af6bb7a318..ffab3dc223 100644 --- a/src/Mod/Arch/ArchAxis.py +++ b/src/Mod/Arch/ArchAxis.py @@ -52,6 +52,9 @@ __url__ = "http://www.freecadweb.org" def makeAxis(num=5,size=1000,name="Axes"): '''makeAxis(num,size): makes an Axis set based on the given number of axes and interval distances''' + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return obj = FreeCAD.ActiveDocument.addObject("App::FeaturePython",name) obj.Label = translate("Arch",name) _Axis(obj) diff --git a/src/Mod/Arch/ArchBuilding.py b/src/Mod/Arch/ArchBuilding.py index 5685d96a6c..4dadb288d1 100644 --- a/src/Mod/Arch/ArchBuilding.py +++ b/src/Mod/Arch/ArchBuilding.py @@ -193,6 +193,9 @@ BuildingTypes = ['Undefined', def makeBuilding(objectslist=None,baseobj=None,name="Building"): '''makeBuilding(objectslist): creates a building including the objects from the given list.''' + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return obj = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroupPython",name) _Building(obj) if FreeCAD.GuiUp: diff --git a/src/Mod/Arch/ArchCommands.py b/src/Mod/Arch/ArchCommands.py index 7fb39ed399..8f4bde0365 100644 --- a/src/Mod/Arch/ArchCommands.py +++ b/src/Mod/Arch/ArchCommands.py @@ -198,6 +198,9 @@ def removeComponents(objectsList,host=None): def makeComponent(baseobj=None,name="Component",delete=False): '''makeComponent([baseobj]): creates an undefined, non-parametric Arch component from the given base object''' + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name) obj.Label = translate("Arch",name) ArchComponent.Component(obj) diff --git a/src/Mod/Arch/ArchEquipment.py b/src/Mod/Arch/ArchEquipment.py index 1c0995136d..9df56c3dad 100644 --- a/src/Mod/Arch/ArchEquipment.py +++ b/src/Mod/Arch/ArchEquipment.py @@ -57,6 +57,9 @@ Roles = ["Undefined","Furniture", "Hydro Equipment", "Electric Equipment"] def makeEquipment(baseobj=None,placement=None,name="Equipment"): "makeEquipment([baseobj,placement,name]): creates an equipment object from the given base object." + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name) _Equipment(obj) if baseobj: diff --git a/src/Mod/Arch/ArchFloor.py b/src/Mod/Arch/ArchFloor.py index edc745a2cc..b6696ed580 100644 --- a/src/Mod/Arch/ArchFloor.py +++ b/src/Mod/Arch/ArchFloor.py @@ -52,6 +52,9 @@ __url__ = "http://www.freecadweb.org" def makeFloor(objectslist=None,baseobj=None,name="Floor"): '''makeFloor(objectslist): creates a floor including the objects from the given list.''' + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return obj = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroupPython",name) obj.Label = translate("Arch",name) _Floor(obj) diff --git a/src/Mod/Arch/ArchFrame.py b/src/Mod/Arch/ArchFrame.py index 89fc9b5a64..6fe39d1289 100644 --- a/src/Mod/Arch/ArchFrame.py +++ b/src/Mod/Arch/ArchFrame.py @@ -54,6 +54,9 @@ Roles = ['Undefined','Covering','Member','Railing','Shading Device','Tendon'] def makeFrame(baseobj,profile,name=translate("Arch","Frame")): """makeFrame(baseobj,profile,[name]): creates a frame object from a base sketch (or any other object containing wires) and a profile object (an extrudable 2D object containing faces or closed wires)""" + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name) obj.Label = translate("Arch",name) _Frame(obj) diff --git a/src/Mod/Arch/ArchMaterial.py b/src/Mod/Arch/ArchMaterial.py index 7c50c18d71..cac1bf368b 100644 --- a/src/Mod/Arch/ArchMaterial.py +++ b/src/Mod/Arch/ArchMaterial.py @@ -47,6 +47,9 @@ __url__ = "http://www.freecadweb.org" def makeMaterial(name="Material"): '''makeMaterial(name): makes an Material object''' + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return obj = FreeCAD.ActiveDocument.addObject("App::MaterialObjectPython",name) obj.Label = name _ArchMaterial(obj) diff --git a/src/Mod/Arch/ArchPanel.py b/src/Mod/Arch/ArchPanel.py index 8421525ba8..f1768c8515 100644 --- a/src/Mod/Arch/ArchPanel.py +++ b/src/Mod/Arch/ArchPanel.py @@ -66,6 +66,9 @@ def makePanel(baseobj=None,length=0,width=0,thickness=0,placement=None,name="Pan panel element based on the given profile object and the given extrusion thickness. If no base object is given, you can also specify length and width for a simple cubic object.''' + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name) obj.Label = translate("Arch",name) _Panel(obj) diff --git a/src/Mod/Arch/ArchPipe.py b/src/Mod/Arch/ArchPipe.py index a2e619f611..dfeac81e5e 100644 --- a/src/Mod/Arch/ArchPipe.py +++ b/src/Mod/Arch/ArchPipe.py @@ -52,6 +52,9 @@ def makePipe(baseobj=None,diameter=0,length=0,placement=None,name="Pipe"): "makePipe([baseobj,diamerter,length,placement,name]): creates an pipe object from the given base object" + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return obj= FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name) obj.Label = name _ArchPipe(obj) @@ -80,6 +83,9 @@ def makePipeConnector(pipes,radius=0,name="Connector"): "makePipeConnector(pipes,[radius,name]): creates a connector between the given pipes" + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return obj= FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name) obj.Label = name _ArchPipeConnector(obj) diff --git a/src/Mod/Arch/ArchProfile.py b/src/Mod/Arch/ArchProfile.py index 418f0db199..a5f0164c6b 100644 --- a/src/Mod/Arch/ArchProfile.py +++ b/src/Mod/Arch/ArchProfile.py @@ -80,6 +80,9 @@ def readPresets(): def makeProfile(profile=[0,'REC','REC100x100','R',100,100]): '''makeProfile(profile): returns a shape with the face defined by the profile data''' + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return obj = FreeCAD.ActiveDocument.addObject("Part::Part2DObjectPython",profile[2]) obj.Label = translate("Arch",profile[2]) if profile[3]=="C": diff --git a/src/Mod/Arch/ArchRebar.py b/src/Mod/Arch/ArchRebar.py index bdffe9774b..335f423894 100644 --- a/src/Mod/Arch/ArchRebar.py +++ b/src/Mod/Arch/ArchRebar.py @@ -53,6 +53,9 @@ __url__ = "http://www.freecadweb.org" def makeRebar(baseobj=None,sketch=None,diameter=None,amount=1,offset=None,name="Rebar"): """makeRebar([baseobj,sketch,diameter,amount,offset,name]): adds a Reinforcement Bar object to the given structural object, using the given sketch as profile.""" + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch") obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name) obj.Label = translate("Arch",name) diff --git a/src/Mod/Arch/ArchRoof.py b/src/Mod/Arch/ArchRoof.py index 981a197b5d..8dbabe6f03 100644 --- a/src/Mod/Arch/ArchRoof.py +++ b/src/Mod/Arch/ArchRoof.py @@ -55,6 +55,9 @@ def makeRoof(baseobj=None,facenr=0, angles=[45.,], run = [], idrel = [0,],thickn roof shape. The default for angle is 45 and the list is automatically complete to match with number of edges in the wire. If the base object is a solid the roof take the shape.''' + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return import Part obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name) obj.Label = translate("Arch",name) diff --git a/src/Mod/Arch/ArchSectionPlane.py b/src/Mod/Arch/ArchSectionPlane.py index 8128bc7ff0..aa1a1a4bb7 100644 --- a/src/Mod/Arch/ArchSectionPlane.py +++ b/src/Mod/Arch/ArchSectionPlane.py @@ -48,6 +48,9 @@ else: def makeSectionPlane(objectslist=None,name="Section"): """makeSectionPlane([objectslist]) : Creates a Section plane objects including the given objects. If no object is given, the whole document will be considered.""" + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return obj = FreeCAD.ActiveDocument.addObject("App::FeaturePython",name) obj.Label = translate("Arch",name) _SectionPlane(obj) diff --git a/src/Mod/Arch/ArchSite.py b/src/Mod/Arch/ArchSite.py index 65cbfbecaa..f9b318d291 100644 --- a/src/Mod/Arch/ArchSite.py +++ b/src/Mod/Arch/ArchSite.py @@ -54,6 +54,9 @@ __url__ = "http://www.freecadweb.org" def makeSite(objectslist=None,baseobj=None,name="Site"): '''makeBuilding(objectslist): creates a site including the objects from the given list.''' + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return import Part obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name) obj.Label = translate("Arch",name) diff --git a/src/Mod/Arch/ArchSpace.py b/src/Mod/Arch/ArchSpace.py index d1c434d0ba..9d1222236b 100644 --- a/src/Mod/Arch/ArchSpace.py +++ b/src/Mod/Arch/ArchSpace.py @@ -176,6 +176,9 @@ def makeSpace(objects=None,baseobj=None,name="Space"): """makeSpace([objects]): Creates a space object from the given objects. Objects can be one document object, in which case it becomes the base shape of the space object, or a list of selection objects as got from getSelectionEx(), or a list of tuples (object, subobjectname)""" + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name) obj.Label = translate("Arch",name) _Space(obj) diff --git a/src/Mod/Arch/ArchStairs.py b/src/Mod/Arch/ArchStairs.py index 6a10084aa9..14c0811b9f 100644 --- a/src/Mod/Arch/ArchStairs.py +++ b/src/Mod/Arch/ArchStairs.py @@ -49,6 +49,9 @@ else: def makeStairs(baseobj=None,length=None,width=None,height=None,steps=None,name="Stairs"): """makeStairs([baseobj,length,width,height,steps]): creates a Stairs objects with given attributes.""" + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch") obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name) obj.Label = translate("Arch",name) diff --git a/src/Mod/Arch/ArchStructure.py b/src/Mod/Arch/ArchStructure.py index 15595c3329..c09a9621a2 100644 --- a/src/Mod/Arch/ArchStructure.py +++ b/src/Mod/Arch/ArchStructure.py @@ -69,6 +69,9 @@ def makeStructure(baseobj=None,length=None,width=None,height=None,name="Structur structure element based on the given profile object and the given extrusion height. If no base object is given, you can also specify length and width for a cubic object.''' + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch") obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name) obj.Label = translate("Arch",name) @@ -101,6 +104,9 @@ def makeStructure(baseobj=None,length=None,width=None,height=None,name="Structur def makeStructuralSystem(objects=[],axes=[],name="StructuralSystem"): '''makeStructuralSystem(objects,axes): makes a structural system based on the given objects and axes''' + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return result = [] if not axes: print("At least one axis must be given") diff --git a/src/Mod/Arch/ArchWall.py b/src/Mod/Arch/ArchWall.py index e6f8790ce6..98702a2c76 100644 --- a/src/Mod/Arch/ArchWall.py +++ b/src/Mod/Arch/ArchWall.py @@ -57,6 +57,9 @@ def makeWall(baseobj=None,length=None,width=None,height=None,align="Center",face given object, which can be a sketch, a draft object, a face or a solid, or no object at all, then you must provide length, width and height. Align can be "Center","Left" or "Right", face can be an index number of a face in the base object to base the wall on.''' + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch") obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name) obj.Label = translate("Arch",name) diff --git a/src/Mod/Arch/ArchWindow.py b/src/Mod/Arch/ArchWindow.py index 5cc53e1a8c..ed2b44e54a 100644 --- a/src/Mod/Arch/ArchWindow.py +++ b/src/Mod/Arch/ArchWindow.py @@ -63,6 +63,9 @@ def makeWindow(baseobj=None,width=None,height=None,parts=None,name="Window"): '''makeWindow(baseobj,[width,height,parts,name]): creates a window based on the given base 2D object (sketch or draft).''' + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return if baseobj: if Draft.getType(baseobj) == "Window": obj = Draft.clone(baseobj) @@ -112,6 +115,10 @@ def makeWindowPreset(windowtype,width,height,h1,h2,h3,w1,w2,o1,o2,placement=None window object based on the given data. windowtype must be one of the names defined in Arch.WindowPresets""" + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return + def makeSketch(windowtype,width,height,h1,h2,h3,w1,w2,o1,o2): import Part,Sketcher diff --git a/src/Mod/Draft/Draft.py b/src/Mod/Draft/Draft.py index 448ff610a8..030647d983 100644 --- a/src/Mod/Draft/Draft.py +++ b/src/Mod/Draft/Draft.py @@ -666,6 +666,9 @@ def makeCircle(radius, placement=None, face=None, startangle=None, endangle=None wireframe, otherwise as a face. If startangle AND endangle are given (in degrees), they are used and the object appears as an arc. If an edge is passed, its Curve must be a Part.Circle''' + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return import Part, DraftGeomUtils if placement: typecheck([(placement,FreeCAD.Placement)], "makeCircle") if startangle != endangle: @@ -711,6 +714,9 @@ def makeRectangle(length, height, placement=None, face=None, support=None): object with length in X direction and height in Y direction. If a placement is given, it is used. If face is False, the rectangle is shown as a wireframe, otherwise as a face.''' + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return if placement: typecheck([(placement,FreeCAD.Placement)], "makeRectangle") obj = FreeCAD.ActiveDocument.addObject("Part::Part2DObjectPython","Rectangle") _Rectangle(obj) @@ -741,6 +747,9 @@ def makeDimension(p1,p2,p3=None,p4=None): to the given object, i1 is the index of the (curved) edge to measure, and mode is either "radius" or "diameter". ''' + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return obj = FreeCAD.ActiveDocument.addObject("App::FeaturePython","Dimension") _Dimension(obj) if gui: @@ -802,6 +811,9 @@ def makeAngularDimension(center,angles,p3,normal=None): '''makeAngularDimension(center,angle1,angle2,p3,[normal]): creates an angular Dimension from the given center, with the given list of angles, passing through p3. ''' + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return obj = FreeCAD.ActiveDocument.addObject("App::FeaturePython","Dimension") _AngularDimension(obj) obj.Center = center @@ -835,6 +847,9 @@ def makeWire(pointslist,closed=False,placement=None,face=None,support=None): and last points are identical, the wire is closed. If face is true (and wire is closed), the wire will appear filled. Instead of a pointslist, you can also pass a Part Wire.''' + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return import DraftGeomUtils, Part if not isinstance(pointslist,list): e = pointslist.Wires[0].Edges @@ -874,6 +889,9 @@ def makePolygon(nfaces,radius=1,inscribed=True,placement=None,face=None,support= with the given radius, otherwise it is inscribed. If face is True, the resulting shape is displayed as a face, otherwise as a wireframe. ''' + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return if nfaces < 3: return None obj = FreeCAD.ActiveDocument.addObject("Part::Part2DObjectPython","Polygon") _Polygon(obj) @@ -905,6 +923,9 @@ def makeBSpline(pointslist,closed=False,placement=None,face=None,support=None): and last points are identical, the wire is closed. If face is true (and wire is closed), the wire will appear filled. Instead of a pointslist, you can also pass a Part Wire.''' + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return from DraftTools import msg if not isinstance(pointslist,list): nlist = [] @@ -944,6 +965,9 @@ def makeBSpline(pointslist,closed=False,placement=None,face=None,support=None): def makeBezCurve(pointslist,closed=False,placement=None,face=None,support=None,Degree=None): '''makeBezCurve(pointslist,[closed],[placement]): Creates a Bezier Curve object from the given list of vectors. Instead of a pointslist, you can also pass a Part Wire.''' + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return if not isinstance(pointslist,list): nlist = [] for v in pointslist.Vertexes: @@ -982,6 +1006,9 @@ def makeText(stringslist,point=Vector(0,0,0),screen=False): can also be one single string). The current color and text height and font specified in preferences are used. If screen is True, the text always faces the view direction.''' + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return typecheck([(point,Vector)], "makeText") if not isinstance(stringslist,list): stringslist = [stringslist] obj=FreeCAD.ActiveDocument.addObject("App::Annotation","Text") @@ -1002,6 +1029,9 @@ def makeText(stringslist,point=Vector(0,0,0),screen=False): def makeCopy(obj,force=None,reparent=False): '''makeCopy(object): returns an exact copy of an object''' + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return if (getType(obj) == "Rectangle") or (force == "Rectangle"): newobj = FreeCAD.ActiveDocument.addObject(obj.TypeId,getRealName(obj.Name)) _Rectangle(newobj) @@ -1108,6 +1138,9 @@ def makeCopy(obj,force=None,reparent=False): def makeBlock(objectslist): '''makeBlock(objectslist): Creates a Draft Block from the given objects''' + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return obj = FreeCAD.ActiveDocument.addObject("Part::Part2DObjectPython","Block") _Block(obj) obj.Components = objectslist @@ -1127,6 +1160,9 @@ def makeArray(baseobject,arg1,arg2,arg3,arg4=None,name="Array"): and ynum. In case of polar array, center is a vector, totalangle is the angle to cover (in degrees) and totalnum is the number of objects, including the original. The result is a parametric Draft Array.''' + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name) _Array(obj) obj.Base = baseobject @@ -1157,6 +1193,9 @@ def makePathArray(baseobject,pathobject,count,xlate=None,align=False,pathobjsubs pathobject. Optionally translates each copy by FreeCAD.Vector xlate direction and distance to adjust for difference in shape centre vs shape reference point. Optionally aligns baseobject to tangent/normal/binormal of path.''' + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython","PathArray") _PathArray(obj) obj.Base = baseobject @@ -1185,6 +1224,9 @@ def makeEllipse(majradius,minradius,placement=None,face=True,support=None): '''makeEllipse(majradius,minradius,[placement],[face],[support]): makes an ellipse with the given major and minor radius, and optionally a placement.''' + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return obj = FreeCAD.ActiveDocument.addObject("Part::Part2DObjectPython","Ellipse") _Ellipse(obj) if minradius > majradius: @@ -1206,6 +1248,9 @@ def makeEllipse(majradius,minradius,placement=None,face=True,support=None): def makeVisGroup(group=None,name="VisGroup"): '''makeVisGroup([group]): creates a VisGroup object in the given group, or in the active document if no group is given''' + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return obj = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroupPython",name) _VisGroup(obj) if FreeCAD.GuiUp: @@ -1219,6 +1264,9 @@ def extrude(obj,vector,solid=False): '''makeExtrusion(object,vector): extrudes the given object in the direction given by the vector. The original object gets hidden.''' + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return newobj = FreeCAD.ActiveDocument.addObject("Part::Extrusion","Extrusion") newobj.Base = obj newobj.Dir = vector @@ -1235,6 +1283,9 @@ def fuse(object1,object2): the union of the 2 given objects. If the objects are coplanar, a special Draft Wire is used, otherwise we use a standard Part fuse.''' + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return import DraftGeomUtils, Part # testing if we have holes: holes = False @@ -1267,6 +1318,9 @@ def fuse(object1,object2): return obj def cut(object1,object2): + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return '''cut(oject1,object2): returns a cut object made from the difference of the 2 given objects.''' obj = FreeCAD.ActiveDocument.addObject("Part::Cut","Cut") @@ -2587,6 +2641,9 @@ def makeDrawingView(obj,page,lwmod=None,tmod=None,otherProjection=None): given page. lwmod modifies lineweights (in percent), tmod modifies text heights (in percent). The Hint scale, X and Y of the page are used. ''' + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return if getType(obj) == "SectionPlane": import ArchSectionPlane viewobj = FreeCAD.ActiveDocument.addObject("Drawing::FeatureViewPython","View") @@ -2639,6 +2696,9 @@ def makeShape2DView(baseobj,projectionVector=None,facenumbers=[]): 2D projection of the given object. A specific projection vector can also be given. You can also specify a list of face numbers to be considered in individual faces mode. ''' + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return obj = FreeCAD.ActiveDocument.addObject("Part::Part2DObjectPython","Shape2DView") _Shape2DView(obj) if gui: @@ -2678,6 +2738,10 @@ def makeSketch(objectslist,autoconstraints=False,addTo=None, precision, and 'Equal' constraint will be added to curve with equal radius within precision.''' + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return + import Part, DraftGeomUtils from Sketcher import Constraint import Sketcher @@ -2942,6 +3006,9 @@ def makePoint(X=0, Y=0, Z=0,color=None,name = "Point", point_size= 5): p1.X = 1 #move it in x p1.ViewObject.PointColor =(0.0,0.0,1.0) #change the color-make sure values are floats ''' + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return obj=FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name) if isinstance(X,FreeCAD.Vector): Z = X.z @@ -2965,6 +3032,9 @@ def makePoint(X=0, Y=0, Z=0,color=None,name = "Point", point_size= 5): def makeShapeString(String,FontFile,Size = 100,Tracking = 0): '''ShapeString(Text,FontFile,Height,Track): Turns a text string into a Compound Shape''' + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return obj = FreeCAD.ActiveDocument.addObject("Part::Part2DObjectPython","ShapeString") _ShapeString(obj) obj.String = String @@ -3154,6 +3224,9 @@ def heal(objlist=None,delete=True,reparent=True): def makeFacebinder(selectionset,name="Facebinder"): """makeFacebinder(selectionset,[name]): creates a Facebinder object from a selection set. Only faces will be added.""" + if not FreeCAD.ActiveDocument: + FreeCAD.Console.PrintError("No active document. Aborting\n") + return if not isinstance(selectionset,list): selectionset = [selectionset] fb = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name)