Python FreeCAD.activeDocument() Examples

The following are 30 code examples of FreeCAD.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 FreeCAD , or try the search function .
Example #1
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 #2
Source File: CommandsFrame.py    From flamingo with GNU Lesser General Public License v3.0 6 votes vote down vote up
def Activated(self):
    import FreeCAD, FreeCADGui, frameCmd, frameObservers
    selex=Gui.Selection.getSelectionEx()
    faces=frameCmd.faces(selex)
    beams=[sx.Object for sx in selex]
    if len(faces)==len(beams)>1:
      FreeCAD.activeDocument().openTransaction('LevelTheBeams')
      beams.pop(0)
      fBase=faces.pop(0)
      for i in range(len(beams)):
        frameCmd.levelTheBeam(beams[i],[fBase,faces[i]])
      FreeCAD.activeDocument().commitTransaction()
    elif len(faces)!=len(beams):
      FreeCAD.Console.PrintError('Select only one face for each beam.\n')
    else:
      FreeCADGui.Selection.clearSelection()
      s=frameObservers.levelBeamObserver()
      FreeCADGui.Selection.addObserver(s) 
Example #3
Source File: polarUtilsCmd.py    From flamingo with GNU Lesser General Public License v3.0 6 votes vote down vote up
def pickAction(self,path=None,event=None,arg=None):
    FreeCAD.activeDocument().openTransaction('Quick move')
    if event.wasCtrlDown(): k=-1*float(self.edit.text())
    else: k=1*float(self.edit.text())
    sel=FreeCADGui.Selection.getSelection()
    if sel: self.objs=[o for o in sel if hasattr(o,'Shape')]
    if event.wasCtrlDown() and event.wasAltDown():
      if frameCmd.edges(): 
        self.edge=frameCmd.edges()[0]
        for o in self.objs: frameCmd.rotateTheBeamAround(o, self.edge, 90)
      elif self.edge:
        for o in self.objs: frameCmd.rotateTheBeamAround(o, self.edge, 90)
    else:
      for o in self.objs: o.Placement.move(self.direct*k)
      self.Placement.move(self.direct*k)
      pl,direct,M=[self.Placement,self.direct,self.scale]
      self.closeArrow()
      self.__init__(self.edit, pl,direct,M,self.objs)
    FreeCAD.activeDocument().commitTransaction() 
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: 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 #6
Source File: CommandsFrame.py    From flamingo with GNU Lesser General Public License v3.0 6 votes vote down vote up
def Activated(self):
    import FreeCAD, FreeCADGui, frameCmd, frameObservers
    edges=frameCmd.edges()
    if len(edges)>=2 and len(FreeCADGui.Selection.getSelection())>=2:
      e1=edges.pop(0)
      beams=FreeCADGui.Selection.getSelection()[1:]
      if len(edges)==len(beams):
        pairs=[(beams[i],edges[i]) for i in range(len(beams))]
        FreeCAD.activeDocument().openTransaction('AlignEdge')
        for p in pairs:
          frameCmd.joinTheBeamsEdges(p[0],e1,p[1])
        FreeCAD.activeDocument().commitTransaction()
    else:
      FreeCADGui.Selection.clearSelection()
      s=frameObservers.alignEdgeObserver()
      FreeCADGui.Selection.addObserver(s) 
