def accept(self): self.preview.clean() # Create new ship instance obj = App.ActiveDocument.addObject("Part::FeaturePython", "Ship") ship = Instance.Ship(obj, self.solids) Instance.ViewProviderShip(obj.ViewObject) # Set main dimensions obj.Length = self.form.length.value() obj.Beam = self.form.beam.value() obj.Draft = self.form.draft.value() # Discretize it App.ActiveDocument.recompute() return True
def accept(self): """Create the ship instance""" self.preview.clean() obj = App.ActiveDocument.addObject("Part::FeaturePython", "Ship") ship = Instance.Ship(obj, self.solids) Instance.ViewProviderShip(obj.ViewObject) mw = self.getMainWindow() form = mw.findChild(QtGui.QWidget, "TaskPanel") form.length = self.widget(QtGui.QDoubleSpinBox, "Length") form.breadth = self.widget(QtGui.QDoubleSpinBox, "Breadth") form.draft = self.widget(QtGui.QDoubleSpinBox, "Draft") obj.Length = '{} m'.format(form.length.value()) obj.Breadth = '{} m'.format(form.breadth.value()) obj.Draft = '{} m'.format(form.draft.value()) App.ActiveDocument.recompute() return True
def createShip(solids, L, B, T): """Create a new ship instance Position arguments: solids -- List of hull solid shapes L -- Ship length between perpendiculars B -- Ship Breadth T -- Ship design draft Returned value: The new ship object The solids can be easily extracted from an already existing object. For instance, to get the solids from the selected object simply type the following command: solids = Gui.ActiveDocument.ActiveObject.Object.Shape.Solids Regarding the Length, Breadth, and Draft, it is strongly recommended to use Units.parseQuantity method, e.g. The following obfuscated code snippet build such variables: import Units L = Units.parseQuantity("25.5 m") B = Units.parseQuantity("3.9 m") T = Units.parseQuantity("1.0 m") """ obj = App.ActiveDocument.addObject("Part::FeaturePython", "Ship") ship = Instance.Ship(obj, solids) Instance.ViewProviderShip(obj.ViewObject) obj.Length = L obj.Breadth = B obj.Draft = T App.ActiveDocument.recompute() return obj