Python FreeCADGui.activeDocument() Examples

The following are 30 code examples of FreeCADGui.activeDocument(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module FreeCADGui , or try the search function .
Example #1
Source File: frameForms.py    From flamingo with GNU Lesser General Public License v3.0 6 votes vote down vote up
def accept(self):
    if self.labTail:
      self.labTail.removeLabel()
      self.labTail=None
    self.L=frameCmd.getDistance()
    if self.form.edit1.text():
      length=float(self.form.edit1.text())
      FreeCAD.activeDocument().openTransaction('Stretch beam')
      for beam in frameCmd.beams():
        delta=float(beam.Height)-length
        frameCmd.stretchTheBeam(beam,length)
        if self.form.tail.isChecked():
          disp=frameCmd.beamAx(beam).multiply(delta)
          beam.Placement.move(disp)
        elif self.form.both.isChecked():
          disp=frameCmd.beamAx(beam).multiply(delta/2.0)
          beam.Placement.move(disp)
      FreeCAD.activeDocument().recompute()
      FreeCAD.activeDocument().commitTransaction() 
Example #2
Source File: Animation.py    From Animation with GNU General Public License v2.0 6 votes vote down vote up
def createMoviescreen(name='My_Moviescreen'):

	obj = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroupPython",name)
	obj.addProperty("App::PropertyIntegerList","pictureStart","info","Rotationsachse Zentrum relativ").pictureStart=[0,50,100]
	obj.addProperty("App::PropertyPath","pictures","screen","text").pictures="/home/microelly2/pics/t%04.f.png"
	obj.addProperty("App::PropertyLink","rectangle","screen","moving object ")

	obj.rectangle = FreeCAD.ActiveDocument.addObject("Part::Part2DObjectPython","Rectangle Moviescreen")
	Draft._Rectangle(obj.rectangle)
	obj.rectangle.Length = 64
	obj.rectangle.Height = 48
	obj.rectangle.MakeFace = True
	Draft._ViewProviderRectangle(obj.rectangle.ViewObject)
	tx=FreeCADGui.activeDocument().activeView()
	rx=tx.getCameraOrientation()
	obj.rectangle.Placement.Rotation=rx
	_Moviescreen(obj)
	return obj 
Example #3
Source File: frameObservers.py    From flamingo with GNU Lesser General Public License v3.0 6 votes vote down vote up
def addSelection(self,doc,obj,sub,pnt):
      lastSel=FreeCAD.getDocument(doc).getObject(obj)
      subLastSel=lastSel.Shape.getElement(sub)
      if lastSel.TypeId=='Part::FeaturePython' and hasattr(lastSel,"Height") and subLastSel.ShapeType=="Edge":
        self.edges.append(subLastSel)
        self.beams.append(lastSel)
        FreeCAD.Console.PrintMessage('Edge/beam pair nr.'+str(len(self.edges))+'  selected.\n')
      if (len(self.edges)==len(self.beams)==2):
        if frameCmd.isOrtho(*self.edges):
          self.beams.reverse()
          FreeCAD.ActiveDocument.openTransaction('Adjust angle')
          for i in range(len(self.edges)):
          	frameCmd.extendTheBeam(self.beams[i],self.edges[i])
          FreeCAD.ActiveDocument.commitTransaction()
          FreeCAD.Console.PrintWarning("Adjustment executed.\n")
        else:
          FreeCAD.Console.PrintError("Edges must be orthogonal.\n")
        self.edges=[]
        self.beams=[]
        FreeCADGui.Selection.clearSelection()
        FreeCAD.activeDocument().recompute()
        FreeCAD.Console.PrintWarning("Repeat selection or press [ESC]\n") 
Example #4
Source File: frameObservers.py    From flamingo with GNU Lesser General Public License v3.0 6 votes vote down vote up
def addSelection(self,doc,obj,sub,pnt):
      lastSel=FreeCAD.getDocument(doc).getObject(obj)
      subLastSel=lastSel.Shape.getElement(sub)
      if subLastSel.ShapeType=="Edge":
        self.edges.append(subLastSel)
        FreeCAD.Console.PrintMessage('Edge'+str(len(self.edges))+' OK.\n')
      if len(self.edges)==2:
        try:
          FreeCAD.activeDocument().openTransaction('rotJoin')
          frameCmd.rotjoinTheBeam()
          FreeCAD.activeDocument().commitTransaction()
          FreeCAD.activeDocument().recompute()
          FreeCAD.Console.PrintWarning("Edges aligned.\n")
        except:
          FreeCAD.Console.PrintError("Edges must be selected holding [Ctrl] down for the correct execution. \nRetry.\n")
        self.edges=[]
        FreeCADGui.Selection.clearSelection()
        FreeCAD.Console.PrintWarning("Repeat selection or press [ESC]\n") 
Example #5
Source File: a2p_importpart.py    From A2plus with GNU Lesser General Public License v2.1 6 votes vote down vote up
def a2p_FlipConstraintDirection():
    ''' updating constraints, deactivated at moment'''
    constraints = [ obj for obj in FreeCAD.ActiveDocument.Objects 
                        if 'ConstraintInfo' in obj.Content ]
    if len(constraints) == 0:
        QtGui.QMessageBox.information(
            QtGui.qApp.activeWindow(),
            "Command Aborted", 
            'Flip aborted since no a2p constraints in active document.'
            )
        return
    lastConstraintAdded = constraints[-1]
    try:
        if lastConstraintAdded.directionConstraint == 'aligned':
            lastConstraintAdded.directionConstraint = 'opposed'
        else:
            lastConstraintAdded.directionConstraint = 'aligned'
        a2p_solversystem.autoSolveConstraints(FreeCAD.activeDocument(), callingFuncName="a2p_FlipConstraintDirection")
    except:
        pass 
Example #6
Source File: pipeCmd.py    From flamingo with GNU Lesser General Public License v3.0 6 votes vote down vote up
def breakTheTubes(point,pipes=[],gap=0):
  '''
  breakTheTube(point,pipes=[],gap=0)
  Breaks the "pipes" at "point" leaving a "gap".
  '''
  pipes2nd=list()
  if not pipes:
    pipes=[p for p in frameCmd.beams() if isPipe(p)]
  if pipes:
    for pipe in pipes:
      if point<float(pipe.Height) and gap<(float(pipe.Height)-point):
        propList=[pipe.PSize,float(pipe.OD),float(pipe.thk),float(pipe.Height)-point-gap]
        pipe.Height=point
        Z=frameCmd.beamAx(pipe)
        pos=pipe.Placement.Base+Z*(float(pipe.Height)+gap)
        pipe2nd=makePipe(propList,pos,Z)
        pipes2nd.append(pipe2nd)
    #FreeCAD.activeDocument().recompute()
  return pipes2nd 
Example #7
Source File: pipeCmd.py    From flamingo with GNU Lesser General Public License v3.0 6 votes vote down vote up
def makeRoute(n=Z):
  curvedEdges=[e for e in frameCmd.edges() if e.curvatureAt(0)!=0]
  if curvedEdges:
    s=FreeCAD.ActiveDocument.addObject('Sketcher::SketchObject','pipeRoute')
    s.MapMode = "SectionOfRevolution"
    s.Support = [frameCmd.edgeName()]
  else:
    return None
  if frameCmd.faces(): 
    n=frameCmd.faces()[0].normalAt(0,0)
  x=s.Placement.Rotation.multVec(X)
  z=s.Placement.Rotation.multVec(Z)
  t=x.dot(n)*x+z.dot(n)*z
  alfa=degrees(z.getAngle(t))
  if t.Length>0.000000001:
    s.AttachmentOffset.Rotation=s.AttachmentOffset.Rotation.multiply(FreeCAD.Rotation(Y,alfa))
  FreeCAD.ActiveDocument.recompute()
  FreeCADGui.activeDocument().setEdit(s.Name) 
Example #8
Source File: pipeForms.py    From flamingo with GNU Lesser General Public License v3.0 6 votes vote down vote up
def apply(self):
    self.lastPipe=None
    if self.edit1.text():
      self.H=float(self.edit1.text())
    else:
      self.H=200.0
    self.sli.setValue(100)
    for obj in FreeCADGui.Selection.getSelection():
      d=self.pipeDictList[self.sizeList.currentRow()]
      if hasattr(obj,'PType') and obj.PType==self.PType:
        obj.PSize=d['PSize']
        obj.OD=pq(d['OD'])
        obj.thk=pq(d['thk'])
        obj.PRating=self.PRating
        if self.edit1.text():
          obj.Height=self.H
        FreeCAD.activeDocument().recompute() 
Example #9
Source File: pipeForms.py    From flamingo with GNU Lesser General Public License v3.0 6 votes vote down vote up
def getBase(self):
    if self.combo.currentText()!="<new>":                                           
      pl=FreeCAD.ActiveDocument.getObjectsByLabel(self.combo.currentText())[0]    
      sel=FreeCADGui.Selection.getSelection()
      if sel:
        base=sel[0]
        isWire=hasattr(base,'Shape') and base.Shape.Edges #type(base.Shape)==Part.Wire
        isSketch=hasattr(base,'TypeId') and base.TypeId=='Sketcher::SketchObject'
        if isWire or isSketch:
          FreeCAD.activeDocument().openTransaction('Assign Base')
          pl.Base=base
          if isWire:
            pipeCmd.drawAsCenterLine(pl.Base)
            pipeCmd.moveToPyLi(pl.Base,self.combo.currentText())
          FreeCAD.activeDocument().commitTransaction()
        else:
          FreeCAD.Console.PrintError('Not valid Base: select a Wire or a Sketch.\n')
      else:
        pl.Base=None
        FreeCAD.Console.PrintWarning(pl.Label+'-> deleted Base\n')
    else:
      FreeCAD.Console.PrintError('Please choose or create a PypeLine first\n') 
Example #10
Source File: pipeForms.py    From flamingo with GNU Lesser General Public License v3.0 6 votes vote down vote up
def breakPipe(self):
    p2nd=None
    FreeCAD.activeDocument().openTransaction('Break pipes')
    if self.edit1.text()[-1]=='%':
      pipes=[p for p in frameCmd.beams() if pipeCmd.isPipe(p)]
      for p in pipes:
        p2nd=pipeCmd.breakTheTubes(float(p.Height)*float(self.edit1.text().rstrip('%').strip())/100,pipes=[p],gap=float(self.edit2.text()))
        if p2nd and self.combo.currentText()!='<none>':
          for p in p2nd:
            pipeCmd.moveToPyLi(p,self.combo.currentText())
    else:
      p2nd=pipeCmd.breakTheTubes(float(self.edit1.text()),gap=float(self.edit2.text()))
      if p2nd and self.combo.currentText()!='<none>':
        for p in p2nd:
          pipeCmd.moveToPyLi(p,self.combo.currentText())
    FreeCAD.activeDocument().commitTransaction()
    FreeCAD.activeDocument().recompute() 
Example #11
Source File: a2p_importpart.py    From A2plus with GNU Lesser General Public License v2.1 5 votes vote down vote up
def Activated(self, index):
        if index == 0:
            ''' Remove the existing labels from screen'''
            doc = FreeCAD.activeDocument()
            dofGroup = doc.getObject("dofLabels")
            if dofGroup != None:
                for lbl in dofGroup.Group:
                    doc.removeObject(lbl.Name)
                doc.removeObject("dofLabels")
        else:
            ss = a2p_solversystem.SolverSystem()
            ss.DOF_info_to_console() 
Example #12
Source File: a2p_importpart.py    From A2plus with GNU Lesser General Public License v2.1 5 votes vote down vote up
def IsChecked(self):
        doc = FreeCAD.activeDocument()
        if not doc: return False
        dofGroup = doc.getObject("dofLabels")
        return dofGroup != None 
Example #13
Source File: a2p_importpart.py    From A2plus with GNU Lesser General Public License v2.1 5 votes vote down vote up
def Activated(self):
        doc = FreeCAD.activeDocument()
        try:
            doc.save()
            FreeCAD.closeDocument(doc.Name)
        except:
            FreeCADGui.SendMsgToActiveView("Save")
            if not FreeCADGui.activeDocument().Modified: # user really saved the file           
                FreeCAD.closeDocument(doc.Name)
        #
        mw = FreeCADGui.getMainWindow()
        mdi = mw.findChild(QtGui.QMdiArea)
        sub = mdi.activeSubWindow()
        if sub != None:
            sub.showMaximized() 
Example #14
Source File: a2p_importpart.py    From A2plus with GNU Lesser General Public License v2.1 5 votes vote down vote up
def Activated(self):
        if FreeCAD.activeDocument() is None:
            QtGui.QMessageBox.information(  QtGui.QApplication.activeWindow(),
                                        "No active document found!",
                                        "You have to open an assembly file first."
                                    )
            return
        a2p_FlipConstraintDirection() 
Example #15
Source File: a2p_importpart.py    From A2plus with GNU Lesser General Public License v2.1 5 votes vote down vote up
def IsActive(self):
        doc = FreeCAD.activeDocument()
        return doc != None 
Example #16
Source File: a2p_importpart.py    From A2plus with GNU Lesser General Public License v2.1 5 votes vote down vote up
def __init__(self, view):
        self.obj = None
        self.view = view
        self.doc = FreeCAD.activeDocument()
        self.callbackMove = self.view.addEventCallback("SoLocation2Event",self.onMouseMove)
        self.callbackClick = self.view.addEventCallback("SoMouseButtonEvent",self.onMouseClicked)
        self.callbackKey = self.view.addEventCallback("SoKeyboardEvent",self.KeyboardEvent)
        self.motionActivated = False 
Example #17
Source File: a2p_importpart.py    From A2plus with GNU Lesser General Public License v2.1 5 votes vote down vote up
def IsActive(self):
        doc = FreeCAD.activeDocument()
        if doc is None: return False
        #
        selection = [s for s in FreeCADGui.Selection.getSelectionEx() if s.Document == doc ]
        if len(selection) != 1: return False
        #
        obj = selection[0].Object
        if not a2plib.isA2pPart(obj): return False
        #
        return True 
Example #18
Source File: a2p_importpart.py    From A2plus with GNU Lesser General Public License v2.1 5 votes vote down vote up
def Activated(self):
        doc = FreeCAD.activeDocument()
        selection = [s for s in FreeCADGui.Selection.getSelectionEx() if s.Document == doc ]
        FreeCADGui.ActiveDocument.setEdit(selection[0].Object) 
Example #19
Source File: a2p_importpart.py    From A2plus with GNU Lesser General Public License v2.1 5 votes vote down vote up
def Activated(self):
        flags = QtGui.QMessageBox.StandardButton.Yes | QtGui.QMessageBox.StandardButton.No
        response = QtGui.QMessageBox.information(
            QtGui.QApplication.activeWindow(), 
            u"Migrate proxies of importedParts to recent version", 
            u"Make sure you have a backup of your files. Proceed?", 
            flags
            )
        if response == QtGui.QMessageBox.Yes:
            doc = FreeCAD.activeDocument()
            for ob in doc.Objects:
                if a2plib.isA2pPart(ob):
                    #setup proxies
                    a2p_importedPart_class.Proxy_importPart(ob)
                    if FreeCAD.GuiUp:
                        a2p_importedPart_class.ImportedPartViewProviderProxy(ob.ViewObject)
                    #delete obsolete properties
                    deleteList = []
                    tmp = ob.PropertiesList
                    for prop in tmp:
                        if prop.startswith('pi_') or prop == 'assembly2Version':
                            deleteList.append(prop)
                    for prop in deleteList:
                        ob.removeProperty(prop)
                        
        QtGui.QMessageBox.information(
            QtGui.QApplication.activeWindow(), 
            u"The proxies have been migrated.", 
            u"Please save and reopen this assembly file" 
            ) 
Example #20
Source File: a2p_importpart.py    From A2plus with GNU Lesser General Public License v2.1 5 votes vote down vote up
def KeyboardEvent(self, info):
        if info['State'] == 'UP' and info['Key'] == 'ESCAPE':
            self.removeCallbacks()
            if not self.deleteOnEscape:
                self.obj.Placement.Base = self.initialPosition
            else:
                self.objectToDelete = self.obj #This can be asked by a timer in a calling func...
                #This causes a crash in FC0.19/Qt5/Py3             
                #FreeCAD.activeDocument().removeObject(self.obj.Name)
#=============================================================================== 
Example #21
Source File: a2p_importpart.py    From A2plus with GNU Lesser General Public License v2.1 5 votes vote down vote up
def clickMouse(self, info):
        if info['Button'] == 'BUTTON1' and info['State'] == 'DOWN':
            #if not info['ShiftDown'] and not info['CtrlDown']: #struggles within Inventor Navigation
            if not info['ShiftDown']:
                self.removeCallbacks()
                FreeCAD.activeDocument().recompute()
            elif info['ShiftDown']:
                self.obj = duplicateImportedPart(self.obj)
                self.deleteOnEscape = True 
Example #22
Source File: Animation.py    From Animation with GNU General Public License v2.0 5 votes vote down vote up
def step(self,now):
		pfn=self.obj2.pictures%now
		if os.path.exists(pfn):
			self.obj2.rectangle.ViewObject.TextureImage = pfn
			say("image: " + pfn)
		tx=FreeCADGui.activeDocument().activeView()
		rx=tx.getCameraOrientation()
		r2=FreeCAD.Rotation(FreeCAD.Vector(1,0,0),180)
		r3=rx.multiply(r2)
		self.obj2.rectangle.Placement.Rotation=r3
		FreeCAD.ActiveDocument.recompute()

#---------------------------------------------------------------------------------------------------------- 
Example #23
Source File: a2p_importpart.py    From A2plus with GNU Lesser General Public License v2.1 5 votes vote down vote up
def onTimer(self):
        if self.partMover != None:
            if self.partMover.objectToDelete != None:
                FreeCAD.activeDocument().removeObject(self.partMover.objectToDelete.Name)
                self.partMover.objectToDelete = None
        self.timer.start(100) 
Example #24
Source File: a2p_importpart.py    From A2plus with GNU Lesser General Public License v2.1 5 votes vote down vote up
def Activated(self):
        doc = FreeCAD.activeDocument()
        selection = [s for s in FreeCADGui.Selection.getSelectionEx() if s.Document == doc ]
        self.partMover = PartMover(
            FreeCADGui.activeDocument().activeView(),
            duplicateImportedPart(selection[0].Object),
            deleteOnEscape = True
            )
        self.timer = QtCore.QTimer()
        QtCore.QObject.connect(self.timer, QtCore.SIGNAL("timeout()"), self.onTimer)
        self.timer.start( 100 ) 
Example #25
Source File: a2p_importpart.py    From A2plus with GNU Lesser General Public License v2.1 5 votes vote down vote up
def IsActive(self):
        doc = FreeCAD.activeDocument()
        if doc is None: return False
        return True 
Example #26
Source File: a2p_importpart.py    From A2plus with GNU Lesser General Public License v2.1 5 votes vote down vote up
def IsActive(self):
        doc = FreeCAD.activeDocument()
        if doc is None: return False
        return True 
Example #27
Source File: a2p_importpart.py    From A2plus with GNU Lesser General Public License v2.1 5 votes vote down vote up
def IsActive(self):
        doc = FreeCAD.activeDocument()
        if doc is None: return False
        return True 
Example #28
Source File: frameForms.py    From flamingo with GNU Lesser General Public License v3.0 5 votes vote down vote up
def __init__(self,dialog='anyFile.ui'):
    dialogPath=join(dirname(abspath(__file__)),"dialogs",dialog)
    FreeCAD.Console.PrintMessage(dialogPath+"\n")
    self.form=FreeCADGui.PySideUic.loadUi(dialogPath)
    FreeCAD.Console.PrintMessage(dialogPath+" loaded\n")
    if platform.startswith('win'):# or vQt>=5:
      FreeCAD.Console.PrintWarning("No keyboard shortcuts.\n No callback on SoEvent")
    else:
      FreeCAD.Console.PrintMessage('Keyboard shortcuts available.\n"S" to select\n"RETURN" to perform action\n')
      try:
        self.view=FreeCADGui.activeDocument().activeView() # get3DView()
        self.call=self.view.addEventCallback("SoEvent", self.action)
      except:
        FreeCAD.Console.PrintError('No view available.\n') 
Example #29
Source File: frameForms.py    From flamingo with GNU Lesser General Public License v3.0 5 votes vote down vote up
def accept(self, ang=None):
    if not ang:
      ang=float(self.form.edit1.text())
    self.deleteArrow()
    objects=FreeCADGui.Selection.getSelection()
    if objects and self.Axis:
      FreeCAD.ActiveDocument.openTransaction('rotateTheBeamAround')
      for o in objects:
        if self.form.copyCB.isChecked():
          FreeCAD.activeDocument().copyObject(o,True)
        frameCmd.rotateTheBeamAround(o,self.Axis,ang)
      FreeCAD.ActiveDocument.commitTransaction() 
Example #30
Source File: a2p_importpart.py    From A2plus with GNU Lesser General Public License v2.1 5 votes vote down vote up
def KeyboardEvent(self, info):
        doc = FreeCAD.activeDocument()
        if info['State'] == 'UP' and info['Key'] == 'ESCAPE':
            doc.commitTransaction()
            self.removeCallbacks()
#===============================================================================