Example #7
Source File: pipeFeatures.py    From flamingo with GNU Lesser General Public License v3.0 6 votes vote down vote up
def __init__(self, obj,DN="DN50",PRating="SCH-STD",OD=60.3,thk=3,BR=None, lab=None):
    # initialize the parent class
    super(PypeLine2,self).__init__(obj)
    # define common properties
    obj.PType="PypeLine"
    obj.PSize=DN
    obj.PRating=PRating
    if lab:
      obj.Label=lab
    # define specific properties
    if not BR:
      BR=0.75*OD
    obj.addProperty("App::PropertyLength","BendRadius","PypeLine2","the radius of bending").BendRadius=BR
    obj.addProperty("App::PropertyLength","OD","PypeLine2","Outside diameter").OD=OD
    obj.addProperty("App::PropertyLength","thk","PypeLine2","Wall thickness").thk=thk
    obj.addProperty("App::PropertyString","Group","PypeLine2","The group.").Group=obj.Label+"_pieces"
    group=FreeCAD.activeDocument().addObject("App::DocumentObjectGroup",obj.Group)
    group.addObject(obj)
    FreeCAD.Console.PrintWarning("Created group "+obj.Group+"\n")
    obj.addProperty("App::PropertyLink","Base","PypeLine2","the edges") 
Example #8
Source File: pipeCmd.py    From flamingo with GNU Lesser General Public License v3.0 6 votes vote down vote up
def updatePLColor(sel=None, color=None):
  if not sel:
    sel=FreeCADGui.Selection.getSelection()
  if sel:
    pl=sel[0]
    if hasattr(pl,'PType') and pl.PType=='PypeLine':
      if not color:
        color=pl.ViewObject.ShapeColor
      group=FreeCAD.activeDocument().getObjectsByLabel(pl.Group)[0]
      for o in group.OutList:
        if hasattr(o,'PType'):
          if o.PType in objToPaint: 
            o.ViewObject.ShapeColor=color
          elif o.PType == 'PypeBranch':
            for e in [FreeCAD.ActiveDocument.getObject(name) for name in o.Tubes+o.Curves]: 
              e.ViewObject.ShapeColor=color
  else:
    FreeCAD.Console.PrintError('Select first one pype line\n') 
Example #9
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 #10
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 #11
Source File: CommandsSpSh.py    From flamingo with GNU Lesser General Public License v3.0 6 votes vote down vote up
def Activated(self):
    from PySide import QtGui as qg
    def cellAddress(sp,target):
      import xml.etree.ElementTree as et
      cells=et.fromstring(sp.cells.Content)
      for cell in cells:
        if cell.get('content')==target:
          #print "*** "+target+" is in "+cell.get('address')+" ***"
          return cell.get('address')
      #print "There are no "+target+" in this sheet."

    doc=FreeCAD.activeDocument()
    s=[x for x in doc.Objects if x.TypeId.startswith('Spread')]
    if len(s):
      #print "There is at least 1 Sheet"
      target=qg.QInputDialog.getText(None,"findFirst()","String to search for?")
      i=cellAddress(s[0],target[0])
      import spreadCmd
      #print "From spreadCmd.py: row = "+spreadCmd.cellRC(s[0],target[0])
    else:
      #print "There are no sheets in this doc"
      pass 
Example #12
Source File: CommandsPipe.py    From flamingo with GNU Lesser General Public License v3.0 6 votes vote down vote up
def Activated (self):
    import pipeCmd, frameCmd
    from Part import Plane
    selex=FreeCADGui.Selection.getSelectionEx()
    for sx in selex:
      sxFaces=[f for f in frameCmd.faces([sx]) if type(f.Surface)==Plane]
      if len(sxFaces)>0:
        refFace=sxFaces[0]
        support=sx.Object
    FreeCAD.activeDocument().openTransaction('Raise-up the support')
    for b in frameCmd.beams():
      if pipeCmd.isPipe(b):
        pipeCmd.laydownTheTube(b,refFace,support)
        break
    FreeCAD.activeDocument().recompute()
    FreeCAD.activeDocument().commitTransaction() 
