Body.Tip not updated when a Mirrored Feature is added.

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
vectronic
Posts: 52
Joined: Sun Feb 18, 2018 9:44 pm

Body.Tip not updated when a Mirrored Feature is added.

Post by vectronic »

Hello,

I am hoping someone can tell me whether I have either found a bug or am doing something wrong.

I can create a Body in Part Design and then add a sketch and features such as Pads and Pockets (all via the Python API).

I can set the latest feature visible using the Python API via:

Code: Select all

myBody.Tip.ViewObject.Visibility = True
However if I then add a Mirrored Feature and again use:

Code: Select all

myBody.Tip
this returns the last Pad/Pocket Feature added before the Mirrored Feature.

The screenshot below shows the state after I have added a Mirrored Feature and then invoked

Code: Select all

myBody.Tip.ViewObject.Visibility = True
Screenshot 2019-02-10 at 14.16.57.png
Screenshot 2019-02-10 at 14.16.57.png (38.55 KiB) Viewed 431 times
Should a Body's Tip be updated to point to the Mirrored Feature?

If it should not by design, then can anyone tell me an alternative way that I could programmatically access the last added Feature on a body (including referencing a Mirrored Feature)?

I have also attached the sample file used for the screenshot.

I am not using the latest from Git, but the latest release 0.18_pre build for MacOS. (I have struggled to build from the latest source on Mac. I have had a look at the commit comments since the release I am using and couldn't see anything related.)

Thanks very much.


OS: macOS 10.14
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.15525 (Git)
Build type: Release
Branch: master
Hash: 1a7d3d9a37fe43468c8ac84590c1db53e2b2000a
Python version: 3.6.7
Qt version: 5.6.2
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedKingdom (en_GB)
Attachments
temp.FCStd
(305.32 KiB) Downloaded 14 times
wmayer
Founder
Posts: 20298
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Body.Tip not updated when a Mirrored Feature is added.

Post by wmayer »

Should a Body's Tip be updated to point to the Mirrored Feature?
Yes. If I got you right you do all this by scripting. So, it's up to you to set the tip of the body to the mirror object.

You can e.g. enable the macro recording to print all executed Python into to the console window. There you should find a line which assigns the mirror to the body tip.

Example code:

Code: Select all

App.newDocument("Unbenannt")
App.activeDocument().addObject('PartDesign::Body','Body')
Gui.activeView().setActiveObject('pdbody', App.activeDocument().Body)
App.activeDocument().Body.newObject('Sketcher::SketchObject','Sketch')
App.activeDocument().Sketch.Support = (App.activeDocument().XY_Plane, [''])
App.activeDocument().Sketch.MapMode = 'FlatFace'
App.ActiveDocument.recompute()
Gui.activeDocument().setEdit('Sketch')

import PartDesignGui
ActiveSketch = App.ActiveDocument.getObject('Sketch')

geoList = []
geoList.append(Part.LineSegment(App.Vector(-19.859026,13.610367,0),App.Vector(21.382137,13.610367,0)))
geoList.append(Part.LineSegment(App.Vector(21.382137,13.610367,0),App.Vector(21.382137,-11.657660,0)))
geoList.append(Part.LineSegment(App.Vector(21.382137,-11.657660,0),App.Vector(-19.859026,-11.657660,0)))
geoList.append(Part.LineSegment(App.Vector(-19.859026,-11.657660,0),App.Vector(-19.859026,13.610367,0)))
App.ActiveDocument.Sketch.addGeometry(geoList,False)
conList = []
conList.append(Sketcher.Constraint('Coincident',0,2,1,1))
conList.append(Sketcher.Constraint('Coincident',1,2,2,1))
conList.append(Sketcher.Constraint('Coincident',2,2,3,1))
conList.append(Sketcher.Constraint('Coincident',3,2,0,1))
conList.append(Sketcher.Constraint('Horizontal',0))
conList.append(Sketcher.Constraint('Horizontal',2))
conList.append(Sketcher.Constraint('Vertical',1))
conList.append(Sketcher.Constraint('Vertical',3))
App.ActiveDocument.Sketch.addConstraint(conList)

Gui.getDocument('Unbenannt').resetEdit()

App.activeDocument().Body.newObject("PartDesign::Pad","Pad")
App.activeDocument().Pad.Profile = App.activeDocument().Sketch
App.activeDocument().Pad.Length = 10.0
App.ActiveDocument.recompute()
Gui.activeDocument().hide("Sketch")
App.ActiveDocument.recompute()
Gui.ActiveDocument.Pad.ShapeColor=Gui.ActiveDocument.Body.ShapeColor
Gui.ActiveDocument.Pad.LineColor=Gui.ActiveDocument.Body.LineColor
Gui.ActiveDocument.Pad.PointColor=Gui.ActiveDocument.Body.PointColor
Gui.ActiveDocument.Pad.Transparency=Gui.ActiveDocument.Body.Transparency
Gui.ActiveDocument.Pad.DisplayMode=Gui.ActiveDocument.Body.DisplayMode
Gui.activeDocument().setEdit('Pad', 0)
Gui.Selection.clearSelection()
Gui.activeDocument().hide("Sketch")
App.ActiveDocument.Pad.Length = 10.000000
App.ActiveDocument.Pad.Length2 = 100.000000
App.ActiveDocument.Pad.Type = 0
App.ActiveDocument.Pad.UpToFace = None
App.ActiveDocument.Pad.Reversed = 0
App.ActiveDocument.Pad.Midplane = 0
App.ActiveDocument.Pad.Offset = 0.000000
App.ActiveDocument.recompute()
Gui.activeDocument().resetEdit()
App.activeDocument().Body.newObject('Sketcher::SketchObject','Sketch001')
App.activeDocument().Sketch001.Support = (App.ActiveDocument.Pad,["Face6"])
App.activeDocument().Sketch001.MapMode = 'FlatFace'
App.ActiveDocument.recompute()
Gui.activeDocument().setEdit('Sketch001')
Gui.activateWorkbench('SketcherWorkbench')

import PartDesignGui

ActiveSketch = App.ActiveDocument.getObject('Sketch001')
if ActiveSketch.ViewObject.RestoreCamera:
  ActiveSketch.ViewObject.TempoVis.saveCamera()

geoList = []
geoList.append(Part.LineSegment(App.Vector(-13.274072,9.593348,0),App.Vector(-8.626629,9.593348,0)))
geoList.append(Part.LineSegment(App.Vector(-8.626629,9.593348,0),App.Vector(-8.626629,6.547125,0)))
geoList.append(Part.LineSegment(App.Vector(-8.626629,6.547125,0),App.Vector(-13.274072,6.547125,0)))
geoList.append(Part.LineSegment(App.Vector(-13.274072,6.547125,0),App.Vector(-13.274072,9.593348,0)))
App.ActiveDocument.Sketch001.addGeometry(geoList,False)
conList = []
conList.append(Sketcher.Constraint('Coincident',0,2,1,1))
conList.append(Sketcher.Constraint('Coincident',1,2,2,1))
conList.append(Sketcher.Constraint('Coincident',2,2,3,1))
conList.append(Sketcher.Constraint('Coincident',3,2,0,1))
conList.append(Sketcher.Constraint('Horizontal',0))
conList.append(Sketcher.Constraint('Horizontal',2))
conList.append(Sketcher.Constraint('Vertical',1))
conList.append(Sketcher.Constraint('Vertical',3))
App.ActiveDocument.Sketch001.addConstraint(conList)

Gui.getDocument('Unbenannt').resetEdit()

Gui.activateWorkbench('PartDesignWorkbench')
App.getDocument('Unbenannt').recompute()
App.activeDocument().Body.newObject("PartDesign::Pad","Pad001")
App.activeDocument().Pad001.Profile = App.activeDocument().Sketch001
App.activeDocument().Pad001.Length = 10.0
App.ActiveDocument.recompute()
Gui.activeDocument().hide("Sketch001")
App.ActiveDocument.recompute()
Gui.ActiveDocument.Pad001.ShapeColor=Gui.ActiveDocument.Body.ShapeColor
Gui.ActiveDocument.Pad001.LineColor=Gui.ActiveDocument.Body.LineColor
Gui.ActiveDocument.Pad001.PointColor=Gui.ActiveDocument.Body.PointColor
Gui.ActiveDocument.Pad001.Transparency=Gui.ActiveDocument.Body.Transparency
Gui.ActiveDocument.Pad001.DisplayMode=Gui.ActiveDocument.Body.DisplayMode
Gui.activeDocument().setEdit('Pad001', 0)
Gui.Selection.clearSelection()
Gui.activeDocument().hide("Sketch001")
App.ActiveDocument.Pad001.Length = 10.000000
App.ActiveDocument.Pad001.Length2 = 100.000000
App.ActiveDocument.Pad001.Type = 0
App.ActiveDocument.Pad001.UpToFace = None
App.ActiveDocument.Pad001.Reversed = 0
App.ActiveDocument.Pad001.Midplane = 0
App.ActiveDocument.Pad001.Offset = 0.000000
Gui.activeDocument().hide("Pad")
App.ActiveDocument.recompute()
Gui.activeDocument().resetEdit()
App.activeDocument().Body.newObject("PartDesign::Mirrored","Mirrored")
App.ActiveDocument.recompute()
App.activeDocument().Mirrored.Originals = [App.activeDocument().Pad001,]
App.activeDocument().Mirrored.MirrorPlane = (App.activeDocument().Sketch001, ["V_Axis"])
App.ActiveDocument.recompute()
Gui.ActiveDocument.Mirrored.ShapeColor=Gui.ActiveDocument.Body.ShapeColor
Gui.ActiveDocument.Mirrored.LineColor=Gui.ActiveDocument.Body.LineColor
Gui.ActiveDocument.Mirrored.PointColor=Gui.ActiveDocument.Body.PointColor
Gui.ActiveDocument.Mirrored.Transparency=Gui.ActiveDocument.Body.Transparency
Gui.ActiveDocument.Mirrored.DisplayMode=Gui.ActiveDocument.Body.DisplayMode
Gui.activeDocument().setEdit('Mirrored', 0)
Gui.Selection.clearSelection()
App.activeDocument().Body.Tip = App.activeDocument().Mirrored
Gui.activeDocument().show("Mirrored")
App.ActiveDocument.recompute()
App.ActiveDocument.Mirrored.MirrorPlane = (App.ActiveDocument.Sketch001, ["V_Axis"])
App.ActiveDocument.Mirrored.Originals = [App.ActiveDocument.Pad001,]
Gui.activeDocument().hide("Pad001")
App.ActiveDocument.recompute()
Gui.activeDocument().resetEdit()
vectronic
Posts: 52
Joined: Sun Feb 18, 2018 9:44 pm

Re: Body.Tip not updated when a Mirrored Feature is added.

Post by vectronic »

Hi, thanks for the reply.

I hadn't considered updating the Body.Tip myself when creating the Mirror Feature. All the other features e.g. Pad, Pocket seem to update the Tip without needing to do it explicitly...?

Anyway in the case of creating a Mirror I have now updated the Tip explicitly and it works as expected.

Thanks very much.
Post Reply