Example #13
Source File: frameFeatures.py    From flamingo with GNU Lesser General Public License v3.0 6 votes vote down vote up
def makeSingle(self):
    FreeCAD.activeDocument().openTransaction('Insert Single Struct')
    if self.SType=='<by sketch>':
      profile=FreeCAD.ActiveDocument.getObjectsByLabel(self.form.listSizes.currentItem().text())[0]
    else:
      prop=self.sectDictList[self.form.listSizes.currentRow()]
      profile=newProfile(prop)
    if frameCmd.faces():
      Z=FreeCAD.Vector(0,0,1)
      for f in frameCmd.faces():
        beam=makeStructure(profile)
        beam.Placement=FreeCAD.Placement(f.CenterOfMass,FreeCAD.Rotation(Z,f.normalAt(0,0)))
        if self.form.editLength.text(): beam.Height=float(self.form.editLength.text())
    else:
      for e in frameCmd.edges():
        beam=makeStructure(profile)
        frameCmd.placeTheBeam(beam,e)
        if self.form.editLength.text(): beam.Height=float(self.form.editLength.text())
    FreeCAD.ActiveDocument.recompute() 
Example #14
Source File: frameFeatures.py    From flamingo with GNU Lesser General Public License v3.0 6 votes vote down vote up
def accept(self):
    if FreeCAD.ActiveDocument:
      # GET BASE
      bases=[b for b in FreeCADGui.Selection.getSelection() if hasattr(b,'Shape')]
      if bases and self.form.listSizes.selectedItems():
        FreeCAD.activeDocument().openTransaction('Insert FrameBranch')
        if self.SType=='<by sketch>':
          profile=FreeCAD.ActiveDocument.getObjectsByLabel(self.form.listSizes.currentItem().text())[0]
        else:
          prop=self.sectDictList[self.form.listSizes.currentRow()]
          profile=newProfile(prop)
        # MAKE FRAMEBRANCH
        if self.form.editName.text():
          name=self.form.editName.text()
        else:
          name='Travatura'
        a=FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name)
        FrameBranch(a,bases[0],profile)
        ViewProviderFrameBranch(a.ViewObject)
        FreeCAD.activeDocument().commitTransaction()
        FreeCAD.activeDocument().recompute()
        FreeCAD.activeDocument().recompute() 
Example #15
Source File: a2p_viewProviderProxies.py    From A2plus with GNU Lesser General Public License v2.1 6 votes vote down vote up
def onDelete(self, viewObject, subelements): # subelements is a tuple of strings
        if FreeCAD.activeDocument() != viewObject.Object.Document:
            return False

        if not hasattr(self,'enableDeleteCounterPart'):
            self.enableDeleteCounterPart = True

        if not self.enableDeleteCounterPart: return True # nothing more to do...

        # first delete the mirror...
        obj = viewObject.Object
        doc = obj.Document
        if hasattr( obj.Proxy, 'mirror_name'):
            try:
                m = doc.getObject(obj.Proxy.mirror_name)
                m.Proxy.enableDeleteCounterPart = False
                doc.removeObject( obj.Proxy.mirror_name ) # also delete mirror
            except:
                pass # if mirror is already deleted...
        return True

#============================================================================== 
Example #16
Source File: a2p_viewProviderProxies.py    From A2plus with GNU Lesser General Public License v2.1 6 votes vote down vote up
def onDelete(self, viewObject, subelements): # subelements is a tuple of strings
        if FreeCAD.activeDocument() != viewObject.Object.Document:
            return False
        
        if not hasattr(self,'enableDeleteCounterPart'):
            self.enableDeleteCounterPart = True
            
        if not self.enableDeleteCounterPart: return True # nothing more to do...

        # First delete the original...
        obj = viewObject.Object
        doc = obj.Document
        try:
            c = doc.getObject(obj.Proxy.constraintObj_name)
            c.Proxy.enableDeleteCounterPart = False
            doc.removeObject(obj.Proxy.constraintObj_name) # also delete the original
        except:
            pass # if original has already been removed...
        return True


#============================================================================== 
Example #17
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 #18
Source File: a2p_constraintDialog.py    From A2plus with GNU Lesser General Public License v2.1 6 votes vote down vote up
def solve(self):
        doc = FreeCAD.activeDocument()
        if self.constraintObject not in doc.Objects:
            QtGui.QMessageBox.information(
                QtGui.QApplication.activeWindow(),
                "Constraint does not exist anymore",
                "Constraint has already been deleted"
                )
            a2plib.setConstraintEditorRef(None)
            self.Deleted.emit()
            return

        self.winModified = True
        self.setConstraintEditorData()
        doc = FreeCAD.activeDocument()
        if doc != None:
            solveConstraints(doc)
            doc.recompute() 
Example #19
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 #20
Source File: pipeForms.py    From flamingo with GNU Lesser General Public License v3.0 5 votes vote down vote up
def apply(self):
    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
        FreeCAD.activeDocument().recompute() 
Example #21
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 #22
Source File: CommandsPolar.py    From flamingo with GNU Lesser General Public License v3.0 5 votes vote down vote up
def Activated(self):
    import polarUtilsCmd as puc
    import FreeCAD
    doc=FreeCAD.activeDocument()
    sketch=doc.addObject("Sketcher::SketchObject","imported")
    sketch.Placement = FreeCAD.Placement(FreeCAD.Vector(0.000000,0.000000,0.000000),FreeCAD.Rotation(0.000000,0.000000,0.000000,1.000000))
    puc.disegna(sketch,puc.getFromFile()) 
Example #23
Source File: pipeForms.py    From flamingo with GNU Lesser General Public License v3.0 5 votes vote down vote up
def insert(self):
    d=self.pipeDictList[self.sizeList.currentRow()]
    FreeCAD.activeDocument().openTransaction('Insert pype-branch')
    plLabel=self.edit1.text()
    if not plLabel: plLabel="Traccia"
    if not self.edit2.text(): bendRad=0.75*float(d["OD"])
    else: bendRad=float(self.edit2.text())
    a=pipeCmd.makeBranch(DN=d["PSize"],PRating=self.PRating,OD=float(d["OD"]),thk=float(d["thk"]), BR=bendRad, lab=plLabel, color=self.color)
    if self.combo.currentText()!='<none>':
      pipeCmd.moveToPyLi(a,self.combo.currentText())
    FreeCAD.activeDocument().commitTransaction()
    FreeCAD.ActiveDocument.recompute()
    FreeCAD.ActiveDocument.recompute() 
Example #24
Source File: pipeForms.py    From flamingo with GNU Lesser General Public License v3.0 5 votes vote down vote up
def partList(self):
    from PySide.QtGui import QFileDialog as qfd
    f=None
    f=qfd.getSaveFileName()[0]
    if f:
      if self.combo.currentText()!='<new>':
        group=FreeCAD.activeDocument().getObjectsByLabel(FreeCAD.__activePypeLine__+'_pieces')[0]
        fields=['Label','PType','PSize','Volume','Height']
        rows=list()
        for o in group.OutList:
          if hasattr(o,'PType'):
            if o.PType in ['Pipe','Elbow','Flange','Clamp','Reduct','Cap']:
              data=[o.Label,o.PType,o.PSize,o.Shape.Volume,'-']
              if o.PType=='Pipe':
                data[4]=o.Height
              rows.append(dict(zip(fields,data)))
            elif o.PType in ['PypeBranch']:
              for name in o.Tubes+o.Curves:
                pype=FreeCAD.ActiveDocument.getObject(name)
                data=[pype.Label,pype.PType,pype.PSize,pype.Shape.Volume,'-']
                if pype.PType=='Pipe':
                  data[4]=pype.Height
                rows.append(dict(zip(fields,data)))
        plist=open(abspath(f),'w')
        w=csv.DictWriter(plist,fields,restval='-',delimiter=';')
        w.writeheader()
        w.writerows(rows)
        plist.close()
        FreeCAD.Console.PrintMessage('Data saved in %s.\n' %f) 
Example #25
Source File: pipeForms.py    From flamingo with GNU Lesser General Public License v3.0 5 votes vote down vote up
def insert(self):
    d=self.pipeDictList[self.sizeList.currentRow()]
    FreeCAD.activeDocument().openTransaction('Insert pype-line')
    if self.combo.currentText()=='<new>':
      plLabel=self.edit1.text()
      if not plLabel: plLabel="Tubatura"
      a=pipeCmd.makePypeLine2(DN=d["PSize"],PRating=self.PRating,OD=float(d["OD"]),thk=float(d["thk"]), lab=plLabel, color=self.color)
      self.combo.addItem(a.Label)
    else:
      plname=self.combo.currentText()
      plcolor=FreeCAD.activeDocument().getObjectsByLabel(plname)[0].ViewObject.ShapeColor
      pipeCmd.makePypeLine2(DN=d["PSize"],PRating=self.PRating,OD=float(d["OD"]),thk=float(d["thk"]), pl=plname, color=plcolor)
    FreeCAD.activeDocument().commitTransaction()
    FreeCAD.ActiveDocument.recompute()
    FreeCAD.ActiveDocument.recompute() 
Example #26
Source File: polarUtilsCmd.py    From flamingo with GNU Lesser General Public License v3.0 5 votes vote down vote up
def disegna(sk, pos):
  'arg1=sketch, arg2=pos (list of 3-uple): draws the segments of "pos" in "sketch" and close the polygon'
  import FreeCAD, Part, Sketcher
  lines=[]
  while len(pos)>1:
    lines.append(sk.addGeometry(Part.Line(FreeCAD.Vector(pos[0]),FreeCAD.Vector(pos[1]))))
    pos.pop(0)
  for i in range(len(lines)-1):
    sk.addConstraint(Sketcher.Constraint('Coincident',lines[i],2,lines[i+1],1))
  sk.addConstraint(Sketcher.Constraint('Coincident',lines[len(lines)-1],2,lines[0],1))
  FreeCAD.activeDocument().recompute()
  return lines 
Example #27
Source File: pipeForms.py    From flamingo with GNU Lesser General Public License v3.0 5 votes vote down vote up
def insert(self):
    d=self.pipeDictList[self.sizeList.currentRow()]
    FreeCAD.activeDocument().openTransaction('Insert cap')
    if len(frameCmd.edges())==0:
      propList=[d['PSize'],float(pq(d['OD'])),float(pq(d['thk']))]
      vs=[v for sx in FreeCADGui.Selection.getSelectionEx() for so in sx.SubObjects for v in so.Vertexes]
      if len(vs)==0:   # nothing is selected
        self.lastCap=pipeCmd.makeCap(propList)
        if self.combo.currentText()!='<none>':
          pipeCmd.moveToPyLi(self.lastCap,self.combo.currentText())
      else:
        for v in vs:   # vertexes are selected
          self.lastCap=pipeCmd.makeCap(propList,v.Point)
        if self.combo.currentText()!='<none>':
          pipeCmd.moveToPyLi(self.lastCap,self.combo.currentText())
    else:
      for edge in frameCmd.edges():
        if edge.curvatureAt(0)!=0:   # curved edges are selected...
          objs=[o for o in FreeCADGui.Selection.getSelection() if hasattr(o,'PSize') and hasattr(o,'OD') and hasattr(o,'thk')]
          Z=None
          if len(objs)>0:  # ...pype objects are selected
            propList=[objs[0].PSize,objs[0].OD,objs[0].thk]
            Z=edge.centerOfCurvatureAt(0)-objs[0].Shape.Solids[0].CenterOfMass
          else:            # ...no pype objects are selected
            propList=[d['PSize'],float(pq(d['OD'])),float(pq(d['thk']))]
            Z=edge.tangentAt(0).cross(edge.normalAt(0))
          self.lastCap=pipeCmd.makeCap(propList,edge.centerOfCurvatureAt(0),Z)
        if self.combo.currentText()!='<none>':
          pipeCmd.moveToPyLi(self.lastCap,self.combo.currentText())
    FreeCAD.activeDocument().commitTransaction()
    FreeCAD.activeDocument().recompute() 
Example #28
Source File: pipeForms.py    From flamingo with GNU Lesser General Public License v3.0 5 votes vote down vote up
def insert(self):
    selex=FreeCADGui.Selection.getSelectionEx()
    if len(selex)==0:
      d=self.pipeDictList[self.sizeList.currentRow()]
      propList=[d['PSize'],self.PRating,float(pq(d['C'])),float(pq(d['H'])),float(pq(d['d']))]
      FreeCAD.activeDocument().openTransaction('Insert clamp in (0,0,0)')
      ub=pipeCmd.makeUbolt(propList)
      if self.combo.currentText()!='<none>':
        pipeCmd.moveToPyLi(ub,self.combo.currentText())
      FreeCAD.activeDocument().commitTransaction()
      FreeCAD.activeDocument().recompute()
    else:
      FreeCAD.activeDocument().openTransaction('Insert clamp on tube')
      for objex in selex:
        if hasattr(objex.Object,'PType') and objex.Object.PType=='Pipe':
          d=[typ for typ in self.pipeDictList if typ['PSize']==objex.Object.PSize]
          if len(d)>0:
            d=d[0]
          else:
            d=self.pipeDictList[self.sizeList.currentRow()]
          propList=[d['PSize'],self.PRating,float(pq(d['C'])),float(pq(d['H'])),float(pq(d['d']))]
          H=float(objex.Object.Height)
          gap=H-float(pq(d['C']))
          steps=[gap*self.cb1.isChecked(),H/2*self.cb2.isChecked(),(H-gap)*self.cb3.isChecked()]
          for s in steps:
            if s:
              ub=pipeCmd.makeUbolt(propList,pos=objex.Object.Placement.Base, Z=frameCmd.beamAx(objex.Object))
              ub.Placement.move(frameCmd.beamAx(objex.Object).multiply(s))
              if self.refNorm:
                pipeCmd.rotateTheTubeAx(obj=ub,angle=degrees(self.refNorm.getAngle((frameCmd.beamAx(ub,FreeCAD.Vector(0,1,0))))))
              if self.combo.currentText()!='<none>':
                pipeCmd.moveToPyLi(ub,self.combo.currentText())
      FreeCAD.activeDocument().commitTransaction()
    FreeCAD.activeDocument().recompute() 
Example #29
Source File: pipeForms.py    From flamingo with GNU Lesser General Public License v3.0 5 votes vote down vote up
def applyProp(self):
    r=self.pipeDictList[self.sizeList.currentRow()]
    DN=r['PSize']
    OD1=float(pq(r['OD']))
    OD2=float(pq(self.OD2list.currentItem().text()))
    thk1=float(pq(r['thk']))
    try:
      thk2=float(pq(r['thk2'].split('>')[self.OD2list.currentRow()]))
    except:
      thk2=thk1
    H=pq(r['H'])
    reductions=[red for red in FreeCADGui.Selection.getSelection() if hasattr(red,'PType') and red.PType=='Reduct']
    if len(reductions):
      for reduct in reductions:
        reduct.PSize=DN
        reduct.PRating=self.PRating
        reduct.OD=OD1
        reduct.OD2=OD2
        reduct.thk=thk1
        reduct.thk2=thk2
        reduct.Height=H
    elif self.lastReduct:
      self.lastReduct.PSize=DN
      self.lastReduct.PRating=self.PRating
      self.lastReduct.OD=OD1
      self.lastReduct.OD2=OD2
      self.lastReduct.thk=thk1
      self.lastReduct.thk2=thk2
      self.lastReduct.Height=H
    FreeCAD.activeDocument().recompute() 
Example #30
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)