コード例 #1
0
ファイル: spreadCmd.py プロジェクト: oddtopus/flamingo
def setTipo(l,w):
  'arg1=length,arg2=width'
  import FreeCAD
  fpTipo=FreeCAD.activeDocument().tipo
  fpTipo.length=l
  fpTipo.width=w
  FreeCAD.activeDocument().recompute()
コード例 #2
0
ファイル: PCBboard.py プロジェクト: geggio84/FreeCAD-PCB
def getAnnotations():
    if not FreeCAD.activeDocument():
        return False
    #
    doc = FreeCAD.activeDocument()
    data = []
    
    for j in doc.Objects:
        if hasattr(j, "Proxy") and hasattr(j.Proxy, "Type") and 'PCBannotation' in j.Proxy.Type:
            try:
                annotation = ''
                for i in j.ViewObject.Text:
                    annotation += u'{0}\n'.format(i)

                data.append([
                    j.X.Value, j.Y.Value, 
                    j.ViewObject.Size.Value, 
                    j.Side, 
                    annotation.strip(), 
                    j.ViewObject.Align, 
                    j.Rot.Value, 
                    j.ViewObject.Mirror, 
                    j.ViewObject.Spin
                ])
            except Exception, e:
                FreeCAD.Console.PrintWarning(str(e) + "\n")
コード例 #3
0
ファイル: pyooml.py プロジェクト: Gafeju/friki
	def __init__(self, l = 10):
		"""Create a frame. l is the vector's length"""

		#-- Store the vector length
		self.l = l

		#-- Create the Freecad Object
		self.obj = FreeCAD.ActiveDocument.addObject("Part::Compound","Frame")

		#-- Build the frame
		self.x_axis = svector(1, 0, 0, l = l).color("red")
		self.x_axis.label = "X axis"

		self.y_axis = svector(0, 1, 0, l = l).color("green")
		self.y_axis.label = "Y axis"

		self.z_axis = svector(0, 0, 1, l = l).color("blue")
		self.z_axis.label = "Z axis"

		self.origin = sphere(r = 0.5)
		self.origin.label = "Origin"

		#-- Creat the compound object
		self.obj.Links = [self.x_axis.obj, self.y_axis.obj, self.z_axis.obj,
						  self.origin.obj]

		#-- Default display mode
		self.obj.ViewObject.DisplayMode = 'Shaded'

		FreeCAD.activeDocument().recompute()
		return
コード例 #4
0
ファイル: PlotAux.py プロジェクト: AjinkyaDahale/FreeCAD
    def spreadSheet(self, roll, gz, draft, trim):
        """ Create a Spreadsheet with the results

        Position arguments:
        roll -- List of roll angles (in degrees).
        gz -- List of GZ values (in meters).
        draft -- List of equilibrium drafts (in meters).
        trim -- List of equilibrium trim angles (in degrees).
        """
        s = FreeCAD.activeDocument().addObject('Spreadsheet::Sheet',
                                               'GZ')

        # Print the header
        s.set("A1", "roll [deg]")
        s.set("B1", "GZ [m]")
        s.set("C1", "draft [m]")
        s.set("D1", "trim [deg]")

        # Print the data
        for i in range(len(roll)):
            s.set("A{}".format(i + 2), str(roll[i]))
            s.set("B{}".format(i + 2), str(gz[i]))
            s.set("C{}".format(i + 2), str(draft[i]))
            s.set("D{}".format(i + 2), str(trim[i]))

        # Recompute
        FreeCAD.activeDocument().recompute()
コード例 #5
0
def proceed():
   QtGui.qApp.setOverrideCursor(QtCore.Qt.WaitCursor)

   FreeCAD.Console.PrintMessage("===========================================\n")
   FreeCAD.Console.PrintMessage("unfoldBox: start.\n")
   try:
      file_name  = fields_l[0].text()
      scale    = float(fields_l[1].text())
      scale_auto = scale_check.isChecked()
      a3 = a3_check.isChecked()
      cartridge = cartridge_check.isChecked()
      onedrawing = onedrawing_check.isChecked()
      sewed = sewed_check.isChecked()
      FreeCAD.Console.PrintMessage("unfoldBox.file_name: "+file_name+"\n")
      FreeCAD.Console.PrintMessage("unfoldBox.scale: "+str(scale)+"\n")
      FreeCAD.Console.PrintMessage("unfoldBox.scale_check: "+str(scale_auto)+"\n")
      FreeCAD.Console.PrintMessage("unfoldBox.a3_check: "+str(a3)+"\n")
      FreeCAD.Console.PrintMessage("unfoldBox.cartridge: "+str(cartridge)+"\n")
      FreeCAD.Console.PrintMessage("unfoldBox.onedrawing: "+str(onedrawing)+"\n")
      FreeCAD.Console.PrintMessage("unfoldBox.sewed: "+str(sewed)+"\n")
   except:
      msg="unfoldBox: wrong inputs...\n"
      FreeCAD.Console.PrintError(msg)
      errorDialog(msg)

   QtGui.qApp.restoreOverrideCursor()
   DialogBox.hide()
   #
   # Get selection
   #
   sel=FreeCADGui.Selection.getSelection()
   faceid=0
   objnames_l=[]
   tree_l=[]
   grp=FreeCAD.activeDocument().addObject("App::DocumentObjectGroup", str(file_name)) 
   for objid in range( sel.__len__() ):
     obj=Draft.clone(sel[objid])
     grp.addObject(obj)
     objnames_l.append( [ obj , sel[objid].Name ] )
 
   unfold=unfoldBox()
   if sewed : 
       objnames_l=unfold.done(objnames_l)
       grp.addObject(objnames_l[0][0])
   else:
       for objid in range( objnames_l.__len__() ):
         unfold.moveXY(objnames_l[objid][0])
 
   id=0
   while objnames_l.__len__() > 0:
       draw=Drawing2d( scale, scale_auto , a3 , cartridge , onedrawing , FreeCAD.activeDocument().Name , "Page"+str(id) ) 
       objnames_l=draw.all( objnames_l )
       id=id+1
       FreeCAD.Console.PrintMessage("unfoldBox: obj_l= "+str(objnames_l.__len__())+"\n")
 
   FreeCAD.Console.PrintMessage("unfoldBox: end.\n")
   FreeCAD.Console.PrintMessage("===========================================\n")
コード例 #6
0
ファイル: frameObservers.py プロジェクト: oddtopus/flamingo
 def addSelection(self,doc,obj,sub,pnt):
   subObject=FreeCAD.getDocument(doc).getObject(obj).Shape.getElement(sub)
   if subObject.ShapeType=="Face":
     if self.faceBase==None:
       self.faceBase=subObject
       FreeCAD.Console.PrintMessage('Target face selected.\n')
     else:
       FreeCAD.activeDocument().openTransaction('alignFlange')
       frameCmd.rotTheBeam(FreeCAD.getDocument(doc).getObject(obj),self.faceBase,subObject)
       FreeCAD.activeDocument().commitTransaction()
コード例 #7
0
ファイル: AssemblyLib.py プロジェクト: 3DPrinterGuy/FreeCAD
def importAssembly(FileName,DestItem):
	for i in Part.read(FileName).Solids:
		po = FreeCAD.activeDocument().addObject('Assembly::ItemPart','STP-Part')
		DestItem.Items = DestItem.Items + [po]
		bo = FreeCAD.activeDocument().addObject('PartDesign::Body','STP-Body')
		po.Model = bo
		so = FreeCAD.activeDocument().addObject('PartDesign::Solid','STP-Solid')
		bo.Model = so
		bo.Tip   = so
		so.Shape = i
コード例 #8
0
ファイル: FemCommands.py プロジェクト: computingtek/FreeCAD
 def hide_meshes_show_parts_constraints(self):
     if FreeCAD.GuiUp:
         for acnstrmesh in FreeCAD.activeDocument().Objects:
             if "Constraint" in acnstrmesh.TypeId:
                 acnstrmesh.ViewObject.Visibility = True
             if "Mesh" in acnstrmesh.TypeId:
                 aparttoshow = acnstrmesh.Name.replace("_Mesh","")
                 for apart in FreeCAD.activeDocument().Objects:
                     if aparttoshow == apart.Name:
                         apart.ViewObject.Visibility = True
                 acnstrmesh.ViewObject.Visibility = False #OvG: Hide meshes and show constraints and meshed part e.g. on purging results
コード例 #9
0
ファイル: FemCommands.py プロジェクト: computingtek/FreeCAD
 def hide_parts_constraints_show_meshes(self):
     if FreeCAD.GuiUp:
         for acnstrmesh in FreeCAD.activeDocument().Objects:
             #if "Constraint" in acnstrmesh.TypeId:
             #    acnstrmesh.ViewObject.Visibility = False
             if "Mesh" in acnstrmesh.TypeId:
                 aparttoshow = acnstrmesh.Name.replace("_Mesh","")
                 for apart in FreeCAD.activeDocument().Objects:
                     if aparttoshow == apart.Name:
                         apart.ViewObject.Visibility = False
                 acnstrmesh.ViewObject.Visibility = True #OvG: Hide constraints and parts and show meshes
コード例 #10
0
ファイル: PCBtoolBar.py プロジェクト: huigao80/FreeCAD-PCB
 def fastExplodeModels(self):
     if FreeCAD.activeDocument():
         doc = FreeCAD.activeDocument()
         if len(doc.Objects):
             a = doc.addObject("App::FeaturePython", 'Explode')
             obj = explodeObject(a)
             viewProviderExplodeObject(a.ViewObject)
             
             for elem in doc.Objects:
                 if hasattr(elem, "Proxy") and hasattr(elem, "Type") and elem.Proxy.Type == "PCBpart":
                     if elem.Side == "TOP":
                         obj.spisObiektowGora[elem.Name] = [doc.getObject(elem.Name).Placement.Base.z, 3]
                     else:
                         obj.spisObiektowDol[elem.Name] = [doc.getObject(elem.Name).Placement.Base.z, 3]
                 #elif hasattr(elem, "Proxy") and hasattr(elem, "Type") and elem.Proxy.Type == 'partsGroup':  # objects
                     #for i in elem.OutList:
                         #if hasattr(i, "Proxy") and hasattr(i, "Type") and i.Proxy.Type == "PCBpart":
                             #if i.Side == "TOP":
                                 #obj.spisObiektowGora[i.Name] = [doc.getObject(i.Name).Placement.Base.z, 3]
                             #else:
                                 #obj.spisObiektowDol[i.Name] = [doc.getObject(i.Name).Placement.Base.z, 3]
                         ##if float("%4.2f" % i.Placement.Rotation.Axis.x) > 0.:  # bottom side -> nie zawsze rozpoznaje poprawnie
                             ##obj.spisObiektowDol[i.Name] = [doc.getObject(i.Name).Placement.Base.z, 3]
                         ##else:  # top side
                             ##obj.spisObiektowGora[i.Name] = [doc.getObject(i.Name).Placement.Base.z, 3]
                 elif hasattr(elem, "Proxy") and hasattr(elem, "Type") and elem.Proxy.Type == 'layersGroup':  # layers
                     for i in elem.OutList:
                         if hasattr(i, "Proxy") and hasattr(i, "Type") and ('tSilk' in i.Proxy.Type or 'tDocu' in i.Proxy.Type):
                             obj.spisObiektowGora[i.Name] = [doc.getObject(i.Name).Placement.Base.z, 1]
                         elif hasattr(i, "Proxy") and hasattr(i, "Type") and 'tPad' in i.Proxy.Type:
                             obj.spisObiektowGora[i.Name] = [doc.getObject(i.Name).Placement.Base.z, 2]
                         elif hasattr(i, "Proxy") and hasattr(i, "Type") and 'tPath' in i.Proxy.Type:
                             obj.spisObiektowGora[i.Name] = [doc.getObject(i.Name).Placement.Base.z, 2]
                         #elif hasattr(i, "Proxy") and hasattr(i, "Type") and 'tKeepout' in i.Proxy.Type:
                             #obj.spisObiektowGora[i.Name] = [doc.getObject(i.Name).Placement.Base.z, 4]
                         elif hasattr(i, "Proxy") and hasattr(i, "Type") and 'tcenterDrill' in i.Proxy.Type:
                             obj.spisObiektowGora[i.Name] = [doc.getObject(i.Name).Placement.Base.z, 2]
                         elif hasattr(i, "Proxy") and hasattr(i, "Type") and ('bSilk' in i.Proxy.Type or 'bDocu' in i.Proxy.Type):
                             obj.spisObiektowDol[i.Name] = [doc.getObject(i.Name).Placement.Base.z, 1]
                         elif hasattr(i, "Proxy") and hasattr(i, "Type") and 'bPad' in i.Proxy.Type:
                             obj.spisObiektowDol[i.Name] = [doc.getObject(i.Name).Placement.Base.z, 2]
                         elif hasattr(i, "Proxy") and hasattr(i, "Type") and 'bPath' in i.Proxy.Type:
                             obj.spisObiektowDol[i.Name] = [doc.getObject(i.Name).Placement.Base.z, 2]
                         #elif hasattr(i, "Proxy") and hasattr(i, "Type") and 'bKeepout' in i.Proxy.Type:
                             #obj.spisObiektowDol[i.Name] = [doc.getObject(i.Name).Placement.Base.z, 4]
                         elif hasattr(i, "Proxy") and hasattr(i, "Type") and 'bcenterDrill' in i.Proxy.Type:
                             obj.spisObiektowDol[i.Name] = [doc.getObject(i.Name).Placement.Base.z, 2]
             
             obj.setParam(a, 'Inverse', False)
             obj.setParam(a, 'Active', True)
             obj.setParam(a, 'TopStepSize', 10)
             obj.setParam(a, 'BottomStepSize', 10)
             obj.generuj(a)
コード例 #11
0
ファイル: polarUtilsCmd.py プロジェクト: oddtopus/flamingo
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
コード例 #12
0
ファイル: pyooml.py プロジェクト: Gafeju/friki
	def __init__(self, r, angle1 = -90):
		"""Create a primitive sphere of given r radius"""

		#-- Create the Freecad Object
		self.obj = FreeCAD.ActiveDocument.addObject("Part::Sphere","Sphere","Sphere")

		#-- Asign the attrributes
		self.r = r
		self.angle1 = angle1

		FreeCAD.activeDocument().recompute()
		return
コード例 #13
0
ファイル: frameObservers.py プロジェクト: oddtopus/flamingo
 def addSelection(self,doc,obj,sub,pnt):
   Obj=FreeCAD.getDocument(doc).getObject(obj)
   if self.beam==None and Obj.TypeId=='Part::FeaturePython' and hasattr(Obj,'Height'):
     self.beam=Obj
     FreeCAD.Console.PrintMessage('Beam type selected.\n')
     from PySide.QtGui import QInputDialog as qid
     dist=float(qid.getText(None,"stretch a beam","old length = "+str(self.beam.Height)+"\nnew length?")[0])
     frameCmd.stretchTheBeam(self.beam,dist)
     FreeCAD.activeDocument().recompute()
     self.av.removeEventCallback("SoKeyboardEvent",self.stop)
     FreeCADGui.Selection.removeObserver(self)
     FreeCAD.Console.PrintMessage("I quit.")
コード例 #14
0
ファイル: frameForms.py プロジェクト: oddtopus/flamingo
 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()
コード例 #15
0
ファイル: frameObservers.py プロジェクト: oddtopus/flamingo
 def addSelection(self,doc,obj,sub,pnt):
   subObject=FreeCAD.getDocument(doc).getObject(obj).Shape.getElement(sub)
   if subObject.ShapeType=="Face":
     if self.targetFace==None:
       self.targetFace=subObject
       FreeCAD.Console.PrintMessage('Target face selected.\n')
     else:
       beam=FreeCAD.getDocument(doc).getObject(obj)
       FreeCAD.activeDocument().openTransaction('levelTheBeam')
       frameCmd.levelTheBeam(beam,[self.targetFace,subObject])
       FreeCAD.activeDocument().commitTransaction()
       FreeCAD.Console.PrintMessage('Face moved.\n')
       FreeCAD.Console.PrintWarning('Select another face or press [ESC].\n')
コード例 #16
0
ファイル: pyooml.py プロジェクト: Gafeju/friki
	def copy(self):
		"""Return a copy of the object"""

		#-- Create a new union
		lc = [child.copy() for child in self.childs]
		u = union(lc)

		#-- Copy the placement
		u.obj.Placement = self.obj.Placement

		FreeCAD.activeDocument().recompute()

		return u
コード例 #17
0
ファイル: frameFeatures.py プロジェクト: oddtopus/flamingo
 def insert(self):      # insert the section
   result=FreeCAD.ActiveDocument.findObjects("App::DocumentObjectGroup","Profiles_set")
   if result:
     group= result[0]
   else:
     group=FreeCAD.activeDocument().addObject("App::DocumentObjectGroup","Profiles_set")
   if self.sizeList.selectedItems():
     prop=self.sectDictList[self.sizeList.currentRow()]
     if prop['stype']=='C':
       s=makeCircle(float(prop['H']))
     else:
       s=ArchProfile.makeProfile([0,'SECTION',prop['SSize']+'-000',prop['stype'],float(prop['W']),float(prop['H']),float(prop['ta']),float(prop['tf'])])
     group.addObject(s)
   FreeCAD.activeDocument().recompute()
コード例 #18
0
ファイル: frameObservers.py プロジェクト: oddtopus/flamingo
 def addSelection(self,doc,obj,sub,pnt):
   selex=FreeCADGui.Selection.getSelectionEx()
   if self.beam==None and hasattr(selex[len(selex)-1].Object,'Height'):
     self.beam=selex[len(selex)-1].Object
     FreeCAD.Console.PrintMessage('Beam selected\n')
   elif self.edge==None and selex[len(selex)-1].SubObjects[0].ShapeType=='Edge':
     self.edge=selex[len(selex)-1].SubObjects[0]
     FreeCAD.Console.PrintMessage('Edge selected\n')
   if self.edge!=None and self.beam!=None:
     frameCmd.placeTheBeam(self.beam,self.edge)
     FreeCAD.Console.PrintMessage('Beam placed.\n')
     FreeCAD.Console.PrintWarning('Select another beam and another edge.\n[ESC] to exit.\n')
     self.beam=self.edge=None
     FreeCAD.activeDocument().recompute()
コード例 #19
0
ファイル: frameObservers.py プロジェクト: oddtopus/flamingo
 def addSelection(self,doc,obj,sub,pnt):
   subObject=FreeCAD.getDocument(doc).getObject(obj).Shape.getElement(sub)
   if subObject.ShapeType=="Edge":
     self.edges.append(subObject)
     FreeCAD.Console.PrintMessage("Edge"+str(len(self.edges))+" OK\n")
   if len(self.edges)>1:
     sel=FreeCADGui.Selection.getSelection()
     beam=sel[len(sel)-1]
     FreeCAD.activeDocument().openTransaction('joinTheBeamsEdges')
     frameCmd.joinTheBeamsEdges(beam,self.edges[0],self.edges[1])
     FreeCAD.activeDocument().commitTransaction()
     FreeCAD.Console.PrintMessage('Done.\n')
     self.edges=[]
     FreeCAD.Console.PrintWarning('Select other edges or [ESC] to exit\n')
コード例 #20
0
ファイル: Kartan.py プロジェクト: microelly2/Animation
	def step(self,now):
		say("Kardan step!" + str(now))
		FreeCAD.R=self
		
		if now<self.obj2.start or now>=self.obj2.end:
			say("ausserhalb")
			pass
		else:
			if not self.obj2.obj:
				errorDialog("kein Sketch zugeordnet")
				raise Exception(' self.obj2.obj nicht definiert')
			
			# alpha=60
			alpha=self.obj2.angleZenit
			phi=1
			
			# testfall
			phi=10

			# achse 1
			fa1=self.obj2.objAxis1
			p0=fa1.Placement
			phi0=p0.Rotation.Angle/pi*180
			# say("phi0 Basis " + str(phi0))
			p1=FreeCAD.Placement(App.Vector(0,0,0),App.Rotation(App.Vector(0,0,1),phi))
			r1=p1.multiply(p0)
			fa1.Placement=r1

			
			phi20=arctan(tan(phi0*pi/180)*cos(alpha*pi/180))*180/pi
			phi21=arctan(tan((phi0+phi)*pi/180)*cos(alpha*pi/180))*180/pi
			say("phi20 "+str(phi20))
			say("phi21 "+str(phi21))
			
			# achse 2
			timepos=now-self.obj2.start
			if 90/phi-1<=timepos and timepos<270/phi-1: 
				phi21=180+phi21
				say("*************** ! phi21 ="+str(phi21) + " now:" + str(now))

			fa2=self.obj2.objAxis2
			p1=FreeCAD.Placement(App.Vector(0,0,0),App.Rotation(App.Vector(0,0,1),phi21))
			p2=FreeCAD.Placement(App.Vector(0,0,0),App.Rotation(App.Vector(0,1,0),alpha))
			r3=p2.multiply(p1)
			fa2.Placement=r3

			# kreuz
			f=self.obj2.objCross
			rotcross(f,alpha,phi0+phi)
			FreeCAD.activeDocument().recompute()
コード例 #21
0
ファイル: PlotAux.py プロジェクト: DevJohan/FreeCAD_sf_master
    def spreadSheet(self, ship, trim):
        """ Write data file.
        @param ship Selected ship instance
        @param trim Trim in degrees.
        @return True if error happens.
        """
        s = FreeCAD.activeDocument().addObject('Spreadsheet::Sheet',
                                               'Hydrostatics')

        # Print the header
        s.set("A1", "displacement [ton]")
        s.set("B1", "draft [m]")
        s.set("C1", "wetted surface [m^2]")
        s.set("D1", "1cm trimming ship moment [ton*m]")
        s.set("E1", "Floating area [m^2]")
        s.set("F1", "KBl [m]")
        s.set("G1", "KBt [m]")
        s.set("H1", "BMt [m]")
        s.set("I1", "Cb")
        s.set("J1", "Cf")
        s.set("K1", "Cm")

        # Print the data
        for i in range(len(self.points)):
            point = self.points[i]
            s.set("A{}".format(i + 2),
                  str(point.disp.getValueAs("kg").Value / 1000.0))
            s.set("B{}".format(i + 2),
                  str(point.draft.getValueAs("m").Value))
            s.set("C{}".format(i + 2),
                  str(point.wet.getValueAs("m^2").Value))
            s.set("D{}".format(i + 2),
                  str(point.mom.getValueAs("kg*m").Value / 1000.0))
            s.set("E{}".format(i + 2),
                  str(point.farea.getValueAs("m^2").Value))
            s.set("F{}".format(i + 2),
                  str(point.xcb.getValueAs("m").Value))
            s.set("G{}".format(i + 2),
                  str(point.KBt.getValueAs("m").Value))
            s.set("H{}".format(i + 2),
                  str(point.BMt.getValueAs("m").Value))
            s.set("I{}".format(i + 2),
                  str(point.Cb))
            s.set("J{}".format(i + 2),
                  str(point.Cf))
            s.set("K{}".format(i + 2),
                  str(point.Cm))

        # Recompute
        FreeCAD.activeDocument().recompute()
コード例 #22
0
ファイル: pyooml.py プロジェクト: Gafeju/friki
	def __init__(self, items):
		"""items = list of parts to perform union"""

		#-- Create the Freecad Object
		self.obj = FreeCAD.activeDocument().addObject("Part::MultiFuse","Union")

		#-- Save the list of parts
		self.childs = items

		#-- Do the union!
		l = [item.obj for item in self.childs]
		self.obj.Shapes = l

		FreeCAD.activeDocument().recompute()
コード例 #23
0
ファイル: Gearing.py プロジェクト: microelly2/Animation
	def onChanged(self,obj,prop):
		say("**	onChanged ")
		if hasattr(FreeCAD,"animationLock"):
			if FreeCAD.animationLock:
				return
			
		FreeCAD.animationLock=True
		say("------------------------------***Lock EIN")
#		say(obj)
		say(obj.Label + " "  + prop)
		FreeCAD.mytoc=[self,obj,prop]
		oldval=FreeCAD.animation['changed'][2]
		val=obj.getPropertyByName(prop)
		say("old:" + str(oldval) + " new:" + str(val))

		
		# g=FreeCAD.getDocument("getriebe").getObject("My_Gearing")
		g=obj
		
			
		sys=g.obj
		
		s=sys.Links[0]
		pm=sys.Links[1]
		p=pm.Links[0]
		m=pm.Links[1]

		# lage planet-stern
		if prop=='distStarPlanet':
			pm.Placement.Base.x=obj.distStarPlanet

		# age moond stren
		if prop=='distPlanetMoon':
			m.Placement.Base.x=obj.distPlanetMoon
			
		if prop=='end':
			obj.end=obj.start+obj.duration
		
		say("begonnen")
		if prop=='objMoon':
			m.Links=[obj.objMoon]
		if prop=='objStar':
			s.Links=[obj.objStar]
		if prop=='objPlanet':
			p.Links=[obj.objPlanet]
		FreeCAD.animationLock=False
		FreeCAD.activeDocument().recompute()
		say("******************************Lock aus")
		say("fertig")
コード例 #24
0
	def generate_unit_cell(self):
		'''Generates a complete unit cell from single mesh wires.'''
		try:
			mesh_lattice_const = float(self.sb_mesh_lattice_const.text())*1e-3
			wire_diameter = float(self.sb_wire_diameter.text())*1e-3
			space_above_mesh = float(self.sb_space_above_mesh.text())*1e-3
			space_below_mesh = float(self.sb_space_below_mesh.text())*1e-3
			safety_distance = float(self.sb_safety_distance.text())*1e-3 # to prevent overlap of wires, which can cause trouble in later union or common operations and some other glitches
		except:
			FreeCAD.Console.PrintError("Error in evaluating the parameters")

		wires = {}
		for direction in ["x", "y"]:
			wires[direction] = []
			for wire_num in range(5): # draw 4 wires in each direction
				wire = self.generate_wire(wire_diameter, mesh_lattice_const, safety_distance=safety_distance)
				# position wire
				if direction == "x":
					wire.Placement.Base += FreeCAD.Vector(0, wire_num*mesh_lattice_const, 0)
					if wire_num%2:
						wire.Placement.Rotation = FreeCAD.Rotation(FreeCAD.Vector(1,0,0), 180)
					else:
						wire.Placement.Base += FreeCAD.Vector(0, 0, 2*safety_distance)
				else:
					wire.Placement.Rotation = FreeCAD.Rotation(FreeCAD.Vector(0,0,1), 90)
					wire.Placement.Base += FreeCAD.Vector(wire_num*mesh_lattice_const, 0, 0)
					if not wire_num%2:
						wire.Placement.Rotation = wire.Placement.Rotation.multiply(FreeCAD.Rotation(FreeCAD.Vector(1,0,0), 180))
					else:
						wire.Placement.Base += FreeCAD.Vector(0, 0, 2*safety_distance)

				wires[direction].append(wire)

		mesh = FreeCAD.activeDocument().addObject("Part::MultiFuse","Mesh")
		mesh.Shapes = wires["x"] + wires["y"]
		mesh.Placement.Base = FreeCAD.Vector(-2.*mesh_lattice_const, -2.*mesh_lattice_const, 0) # translate mesh to origin

		gas_box = FreeCAD.activeDocument().addObject("Part::Box","Gas")
		gas_box.Length = mesh_lattice_const*2.
		gas_box.Width = mesh_lattice_const*2.
		gas_box.Height = space_above_mesh + space_below_mesh + wire_diameter*2.
		gas_box.Placement.Base = FreeCAD.Vector(-mesh_lattice_const, -mesh_lattice_const, -space_below_mesh-wire_diameter)

		unit_cell = FreeCAD.activeDocument().addObject("Part::Cut", "Unit Cell")
		unit_cell.Base = gas_box
		unit_cell.Tool = mesh
		
		mesh.touch() # to force recomputation
		FreeCAD.ActiveDocument.recompute()
コード例 #25
0
    def copyTools(self):
        tools = []
        model = self.form.ToolsList.model()
        for i in range(model.rowCount()):
            item = model.item(i, 0)
            if item.checkState():
                item = model.index(i, 1)
                tools.append(item.data())
        if len(tools) == 0:
            return

        targets = self.TLM.getLists()
        currList = "<Main>"

        for target in targets:
            if target == currList:
                targets.remove(target)

        if len(targets) == 0:
            FreeCAD.Console.PrintWarning("no place to go")
            return
        elif len(targets) == 1:
            targetlist = targets[0]
        else:
            form = FreeCADGui.PySideUic.loadUi(":/panels/DlgToolCopy.ui")
            form.cboTarget.addItems(targets)
            r = form.exec_()
            if r is False:
                return None
            else:
                targetlist = form.cboTarget.currentText()

        for toolnum in tools:
            tool = self.TLM.getTool(currList, int(toolnum))
            PathLog.debug('tool: {}, toolnum: {}'.format(tool, toolnum))
            for i in FreeCAD.ActiveDocument.findObjects("Path::Feature"):
                if isinstance(i.Proxy, PathScripts.PathJob.ObjectPathJob) and i.Label == targetlist:

                    label = "T{}: {}".format(toolnum, tool.Name)
                    obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython",label)
                    PathScripts.PathLoadTool.LoadTool(obj)
                    PathScripts.PathLoadTool._ViewProviderLoadTool(obj.ViewObject)
                    PathUtils.addToJob(obj, targetlist)
                    FreeCAD.activeDocument().recompute()
                    newtool = tool.copy()
                    obj.Tooltable.setTool(int(toolnum), newtool)
                    obj.ToolNumber = int(toolnum)
                    #obj.recompute()
        FreeCAD.ActiveDocument.recompute()
コード例 #26
0
 def fusion(self,objnames_l):
    #
    # Init
    #
    obj_l=[]
    objna_l=[]
    obj0=objnames_l[0][0];name=objnames_l[0][1]
    objfuse=FreeCAD.activeDocument().addObject("Part::MultiFuse","Unfolding")
    for k in range( objnames_l.__len__() ):
      objk=objnames_l[k][0]
      obj_l.append(objk)
    objfuse.Shapes=obj_l
    FreeCAD.activeDocument().recompute()
    objna_l.append([objfuse,name])
    return objna_l 
コード例 #27
0
ファイル: Gearing.py プロジェクト: microelly2/Animation
	def step(self,now):
		say("Gearing step!" + str(now))
		FreeCAD.R=self
		self.ignore=True

		if now<self.obj2.start or now>self.obj2.end:
			sayd("ausserhalb")
			pass
		else:
			if not self.obj2.obj:
				errorDialog("kein Sketch zugeordnet")
				raise Exception(' self.obj2.obj nicht definiert')
			sys=self.obj2.obj
			s=sys.Links[0]
			pm=sys.Links[1]
			p=pm.Links[0]
			m=pm.Links[1]
			#say("sonne "+ s.Label)
			#say("planet "+ p.Label)
			#say("moinde" + m.Label)
			
			if now==self.obj2.start:
				s.Placement.Rotation.Axis=FreeCAD.Vector(0,0,1)
				p.Placement.Rotation.Axis=FreeCAD.Vector(0,0,1)
				m.Placement.Rotation.Axis=FreeCAD.Vector(0,0,1)
				
			# Eigenachsen Rotationen
			print(s.Placement.Rotation.Angle)
			an=s.Placement.Rotation.Angle
			ax=s.Placement.Rotation.Axis
			day_star=self.obj2.dayStar
			day_planet=self.obj2.dayPlanet
			day_moon=self.obj2.dayMoon

			rotstep(s,day_star)
			rotstep(p,day_planet)
			rotstep(m,day_moon)
			#p.Placement.Rotation.Angle += math.pi * 2/day_planet
			#m.Placement.Rotation.Angle += math.pi * 2/day_moon
			
			# Schenkel Rotationen
			sys.Placement.Rotation.Angle += 0
			pm.Placement.Rotation.Angle += 0
			
			FreeCAD.activeDocument().recompute()


		self.ignore=False
コード例 #28
0
ファイル: CommandsPolar.py プロジェクト: oddtopus/flamingo
 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())
コード例 #29
0
ファイル: PCBtoolBar.py プロジェクト: huigao80/FreeCAD-PCB
 def createCenteDrill(self):
     if FreeCAD.activeDocument() and getPCBheight()[0]:
         try:
             form = createDrillcenter_Gui()
             FreeCADGui.Control.showDialog(form)
         except Exception ,e:
             FreeCAD.Console.PrintWarning("{0} \n".format(e))
コード例 #30
0
def importDXFface(filename,layer=None,doc=None):
    import FreeCAD,importDXF
    doc = doc or FreeCAD.activeDocument()
    layers = importDXF.processdxf(doc,filename) or importDXF.layers
    for l in layers:
        if FreeCAD.GuiUp:
            for o in l.Group:
                o.ViewObject.hide()
            l.ViewObject.hide()
    groupobj=[go for go in layers if (not layer) or go.Label == layer]
    edges=[]
    if not groupobj:
        raise ValueError, 'import of layer %s failed' % layer
    for shapeobj in groupobj[0].Group:
        edges.extend(shapeobj.Shape.Edges)
    faces = edgestofaces(edges)
        # in order to allow multiple import with the same layer name
        # we need to remove used objects from the layer group
        #shapeobj.Document.removeObject(shapeobj.Name)
    #groupobj[0].Document.removeObject(groupobj[0].Name)
    for layer in layers: #remove everything that has been imported
        layer.removeObjectsFromDocument()
        #for obj in layer.Group:
        #    obj.Document.removeObject(obj.Name)
        layer.Document.removeObject(layer.Name)
    return faces
コード例 #31
0
    def generate_unit_cell(self, mesh_only=False):
        '''Generates a complete unit cell from single mesh wires.'''
        try:
            mesh_lattice_const = float(
                self.sb_mesh_lattice_const.text().replace(',', '.')) * 1e-3
            wire_diameter = float(self.sb_wire_diameter.text().replace(
                ',', '.')) * 1e-3
            space_above_mesh = float(self.sb_space_above_mesh.text().replace(
                ',', '.')) * 1e-3
            space_below_mesh = float(self.sb_space_below_mesh.text().replace(
                ',', '.')) * 1e-3
            safety_distance = float(
                self.sb_safety_distance.text().replace(',', '.')
            ) * 1e-3  # to prevent overlap of wires, which can cause trouble in later union or common operations and some other glitches
            num_blocks = int(self.sb_num_blocks.text().replace(
                ',', '.'))  # Number of wires to be drawn in each direction
        except:
            diag = QtGui.QMessageBox(QtGui.QMessageBox.Warning,
                                     'Evaluation error',
                                     'Error in evaluating the parameters')
            diag.setWindowModality(QtCore.Qt.ApplicationModal)
            diag.exec_()
            return False

        wires = {}
        for direction in ["x", "y"]:
            wires[direction] = []
            for wire_num in range(num_blocks * 4 +
                                  1):  # draw 4 wires in each direction
                wire = self.generate_wire(wire_diameter,
                                          mesh_lattice_const,
                                          safety_distance=safety_distance,
                                          num_blocks=num_blocks)
                # position wire
                if direction == "x":
                    wire.Placement.Base += FreeCAD.Vector(
                        0, wire_num * mesh_lattice_const, 0)
                    if wire_num % 2:
                        wire.Placement.Rotation = FreeCAD.Rotation(
                            FreeCAD.Vector(1, 0, 0), 180)
                    else:
                        wire.Placement.Base += FreeCAD.Vector(
                            0, 0, 2 * safety_distance)
                else:
                    wire.Placement.Rotation = FreeCAD.Rotation(
                        FreeCAD.Vector(0, 0, 1), 90)
                    wire.Placement.Base += FreeCAD.Vector(
                        wire_num * mesh_lattice_const, 0, 0)
                    if not wire_num % 2:
                        wire.Placement.Rotation = wire.Placement.Rotation.multiply(
                            FreeCAD.Rotation(FreeCAD.Vector(1, 0, 0), 180))
                    else:
                        wire.Placement.Base += FreeCAD.Vector(
                            0, 0, 2 * safety_distance)

                wires[direction].append(wire)

        mesh = FreeCAD.activeDocument().addObject("Part::MultiFuse", "Mesh")
        mesh.Shapes = wires["x"] + wires["y"]
        mesh.Placement.Base = FreeCAD.Vector(
            -2. * mesh_lattice_const * num_blocks,
            -2. * mesh_lattice_const * num_blocks,
            0)  # translate mesh to origin

        if not mesh_only:
            gas_box = FreeCAD.activeDocument().addObject("Part::Box", "Gas")
            gas_box.Length = mesh_lattice_const * 2.
            gas_box.Width = mesh_lattice_const * 2.
            gas_box.Height = space_above_mesh + space_below_mesh + wire_diameter * 2.
            gas_box.Placement.Base = FreeCAD.Vector(
                -mesh_lattice_const, -mesh_lattice_const,
                -space_below_mesh - wire_diameter)

            unit_cell = FreeCAD.activeDocument().addObject(
                "Part::Cut", "Unit Cell")
            unit_cell.Base = gas_box
            unit_cell.Tool = mesh

        mesh.touch()  # to force recomputation
        FreeCAD.ActiveDocument.recompute()
コード例 #32
0
def run():
    '''create a generic panel without data'''

    a = FreeCAD.activeDocument().addObject("Part::FeaturePython", "MyMonitor")
    ControlPanel(a)
コード例 #33
0
    cp = App.activeDocument().addObject("Part::Compound", "Compound")
    cp.Links = [c, co]

    #	fu=App.activeDocument().addObject("Part::MultiFuse","Fusion")
    #	fu.Shapes = [b,co]

    cm = App.activeDocument().addObject("Part::MultiCommon", "Common")
    cm.Shapes = [b, co]

    for k in [b, c, co, cp]:
        k.ViewObject.Transparency = 70

    App.ActiveDocument.recompute()

    #-------------------------------
    a = FreeCAD.activeDocument().addObject("Part::FeaturePython",
                                           "MyControlPanel")
    m = ControlPanel(a)
    #-----------------------------

    #-- add some parameters to control
    m.addTarget(c, "Angle", maxV=360, minV=0)
    m.addTarget(ss, "A1", maxV=360, minV=0)
    #	m.addTarget(ss,"B4",maxV=360,minV=0)

    if 10:
        m.addTarget(c, "Radius")
        #		m.addTarget(co,"Radius1")
        m.addTarget(co, "Radius2")

        m.addTarget(co, "Height")
        m.addTarget(b, 'Length')
コード例 #34
0
 def shouldShow(self):
     """ Must show when nothing selected.
     """
     return (len(Gui.Selection.getSelectionEx(
         App.activeDocument().Name)) == 0)
コード例 #35
0
 def IsActive(self):
     if FreeCAD.activeDocument() is None: return False
     return True
コード例 #36
0
ファイル: TestGui.py プロジェクト: microelly2/FreeCAD-1
 def Activated(self):
     if FreeCAD.activeDocument() != None:
         FreeCAD.activeDocument().addObject("App::FeatureTest")
     else:
         FreeCAD.PrintMessage("No active document.\n")
コード例 #37
0
    def draw(self):

        #helper Variables
        width = gv.printableWidth + gv.printBedPadding
        length = gv.printableLength + gv.printBedPadding

        #Make file and build part
        try:
            Gui.getDocument("printBedSupport")
            Gui.getDocument("printBedSupport").resetEdit()
            App.getDocument("printBedSupport").recompute()
            App.closeDocument("printBedSupport")
            App.setActiveDocument("")
            App.ActiveDocument = None
            Gui.ActiveDocument = None
        except:
            pass

        #Create Document
        App.newDocument("printBedSupport")
        App.setActiveDocument("printBedSupport")
        App.ActiveDocument = App.getDocument("printBedSupport")
        Gui.ActiveDocument = Gui.getDocument("printBedSupport")

        #make plate
        #Sketch points
        p1x = -width / 2
        p1y = -length / 2
        p2x = -width / 2
        p2y = length / 2
        p3x = width / 2
        p3y = length / 2
        p4x = width / 2
        p4y = -length / 2
        p5x = -(width / 2 - gv.printBedMountHolePadding)
        p5y = -(length / 2 - gv.printBedMountHolePadding)
        p6x = -(width / 2 - gv.printBedMountHolePadding)
        p6y = (length / 2 - gv.printBedMountHolePadding)
        p7x = (width / 2 - gv.printBedMountHolePadding)
        p7y = (length / 2 - gv.printBedMountHolePadding)
        p8x = (width / 2 - gv.printBedMountHolePadding)
        p8y = -(length / 2 - gv.printBedMountHolePadding)
        p9x = (width / 2 - gv.printBedMountHolePadding)
        p9y = length / 2
        p10x = width / 2
        p10y = (length / 2 - gv.printBedMountHolePadding)

        App.activeDocument().addObject('Sketcher::SketchObject', 'Sketch')
        App.activeDocument().Sketch.Placement = App.Placement(
            App.Vector(0.000000, 0.000000, 0.000000),
            App.Rotation(0.000000, 0.000000, 0.000000, 1.000000))
        Gui.activeDocument().activeView().setCamera(
            '#Inventor V2.1 ascii \n OrthographicCamera {\n viewportMapping ADJUST_CAMERA \n position 0 0 87 \n orientation 0 0 1  0 \n nearDistance -112.88701 \n farDistance 287.28702 \n aspectRatio 1 \n focalDistance 87 \n height 143.52005 }'
        )
        #		Gui.activeDocument().setEdit('Sketch')
        App.ActiveDocument.Sketch.addGeometry(
            Part.Line(App.Vector(p1x, p1y, 0), App.Vector(p4x, p4y, 0)))
        App.ActiveDocument.Sketch.addGeometry(
            Part.Line(App.Vector(p4x, p4y, 0), App.Vector(p3x, p3y, 0)))
        App.ActiveDocument.Sketch.addGeometry(
            Part.Line(App.Vector(p3x, p3y, 0), App.Vector(p2x, p2y, 0)))
        App.ActiveDocument.Sketch.addGeometry(
            Part.Line(App.Vector(p2x, p2y, 0), App.Vector(p1x, p1y, 0)))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 0, 2, 1, 1))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 1, 2, 2, 1))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 2, 2, 3, 1))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 3, 2, 0, 1))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Horizontal', 0))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Horizontal', 2))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Vertical', 1))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Vertical', 3))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Symmetric', 1, 2, 0, 1, -1, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addGeometry(
            Part.Line(App.Vector(p5x, p5y, 0), App.Vector(p8x, p8y, 0)))
        App.ActiveDocument.Sketch.addGeometry(
            Part.Line(App.Vector(p8x, p8y, 0), App.Vector(p7x, p7y, 0)))
        App.ActiveDocument.Sketch.addGeometry(
            Part.Line(App.Vector(p7x, p7y, 0), App.Vector(p6x, p6y, 0)))
        App.ActiveDocument.Sketch.addGeometry(
            Part.Line(App.Vector(p6x, p6y, 0), App.Vector(p5x, p5y, 0)))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 4, 2, 5, 1))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 5, 2, 6, 1))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 6, 2, 7, 1))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 7, 2, 4, 1))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Horizontal', 4))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Horizontal', 6))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Vertical', 5))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Vertical', 7))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addGeometry(
            Part.Line(App.Vector(p9x, p9y, 0), App.Vector(p7x, p7y, 0)))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('PointOnObject', 8, 1, 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 8, 2, 5, 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addGeometry(
            Part.Line(App.Vector(p7x, p7y, 0), App.Vector(p10x, p10y, 0)))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 8, 2, 9, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('PointOnObject', 9, 2, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Horizontal', 9))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Vertical', 8))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Equal', 8, 9))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.movePoint(4, 0,
                                            App.Vector(0.000000, 0.000000, 0),
                                            1)
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.toggleConstruction(6)
        App.ActiveDocument.Sketch.toggleConstruction(5)
        App.ActiveDocument.Sketch.toggleConstruction(7)
        App.ActiveDocument.Sketch.toggleConstruction(4)
        App.ActiveDocument.Sketch.toggleConstruction(8)
        App.ActiveDocument.Sketch.toggleConstruction(9)
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addGeometry(
            Part.Circle(App.Vector(p6x, p6y, 0), App.Vector(0, 0, 1),
                        gv.mountToPrintedDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 10, 3, 6, 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addGeometry(
            Part.Circle(App.Vector(p7x, p7y, 0), App.Vector(0, 0, 1),
                        gv.mountToPrintedDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 11, 3, 5, 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addGeometry(
            Part.Circle(App.Vector(p5x, p5y, 0), App.Vector(0, 0, 1),
                        gv.mountToPrintedDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 12, 3, 4, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addGeometry(
            Part.Circle(App.Vector(p8x, p8y, 0), App.Vector(0, 0, 1),
                        gv.mountToPrintedDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 13, 3, 4, 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Equal', 13, 12))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Equal', 12, 10))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Equal', 10, 11))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Symmetric', 5, 2, 4, 1, -1, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('DistanceY', 1, length))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('DistanceX', 0, width))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint(
                'DistanceX', 9,
                gv.printBedMountHolePadding + gv.mountToPrintedDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Radius', 10, gv.mountToPrintedDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.movePoint(
            4, 1, App.Vector(-37.291931, -32.210766, 0), 0)
        App.ActiveDocument.recompute()

        #		Gui.getDocument('printBedSupport').resetEdit()
        App.getDocument('printBedSupport').recompute()
        App.activeDocument().addObject("PartDesign::Pad", "Pad")
        App.activeDocument().Pad.Sketch = App.activeDocument().Sketch
        App.activeDocument().Pad.Length = 10.0
        App.ActiveDocument.recompute()
        Gui.activeDocument().hide("Sketch")
        App.ActiveDocument.Pad.Length = gv.printBedSupportThickness
        App.ActiveDocument.Pad.Reversed = 0
        App.ActiveDocument.Pad.Midplane = 0
        App.ActiveDocument.Pad.Length2 = 100.000000
        App.ActiveDocument.Pad.Type = 0
        App.ActiveDocument.Pad.UpToFace = None
        App.ActiveDocument.recompute()
        #		Gui.activeDocument().resetEdit()

        #Make holes for y bushing mounts
        #Sketch Points
        p1x = -gv.yRodSpacing / 2
        p1y = -length / 2
        p2x = -gv.yRodSpacing / 2
        p2y = length / 2
        p3x = gv.yRodSpacing / 2
        p3y = -length / 2
        p4x = gv.yRodSpacing / 2
        p4y = length / 2
        p5x = -gv.yRodSpacing / 2 - gv.yBushingMountSlotSpacing / 2
        p5y = -gv.yBushingNutSeparation / 2
        p6x = -gv.yRodSpacing / 2 + gv.yBushingMountSlotSpacing / 2
        p6y = -gv.yBushingNutSeparation / 2
        p7x = -gv.yRodSpacing / 2 - gv.yBushingMountSlotSpacing / 2
        p7y = gv.yBushingNutSeparation / 2
        p8x = -gv.yRodSpacing / 2 + gv.yBushingMountSlotSpacing / 2
        p8y = gv.yBushingNutSeparation / 2
        p9x = gv.yRodSpacing / 2 - gv.yBushingMountSlotSpacing / 2
        p9y = -gv.yBushingNutSeparation / 2
        p10x = gv.yRodSpacing / 2 + gv.yBushingMountSlotSpacing / 2
        p10y = -gv.yBushingNutSeparation / 2
        p11x = gv.yRodSpacing / 2 - gv.yBushingMountSlotSpacing / 2
        p11y = gv.yBushingNutSeparation / 2
        p12x = gv.yRodSpacing / 2 + gv.yBushingMountSlotSpacing / 2
        p12y = gv.yBushingNutSeparation / 2
        p13x = p1x
        p13y = p5y
        p14x = p1x
        p14y = p7y
        p15x = p3x
        p15y = p5y
        p16x = p3x
        p16y = p7y

        #Make Sketch
        App.activeDocument().addObject('Sketcher::SketchObject', 'Sketch001')
        App.activeDocument().Sketch001.Support = uf.getFace(
            App.ActiveDocument.Pad, None, None, None, None,
            gv.printBedSupportThickness, 0)
        App.activeDocument().recompute()
        #		Gui.activeDocument().setEdit('Sketch001')
        App.ActiveDocument.Sketch001.addExternal(
            "Pad",
            uf.getEdge(App.ActiveDocument.Pad, 0, 0, length / 2, 0,
                       gv.printBedSupportThickness, 0))
        App.ActiveDocument.Sketch001.addExternal(
            "Pad",
            uf.getEdge(App.ActiveDocument.Pad, 0, 0, -length / 2, 0,
                       gv.printBedSupportThickness, 0))
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Line(App.Vector(p1x, p1y, 0), App.Vector(p2x, p2y, 0)))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('PointOnObject', 0, 1, -4))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Line(App.Vector(p3x, p3y, 0), App.Vector(p4x, p4y, 0)))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('PointOnObject', 1, 1, -4))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Symmetric', 1, 2, 0, 2, -2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Line(App.Vector(p5x, p5y, 0), App.Vector(p6x, p6y, 0)))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Horizontal', 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Line(App.Vector(p7x, p7y, 0), App.Vector(p8x, p8y, 0)))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Horizontal', 3))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Line(App.Vector(p9x, p9y, 0), App.Vector(p10x, p10y, 0)))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Line(App.Vector(p11x, p11y, 0), App.Vector(p12x, p12y, 0)))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Horizontal', 5))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Horizontal', 4))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Equal', 3, 5))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Equal', 5, 4))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Equal', 4, 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Symmetric', 3, 2, 3, 1, 0))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Symmetric', 2, 2, 2, 1, 0))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Symmetric', 5, 2, 5, 1, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Symmetric', 4, 2, 4, 1, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('PointOnObject', 3, 2, 5))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('PointOnObject', 0, 2, -3))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('PointOnObject', 2, 2, 4))
        App.ActiveDocument.recompute()

        #Add Dimmensions early to avoid squishing sketch
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Distance', 5, 2, 4, gv.yBushingNutSeparation))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Distance', 1, 1, 0, 1, gv.yRodSpacing))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('DistanceX', 4, gv.yBushingMountSlotSpacing))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Symmetric', 3, 1, 2, 1, -1))
        App.ActiveDocument.recompute()

        #continue adding other constraints
        App.ActiveDocument.Sketch001.toggleConstruction(0)
        App.ActiveDocument.Sketch001.toggleConstruction(1)
        App.ActiveDocument.Sketch001.toggleConstruction(5)
        App.ActiveDocument.Sketch001.toggleConstruction(4)
        App.ActiveDocument.Sketch001.toggleConstruction(2)
        App.ActiveDocument.Sketch001.toggleConstruction(3)
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Circle(App.Vector(p5x, p5y, 0), App.Vector(0, 0, 1),
                        gv.mountToPrintedDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 6, 3, 2, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Circle(App.Vector(p6x, p6y, 0), App.Vector(0, 0, 1),
                        gv.mountToPrintedDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 7, 3, 2, 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Circle(App.Vector(p7x, p7y, 0), App.Vector(0, 0, 1),
                        gv.mountToPrintedDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 8, 3, 3, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Circle(App.Vector(p8x, p8y, 0), App.Vector(0, 0, 1),
                        gv.mountToPrintedDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 9, 3, 3, 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Circle(App.Vector(p9x, p9y, 0), App.Vector(0, 0, 1),
                        gv.mountToPrintedDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 10, 3, 5, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Circle(App.Vector(p10x, p10y, 0), App.Vector(0, 0, 1),
                        gv.mountToPrintedDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 11, 3, 5, 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Circle(App.Vector(p11x, p11y, 0), App.Vector(0, 0, 1),
                        gv.mountToPrintedDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 12, 3, 4, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Circle(App.Vector(p12x, p12y, 0), App.Vector(0, 0, 1),
                        gv.mountToPrintedDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 13, 3, 4, 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Equal', 6, 7))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Equal', 7, 8))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Equal', 8, 9))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Equal', 9, 10))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Equal', 10, 11))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Equal', 11, 12))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Equal', 12, 13))
        App.ActiveDocument.recompute()

        #Add hole Dimensions
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Radius', 11, gv.mountToPrintedDia / 2))
        App.ActiveDocument.recompute()

        #Cut bushing mount holes through all
        App.activeDocument().addObject("PartDesign::Pocket", "Pocket")
        App.activeDocument().Pocket.Sketch = App.activeDocument().Sketch001
        App.activeDocument().Pocket.Length = 5.0
        App.ActiveDocument.recompute()
        Gui.activeDocument().hide("Sketch001")
        Gui.activeDocument().hide("Pad")
        #		Gui.activeDocument().setEdit('Pocket')
        #		Gui.ActiveDocument.Pocket.ShapeColor=Gui.ActiveDocument.Pad.ShapeColor
        #		Gui.ActiveDocument.Pocket.LineColor=Gui.ActiveDocument.Pad.LineColor
        #		Gui.ActiveDocument.Pocket.PointColor=Gui.ActiveDocument.Pad.PointColor
        App.ActiveDocument.Pocket.Length = 5.000000
        App.ActiveDocument.Pocket.Type = 1
        App.ActiveDocument.Pocket.UpToFace = None
        App.ActiveDocument.recompute()
        #		Gui.activeDocument().resetEdit()

        #Make holes for y belt anchor
        #Sketch points
        p1x = gv.yMotorPulleyDia / 2
        p1y = gv.yBeltAnchorHoleSpacing / 2
        p2x = p1x
        p2y = -p1y

        #Make Sketch
        App.activeDocument().addObject('Sketcher::SketchObject', 'Sketch002')
        App.activeDocument().Sketch002.Support = uf.getFace(
            App.ActiveDocument.Pocket, None, None, None, None,
            gv.printBedSupportThickness, 0)
        App.activeDocument().recompute()
        #		Gui.activeDocument().setEdit('Sketch002')
        App.ActiveDocument.Sketch002.addGeometry(
            Part.Circle(App.Vector(p1x, p1y, 0), App.Vector(0, 0, 1),
                        gv.mountToPrintedDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addGeometry(
            Part.Circle(App.Vector(p2x, p2y, 0), App.Vector(0, 0, 1),
                        gv.mountToPrintedDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Symmetric', 0, 3, 1, 3, -1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Equal', 0, 1))
        App.ActiveDocument.recompute()

        #Add dimensions
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Radius', 0, gv.mountToPrintedDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('DistanceX', -2, 1, 1, 3,
                                gv.yMotorPulleyDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Distance', 0, 3, 1, 3,
                                gv.yBeltAnchorHoleSpacing))
        App.ActiveDocument.recompute()
        #		Gui.getDocument('printBedSupport').resetEdit()
        App.getDocument('printBedSupport').recompute()

        #Cut holes
        App.activeDocument().addObject("PartDesign::Pocket", "Pocket001")
        App.activeDocument().Pocket001.Sketch = App.activeDocument().Sketch002
        App.activeDocument().Pocket001.Length = 5.0
        App.ActiveDocument.recompute()
        Gui.activeDocument().hide("Sketch002")
        Gui.activeDocument().hide("Pocket")
        #		Gui.ActiveDocument.Pocket001.ShapeColor=Gui.ActiveDocument.Pocket.ShapeColor
        #		Gui.ActiveDocument.Pocket001.LineColor=Gui.ActiveDocument.Pocket.LineColor
        #		Gui.ActiveDocument.Pocket001.PointColor=Gui.ActiveDocument.Pocket.PointColor
        App.ActiveDocument.Pocket001.Length = 5.000000
        App.ActiveDocument.Pocket001.Type = 1
        App.ActiveDocument.Pocket001.UpToFace = None
        App.ActiveDocument.recompute()
コード例 #38
0
    def onImport(self):
        Bbox = GIS2BIM.CreateBoundingBox(float(self.X), float(self.Y),
                                         float(self.bboxWidth.text()),
                                         float(self.bboxHeight.text()), 2)
        width = float(self.bboxWidth.text())
        height = float(self.bboxHeight.text())
        GIS2BIM_FreeCAD.CreateLayer("PDOK")
        fileLocationWMS = self.tempFolderPath + "wms.jpg"

        #Create Cadastral Parcels 2D
        if self.clsCad.isChecked() is True:
            GIS_2D_Cadastral_Parcel = GIS2BIM_FreeCAD.CreateLayer(
                "GIS_2D_Cadastral_Parcel")
            CadastralParcelCurves = GIS2BIM_FreeCAD.CurvesFromWFS(
                GIS2BIM_NL.NLPDOKCadastreCadastralParcels, Bbox,
                GIS2BIM_NL.NLPDOKxPathOpenGISposList, -float(self.X),
                -float(self.Y), 1000, 3, False, False, u"Dashdot",
                (0.0, 0.0, 0.0))
            FreeCAD.activeDocument().getObject(
                "GIS_2D_Cadastral_Parcel").addObjects(CadastralParcelCurves)
            FreeCAD.activeDocument().getObject("PDOK").addObject(
                FreeCAD.activeDocument().getObject("GIS_2D_Cadastral_Parcel"))

        #Create Building outline 2D
        if self.clsBld.isChecked() is True:
            GIS_2D_Building_Outline = GIS2BIM_FreeCAD.CreateLayer(
                "GIS_2D_Building_Outline")
            BAGCurves = GIS2BIM_FreeCAD.CurvesFromWFS(
                GIS2BIM_NL.NLPDOKBAGBuildingCountour, Bbox,
                GIS2BIM_NL.NLPDOKxPathOpenGISposList, -float(self.X),
                -float(self.Y), 1000, 3, True, True, u"Solid", (0.7, 0.0, 0.0))
            FreeCAD.activeDocument().getObject(
                "GIS_2D_Building_Outline").addObjects(BAGCurves)
            FreeCAD.activeDocument().getObject("PDOK").addObject(
                FreeCAD.activeDocument().getObject("GIS_2D_Building_Outline"))

        #Create 3D Building BAG 3D V2
        if self.clsBAG3D.isChecked() is True:
            dx = -float(self.X) * 1000
            dy = -float(self.Y) * 1000
            bboxString = GIS2BIM.CreateBoundingBox(
                float(
                    GIS2BIM_FreeCAD.ArchSiteCreateCheck(self.sitename).CRS_x),
                float(
                    GIS2BIM_FreeCAD.ArchSiteCreateCheck(self.sitename).CRS_y),
                float(self.bboxWidth.text()), float(self.bboxHeight.text()), 0)
            jsonFileNames = GIS2BIM_NL.BAG3DDownload(Bbox, self.tempFolderPath)

            #Import JSON
            for jsonFile in jsonFileNames:
                meshes = GIS2BIM_FreeCAD.CityJSONImport(
                    jsonFile, self.X, self.Y, 2, float(self.bboxWidth.text()),
                    float(self.bboxHeight.text()))

            FreeCAD.activeDocument().getObject("PDOK").addObject(
                FreeCAD.activeDocument().getObject("CityJSON"))

        # Import Aerialphoto in view
        if self.clsAerial.isChecked() is True:
            GIS_Raster = GIS2BIM_FreeCAD.CreateLayer("GIS_Raster")
            a = GIS2BIM.WMSRequest(
                GIS2BIM.GetWebServerData("NL_PDOK_Luchtfoto_2020_28992",
                                         "webserverRequests",
                                         "serverrequestprefix"), Bbox,
                fileLocationWMS, 3000, 3000)
            ImageAerialPhoto = GIS2BIM_FreeCAD.ImportImage(
                fileLocationWMS, width, height, 1000, "luchtfoto2020", 0, 0)
            ImageAerialPhoto.addProperty("App::PropertyString",
                                         "WMSRequestURL")
            ImageAerialPhoto.WMSRequestURL = a[2]
            FreeCAD.activeDocument().getObject("GIS_Raster").addObject(
                FreeCAD.activeDocument().getObject(ImageAerialPhoto.Label))
            FreeCAD.activeDocument().getObject("PDOK").addObject(
                FreeCAD.activeDocument().getObject("GIS_Raster"))

        #Create Textdata Cadastral Parcels
        if self.clsAnnotation.isChecked() is True:
            GIS_Annotation = GIS2BIM_FreeCAD.CreateLayer("GIS_Annotation")
            textDataCadastralParcels = GIS2BIM.DataFromWFS(
                GIS2BIM_NL.NLPDOKCadastreCadastralParcelsNummeraanduiding,
                Bbox, GIS2BIM_NL.NLPDOKxPathOpenGISPos,
                GIS2BIM_NL.xPathStringsCadastreTextAngle, -float(self.X),
                -float(self.Y), 1000, 3)
            textDataOpenbareRuimtenaam = GIS2BIM.DataFromWFS(
                GIS2BIM_NL.NLPDOKCadastreOpenbareruimtenaam, Bbox,
                GIS2BIM_NL.NLPDOKxPathOpenGISPos,
                GIS2BIM_NL.xPathStringsCadastreTextAngle, -float(self.X),
                -float(self.Y), 1000, 3)
            placeTextFreeCAD1 = GIS2BIM_FreeCAD.PlaceText(
                textDataCadastralParcels, 500, 0)
            placeTextFreeCAD2 = GIS2BIM_FreeCAD.PlaceText(
                textDataOpenbareRuimtenaam, 2000, 1)
            FreeCAD.activeDocument().getObject("GIS_Annotation").addObjects(
                placeTextFreeCAD1)
            FreeCAD.activeDocument().getObject("GIS_Annotation").addObjects(
                placeTextFreeCAD2)
            FreeCAD.activeDocument().getObject("PDOK").addObject(
                FreeCAD.activeDocument().getObject("GIS_Annotation"))

        #Create Ruimtelijke plannen outline 2D
        if self.clsBouwvlak.isChecked() is True:
            GIS_2D_Ruimtelijke_Plannen = GIS2BIM_FreeCAD.CreateLayer(
                "GIS_2D_Ruimtelijke_Plannen")
            RuimtelijkePlannenBouwvlakCurves = GIS2BIM_FreeCAD.CurvesFromWFS(
                GIS2BIM_NL.NLRuimtelijkeplannenBouwvlak, Bbox,
                ".//{http://www.opengis.net/gml}posList", -float(self.X),
                -float(self.Y), 1000, 3, False, False, u"Solid",
                (0.0, 0.0, 1.0))
            FreeCAD.activeDocument().getObject(
                "GIS_2D_Ruimtelijke_Plannen").addObjects(
                    RuimtelijkePlannenBouwvlakCurves)
            FreeCAD.activeDocument().getObject("PDOK").addObject(
                FreeCAD.activeDocument().getObject(
                    "GIS_2D_Ruimtelijke_Plannen"))

        #Create BGT 2D
        if self.clsBGT.isChecked() is True:
            timeout = 150
            folderBGT = GIS2BIM_FreeCAD.CreateTempFolder(self.tempFolderName +
                                                         '/BGT')
            filepathZIP = folderBGT + '.zip'

            #Download BGT
            URL = GIS2BIM_NL.bgtDownloadURL(float(self.X), float(self.Y),
                                            float(self.bboxWidth.text()),
                                            float(self.bboxHeight.text()),
                                            timeout)
            GIS2BIM.downloadUnzip(URL, filepathZIP, folderBGT)

            #Create Curves

            bgt_curves_faces = [
                "bgt_begroeidterreindeel", "bgt_onbegroeidterreindeel",
                "bgt_ondersteunendwaterdeel", "bgt_ondersteunendwegdeel",
                "bgt_overbruggingsdeel", "bgt_overigbouwwerk", "bgt_waterdeel",
                "bgt_wegdeel"
            ]

            bgt_curves_faces_color = [(223 / 255, 230 / 255, 208 / 255),
                                      (223 / 255, 230 / 255, 208 / 255),
                                      (205 / 255, 230 / 255, 237 / 255),
                                      (226 / 255, 226 / 255, 226 / 255),
                                      (234 / 255, 234 / 255, 234 / 255),
                                      (220 / 255, 155 / 255, 140 / 255),
                                      (205 / 255, 230 / 255, 237 / 255),
                                      (234 / 255, 234 / 255, 234 / 255)]

            bgt_curves_lines = [
                "bgt_functioneelgebied", "bgt_gebouwinstallatie",
                "bgt_kunstwerkdeel", "bgt_overbruggingsdeel",
                "bgt_overigbouwwerk", "bgt_overigescheiding", "bgt_scheiding",
                "bgt_spoor", "bgt_tunneldeel"
            ]

            xpath = './/{http://www.opengis.net/gml}posList'

            GIS2BIM_FreeCAD.CreateLayer("BGT")

            #Draw bgt_curves_lines
            for i in bgt_curves_lines:
                path = folderBGT + '/' + i + '.gml'
                tree = ET.parse(path)
                Curves = GIS2BIM_FreeCAD.CurvesFromGML(
                    tree, xpath, -float(self.X), -float(self.Y),
                    float(self.bboxWidth.text()),
                    float(self.bboxHeight.text()), 1000, 0, 0, 0, "Solid",
                    (0.7, 0.0, 0.0), (0.0, 0.0, 0.0))
                GIS2BIM_FreeCAD.CreateLayer(i)
                FreeCAD.activeDocument().getObject(i).addObjects(Curves)
                FreeCAD.activeDocument().getObject("BGT").addObject(
                    FreeCAD.activeDocument().getObject(i))
                FreeCAD.ActiveDocument.recompute()

            for i, j in zip(bgt_curves_faces, bgt_curves_faces_color):
                path = folderBGT + '/' + i + '.gml'
                tree = ET.parse(path)
                Curves = GIS2BIM_FreeCAD.CurvesFromGML(
                    tree, xpath, -float(self.X), -float(self.Y),
                    float(self.bboxWidth.text()),
                    float(self.bboxHeight.text()), 1000, 2, 1, 1, "Solid",
                    (0.7, 0.0, 0.0), j)
                GIS2BIM_FreeCAD.CreateLayer(i)
                FreeCAD.activeDocument().getObject(i).addObjects(Curves)
                FreeCAD.activeDocument().getObject("BGT").addObject(
                    FreeCAD.activeDocument().getObject(i))
                FreeCAD.ActiveDocument.recompute()

            FreeCAD.activeDocument().getObject("PDOK").addObject(
                FreeCAD.activeDocument().getObject("BGT"))

        # Import bestemmingsplankaart
        if self.clsBestemmingsplan.isChecked() is True:
            GIS_Raster = GIS2BIM_FreeCAD.CreateLayer("GIS_Raster")
            a = GIS2BIM.WMSRequest(
                GIS2BIM.GetWebServerData(
                    "NL_INSPIRE_Ruimtelijke_Plannen_Totaal_28992",
                    "webserverRequests", "serverrequestprefix"), Bbox,
                fileLocationWMS, 3000, 3000)
            ImageAerialPhoto = GIS2BIM_FreeCAD.ImportImage(
                fileLocationWMS, width, height, 1000, "Ruimtelijke Plannen", 0,
                0)
            ImageAerialPhoto.addProperty("App::PropertyString",
                                         "WMSRequestURL")
            ImageAerialPhoto.WMSRequestURL = a[2]
            FreeCAD.activeDocument().getObject("GIS_Raster").addObject(
                FreeCAD.activeDocument().getObject(ImageAerialPhoto.Label))
            FreeCAD.activeDocument().getObject("PDOK").addObject(
                FreeCAD.activeDocument().getObject("GIS_Raster"))

        FreeCAD.ActiveDocument.recompute()
        self.close()
コード例 #39
0
ファイル: make_fillet.py プロジェクト: zyqcome/FreeCAD
def make_fillet(objs, radius=100, chamfer=False, delete=False):
    """Create a fillet between two lines or Part.Edges.

    Parameters
    ----------
    objs: list
        List of two objects of type wire, or edges.

    radius: float, optional
        It defaults to 100. The curvature of the fillet.

    chamfer: bool, optional
        It defaults to `False`. If it is `True` it no longer produces
        a rounded fillet but a chamfer (straight edge)
        with the value of the `radius`.

    delete: bool, optional
        It defaults to `False`. If it is `True` it will delete
        the pair of objects that are used to create the fillet.
        Otherwise, the original objects will still be there.

    Returns
    -------
    Part::Part2DObjectPython
        The object of Proxy type `'Fillet'`.
        It returns `None` if it fails producing the object.
    """
    _name = "make_fillet"
    utils.print_header(_name, "Fillet")

    if len(objs) != 2:
        _err(_tr("Two elements are needed."))
        return None

    e1, e2 = _extract_edges(objs)

    edges = DraftGeomUtils.fillet([e1, e2], radius, chamfer)
    if len(edges) < 3:
        _err(_tr("Radius is too large") + ", r={}".format(radius))
        return None

    lengths = [edges[0].Length, edges[1].Length, edges[2].Length]
    _msg(_tr("Segment") + " 1, " + _tr("length:") + " {}".format(lengths[0]))
    _msg(_tr("Segment") + " 2, " + _tr("length:") + " {}".format(lengths[1]))
    _msg(_tr("Segment") + " 3, " + _tr("length:") + " {}".format(lengths[2]))

    try:
        wire = Part.Wire(edges)
    except Part.OCCError:
        return None

    _doc = App.activeDocument()
    obj = _doc.addObject("Part::Part2DObjectPython",
                         "Fillet")
    fillet.Fillet(obj)
    obj.Shape = wire
    obj.Length = wire.Length
    obj.Start = wire.Vertexes[0].Point
    obj.End = wire.Vertexes[-1].Point
    obj.FilletRadius = radius

    if delete:
        _doc.removeObject(objs[0].Name)
        _doc.removeObject(objs[1].Name)
        _msg(_tr("Removed original objects."))

    if App.GuiUp:
        view_fillet.ViewProviderFillet(obj.ViewObject)
        gui_utils.format_object(obj)
        gui_utils.select(obj)
        gui_utils.autogroup(obj)

    return obj
コード例 #40
0
 def shouldShow(self):
     return (len(Gui.Selection.getSelectionEx(
         App.activeDocument().Name)) == 0)
コード例 #41
0
import FreeCAD, Part, Drawing, math, Mesh, importDXF

DOC = FreeCAD.activeDocument()

DOC_NAME = "part_blade"


def clear_doc():
    # Clear the active document deleting all the objects
    for obj in DOC.Objects:
        DOC.removeObject(obj.Name)


def setview():
    # Rearrange View
    FreeCAD.Gui.SendMsgToActiveView("ViewFit")
    FreeCAD.Gui.activeDocument().activeView().viewAxometric()


if DOC is None:
    FreeCAD.newDocument(DOC_NAME)
    FreeCAD.setActiveDocument(DOC_NAME)
    DOC = FreeCAD.activeDocument()
else:
    clear_doc()

# EPS= tolerance to use to cut the parts
EPS = 0.10
EPS_C = EPS * (-0.5)

diametre_maximal = 406.4 - 8 * 2 - 5 * 2
コード例 #42
0
        mh1Y = button1Y - 300
        mh2Y = button3Y + 300
        self.button1 = Button(self.name+"_button1",\
                              Base.Vector(buttonX,button1Y,\
                                          self.origin.z+self._boardThick))
        self.button2 = Button(self.name+"_button2",\
                              Base.Vector(buttonX,button2Y,\
                                          self.origin.z+self._boardThick))
        self.button3 = Button(self.name+"_button3",\
                              Base.Vector(buttonX,button3Y,\
                                          self.origin.z+self._boardThick))
        self.mh1 = Base.Vector(mhX,mh1Y,self.origin.z)
        self.mh2 = Base.Vector(mhX,mh2Y,self.origin.z)
        self.board = self.board.cut(Part.Face(Part.Wire(\
                                        Part.makeCircle(self._mholerad,\
                                                        self.mh1))\
                                  ).extrude(Base.Vector(0,0,self._boardThick)))
        self.board = self.board.cut(Part.Face(Part.Wire(\
                                        Part.makeCircle(self._mholerad,\
                                                        self.mh2))\
                                  ).extrude(Base.Vector(0,0,self._boardThick)))


if __name__ == '__main__':
    App.ActiveDocument=App.newDocument("ButtonBoard")
    doc = App.activeDocument()
    buttonBoard = ButtonBoard("buttonboard",Base.Vector(0,0,0))
    buttonBoard.show()
    Gui.SendMsgToActiveView("ViewFit") 
    Gui.activeDocument().activeView().viewIsometric()
コード例 #43
0
def getUnderwaterSide(shape, force=True):
    """Get the underwater shape, simply cropping the provided shape by the z=0
    free surface plane.

    Position arguments:
    shape -- Solid shape to be cropped

    Keyword arguments:
    force -- True if in case the common boolean operation fails, i.e. returns
    no solids, the tool should retry it slightly moving the free surface. False
    otherwise. (True by default)

    Returned value:
    Cropped shape. It is not modifying the input shape
    """
    # Convert the shape into an active object
    Part.show(shape)
    orig = App.ActiveDocument.Objects[-1]
    guiObj = Gui.ActiveDocument.getObject(orig.Name)
    guiObj.ShowInTree = False

    bbox = shape.BoundBox
    xmin = Units.Quantity(bbox.XMin, Units.Length)
    xmax = Units.Quantity(bbox.XMax, Units.Length)
    ymin = Units.Quantity(bbox.YMin, Units.Length)
    ymax = Units.Quantity(bbox.YMax, Units.Length)
    zmin = Units.Quantity(bbox.ZMin, Units.Length)
    zmax = Units.Quantity(bbox.ZMax, Units.Length)

    # Create the "sea" box to intersect the ship
    L = xmax - xmin
    B = ymax - ymin
    H = zmax - zmin

    box = App.ActiveDocument.addObject("Part::Box", "Box")
    box.Placement = Placement(Vector(xmin - L, ymin - B, zmin - H),
                              Rotation(App.Vector(0, 0, 1), 0))
    box.Length = 3.0 * L
    box.Width = 3.0 * B
    box.Height = -zmin + H
    guiObj = Gui.ActiveDocument.getObject(box.Name)
    guiObj.ShowInTree = False

    App.ActiveDocument.recompute()
    common = App.activeDocument().addObject("Part::MultiCommon",
                                            "UnderwaterSideHelper")
    common.Shapes = [orig, box]
    guiObj = Gui.ActiveDocument.getObject(common.Name)
    guiObj.ShowInTree = False
    App.ActiveDocument.recompute()
    if force and len(common.Shape.Solids) == 0:
        # The common operation is failing, let's try moving a bit the free
        # surface
        msg = QtGui.QApplication.translate(
            "ship_console",
            "Boolean operation failed when trying to get the underwater side."
            " The tool is retrying such operation slightly moving the free"
            " surface position", None)
        App.Console.PrintWarning(msg + '\n')
        random_bounds = 0.01 * H.Value
        i = 0
        while len(common.Shape.Solids) == 0 and i < COMMON_BOOLEAN_ITERATIONS:
            i += 1
            dH = Units.Quantity(random.uniform(-random_bounds, random_bounds),
                                Units.Length)
            box.Height = -zmin + H + dH
            App.ActiveDocument.recompute()

    out = common.Shape
    App.ActiveDocument.removeObject(common.Name)
    App.ActiveDocument.removeObject(orig.Name)
    App.ActiveDocument.removeObject(box.Name)
    App.ActiveDocument.recompute()
    return out
コード例 #44
0
                    continue
            if ob.propertyDict.get(b'a2p_Version', None) != None:
                out.append(ob)
                continue
        return out

    def getSpreadsheetObjects(self):
        if not self.successfulOpened: return []
        out = []
        for ob in self.objects:
            if ob.propertyDict.get(b'cells', None) != None:
                out.append(ob)
        return out

    def getObjectByName(self, name):
        if not self.successfulOpened: return None
        for ob in self.objects:
            if ob.name == name:
                return ob
        return None


#==============================================================================

if __name__ == "__main__":
    doc = FreeCAD.activeDocument()
    fileName = doc.FileName

    dr = FCdocumentReader()
    dr.openDocument(fileName)
コード例 #45
0
def n_points_line_command():
    """ This command use the selected object(s) to try to build a
    NPointsLine feature object.
    """
    m_sel, m_act_doc = getSel(WF.verbose())

    points_from = ["Points", "Curves", "Objects"]
    try:
        number_of_vertexes, vertex_list = m_sel.get_pointsWithNames(
            get_from=points_from)

        if number_of_vertexes < 2:
            raise Exception(M_EXCEPTION_MSG)

        try:
            m_main_dir = "WorkAxis_P"
            m_sub_dir = "Set000"
            m_group = createFolders(str(m_main_dir))

            # Create a sub group if needed
            if M_SVD_FLAG:
                m_group = createSubGroup(m_act_doc, m_main_dir, m_sub_dir)

            points = []
            # Case of only 2 points
            if number_of_vertexes == 2:
                if WF.verbose():
                    print_msg("Process only 2 points")
                vertex1 = vertex_list[0]
                vertex2 = vertex_list[1]
                points.append(vertex1)
                points.append(vertex2)

                if WF.verbose():
                    print_msg("vertex1 = " + str(vertex1))
                    print_msg("vertex2 = " + str(vertex2))

                App.ActiveDocument.openTransaction(M_MACRO)
                selfobj, m_inst = makeNPointsLineFeature(m_group)
                m_inst.addSubobjects(selfobj, points)
                selfobj.VectorIndex = '1'
                selfobj.Proxy.execute(selfobj)

                if M_SVD_FLAG:
                    App.ActiveDocument.openTransaction(M_MACRO)
                    selfobj, m_inst = makeNPointsLineFeature(m_group)
                    m_inst.addSubobjects(selfobj, points)
                    selfobj.VectorIndex = '2'
                    selfobj.Proxy.execute(selfobj)

                    App.ActiveDocument.openTransaction(M_MACRO)
                    selfobj, m_inst = makeNPointsLineFeature(m_group)
                    m_inst.addSubobjects(selfobj, points)
                    selfobj.VectorIndex = '3'
                    selfobj.Proxy.execute(selfobj)
            # Case of more than 2 points
            else:
                if WF.verbose():
                    print_msg("Process more than 2 points")
                for i in range(number_of_vertexes):
                    vertex = vertex_list[i]
                    points.append(vertex)
                    if WF.verbose():
                        print_msg("vertex = " + str(vertex))

                App.ActiveDocument.openTransaction(M_MACRO)
                selfobj, m_inst = makeNPointsLineFeature(m_group)
                m_inst.addSubobjects(selfobj, points)
                selfobj.VectorIndex = '1'
                selfobj.Proxy.execute(selfobj)

                if M_SVD_FLAG:
                    App.ActiveDocument.openTransaction(M_MACRO)
                    selfobj, m_inst = makeNPointsLineFeature(m_group)
                    m_inst.addSubobjects(selfobj, points)
                    selfobj.VectorIndex = '2'
                    selfobj.Proxy.execute(selfobj)

                    App.ActiveDocument.openTransaction(M_MACRO)
                    selfobj, m_inst = makeNPointsLineFeature(m_group)
                    m_inst.addSubobjects(selfobj, points)
                    selfobj.VectorIndex = '3'
                    selfobj.Proxy.execute(selfobj)

        except Exception as err:
            printError_msg(err.args[0], title=M_MACRO)

    except Exception as err:
        printError_msgWithTimer(err.args[0], title=M_MACRO)

    App.ActiveDocument.commitTransaction()
    App.activeDocument().recompute()
コード例 #46
0
 def methodC(self, obj):
     print "my method C"
     FreeCAD.activeDocument().recompute()
コード例 #47
0
	def draw(self):
		try:
			Gui.getDocument(self.name)
			Gui.getDocument(self.name).resetEdit()
			App.getDocument(self.name).recompute()
			App.closeDocument(self.name)
			App.setActiveDocument("")
			App.ActiveDocument=None
			Gui.ActiveDocument=None	
		except:
			pass

		#make document
		App.newDocument(self.name)
		App.setActiveDocument(self.name)
		App.ActiveDocument=App.getDocument(self.name)
		Gui.ActiveDocument=Gui.getDocument(self.name)
		
		#extrude crossBarTop
		uf.extrudeFrameMember(self.name, gv.crossBarLength)

		if gv.zMotorMountLocation == "Bottom":
			return
					
		#Make Holes for zMotorMount plates
		#Sketch points
		p1x = 0
		p1y = 0
		p2x = p1x
		p2y = gv.frameWidth/2+gv.zRodZScrewDist-gv.zMotorMountPlateWidth/4
		p3x = p1x
		p3y = gv.frameWidth/2+gv.zRodZScrewDist+gv.zMotorMountPlateWidth/4
		p4x = p1x
		p4y = gv.crossBarLength - (gv.frameWidth/2+gv.zRodZScrewDist+gv.zMotorMountPlateWidth/4)
		p5x = p1x
		p5y = gv.crossBarLength - (gv.frameWidth/2+gv.zRodZScrewDist-gv.zMotorMountPlateWidth/4)
		p6x = p1x
		p6y = gv.crossBarLength
		
		#Make Sketch
		App.activeDocument().addObject('Sketcher::SketchObject','Sketch001')
		App.activeDocument().Sketch001.Support = (App.ActiveDocument.Pad,["Face2"])
		App.activeDocument().recompute()
#		Gui.activeDocument().setEdit('Sketch001')
		App.ActiveDocument.Sketch001.addExternal("Pad","Edge7")
		App.ActiveDocument.recompute()
		App.ActiveDocument.Sketch001.addGeometry(Part.Line(App.Vector(p1x,p1y,0),App.Vector(p2x,p2y,0)))
		App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Coincident',-1,1,0,1)) 
		App.ActiveDocument.recompute()
		App.ActiveDocument.recompute()
		App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Vertical',0)) 
		App.ActiveDocument.recompute()
		App.ActiveDocument.Sketch001.addGeometry(Part.Line(App.Vector(p2x,p2y,0),App.Vector(p3x,p3y,0)))
		App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Coincident',0,2,1,1)) 
		App.ActiveDocument.recompute()
		App.ActiveDocument.recompute()
		App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Vertical',1)) 
		App.ActiveDocument.recompute()
		App.ActiveDocument.Sketch001.addGeometry(Part.Line(App.Vector(p3x,p3y,0),App.Vector(p4x,p4y,0)))
		App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Coincident',1,2,2,1)) 
		App.ActiveDocument.recompute()
		App.ActiveDocument.recompute()
		App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Vertical',2)) 
		App.ActiveDocument.recompute()
		App.ActiveDocument.Sketch001.addGeometry(Part.Line(App.Vector(p4x,p4y,0),App.Vector(p5x,p5y,0)))
		App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Coincident',2,2,3,1)) 
		App.ActiveDocument.recompute()
		App.ActiveDocument.recompute()
		App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Vertical',3)) 
		App.ActiveDocument.recompute()
		App.ActiveDocument.Sketch001.addGeometry(Part.Line(App.Vector(p5x,p5y,0),App.Vector(p6x,p6y,0)))
		App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Coincident',3,2,4,1)) 
		App.ActiveDocument.recompute()
		App.ActiveDocument.recompute()
		App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('PointOnObject',4,2,-3)) 
		App.ActiveDocument.recompute()
		App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Vertical',4)) 
		App.ActiveDocument.recompute()
		App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Equal',1,3)) 
		App.ActiveDocument.recompute()
		App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Equal',4,0)) 
		App.ActiveDocument.recompute()
		App.ActiveDocument.Sketch001.toggleConstruction(0) 
		App.ActiveDocument.Sketch001.toggleConstruction(1) 
		App.ActiveDocument.Sketch001.toggleConstruction(2) 
		App.ActiveDocument.Sketch001.toggleConstruction(3) 
		App.ActiveDocument.Sketch001.toggleConstruction(4) 
		App.ActiveDocument.recompute()
		App.ActiveDocument.Sketch001.addGeometry(Part.Circle(App.Vector(p2x,p2y,0),App.Vector(0,0,1),gv.mountToFrameDia/2))
		App.ActiveDocument.recompute()
		App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Coincident',5,3,0,2)) 
		App.ActiveDocument.recompute()
		App.ActiveDocument.Sketch001.addGeometry(Part.Circle(App.Vector(p3x,p3y,0),App.Vector(0,0,1),gv.mountToFrameDia/2))
		App.ActiveDocument.recompute()
		App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Coincident',6,3,1,2)) 
		App.ActiveDocument.recompute()
		App.ActiveDocument.Sketch001.addGeometry(Part.Circle(App.Vector(p4x,p4y,0),App.Vector(0,0,1),gv.mountToFrameDia/2))
		App.ActiveDocument.recompute()
		App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Coincident',7,3,2,2)) 
		App.ActiveDocument.recompute()
		App.ActiveDocument.Sketch001.addGeometry(Part.Circle(App.Vector(p5x,p5y,0),App.Vector(0,0,1),gv.mountToFrameDia/2))
		App.ActiveDocument.recompute()
		App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Coincident',8,3,3,2)) 
		App.ActiveDocument.recompute()
		App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Equal',8,7)) 
		App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Equal',7,6)) 
		App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Equal',6,5)) 
		App.ActiveDocument.recompute()
		
		#Add Dimensions
		App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('Radius',8,gv.mountToFrameDia/2)) 
		App.ActiveDocument.recompute()
		App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('DistanceY',3,gv.zMotorMountPlateWidth/2)) 
		App.ActiveDocument.recompute()
		App.ActiveDocument.Sketch001.addConstraint(Sketcher.Constraint('DistanceY',4,p2y)) 
		App.ActiveDocument.recompute()
#		Gui.getDocument(self.name).resetEdit()
		App.getDocument(self.name).recompute()
		
		#Cut holes through All
		App.activeDocument().addObject("PartDesign::Pocket","Pocket")
		App.activeDocument().Pocket.Sketch = App.activeDocument().Sketch001
		App.activeDocument().Pocket.Length = 5.0
		App.ActiveDocument.recompute()
		Gui.activeDocument().hide("Sketch001")
		Gui.activeDocument().hide("Pad")
#		Gui.ActiveDocument.Pocket.ShapeColor=Gui.ActiveDocument.Pad.ShapeColor
#		Gui.ActiveDocument.Pocket.LineColor=Gui.ActiveDocument.Pad.LineColor
#		Gui.ActiveDocument.Pocket.PointColor=Gui.ActiveDocument.Pad.PointColor
		App.ActiveDocument.Pocket.Length = 5.000000
		App.ActiveDocument.Pocket.Type = 1
		App.ActiveDocument.Pocket.UpToFace = None
		App.ActiveDocument.recompute()
コード例 #48
0
    def Activated(self):
        try:

            s = Gui.Selection.getSelectionEx()
            if (len(s) < 1):
                # An object must be selected
                errMessage = "Select an object to use Extrude Face"
                faced.getInfo(s).errorDialog(errMessage)
                return
            lengthForward = QtGui.QInputDialog.getDouble(
                None, "Get value", "Input:", 0, -10000.0, 10000.0, 2)[0]
            if(lengthForward == 0):
                return  # nothing to do here

            objName = s[0].ObjectName
            sh = s[0].Object.Shape.copy()
            if hasattr(s[0].Object, "getGlobalPlacement"):
                gpl = s[0].Object.getGlobalPlacement()
                sh.Placement = gpl
            name = s[0].SubElementNames[0]
            fullname = objName+"_"+name  # Name of the face extracted
            newobj = s[0].Document.addObject("Part::Feature", fullname)
            newobj.Shape = sh.getElement(name)
            selection = newobj  # The face extraced
            activeSel = Gui.Selection.getSelection(App.ActiveDocument.Name)
            Gui.Selection.removeSelection(activeSel[0])
            # Select the face extracted before
            Gui.Selection.addSelection(selection)
            App.ActiveDocument.recompute()
            m = App.activeDocument().getObject(fullname)
            f = App.activeDocument().addObject(
                'Part::Extrusion', 'ExtrudeFace')	  # Add extrusion
            f.Base = newobj				# App.activeDocument().getObject(fullname)
            f.DirMode = "Normal"
            f.DirLink = None
            f.LengthFwd = lengthForward
            f.LengthRev = 0.0
            f.Solid = True
            f.Reversed = False
            f.Symmetric = False
            f.TaperAngle = 0.0
            f.TaperAngleRev = 0.0
            App.ActiveDocument.recompute()
            newPart_ = App.ActiveDocument.addObject(
                'Part::Feature', f.Name+'N')
            newPart_.Shape = Part.getShape(
                f, '', needSubElement=False, refine=False)
            if newPart_.isValid() == False:
                App.ActiveDocument.removeObject(newPart_.Name)
                App.ActiveDocument.removeObject(f.Name)
                # Shape is not OK
                errMessage = "Failed to extrude the Face"
                faced.getInfo(m).errorDialog(errMessage)
            else:
                # remove old objects
                App.ActiveDocument.removeObject(f.Name)
                App.ActiveDocument.removeObject(m.Name)
                # This will not work for split objects as they are not two separate objects.2021-02-22
                # Make the two objects merged
                obj1 = App.ActiveDocument.getObject(s[0].ObjectName)
                obj2 = newPart_
                selections = Gui.Selection.getSelectionEx()
                for i in selections:
                    Gui.Selection.removeSelection(selections)
                    Gui.Selection.addSelection(obj1)
                    Gui.Selection.addSelection(obj2)
                    Gui.runCommand('Design456_Part_Merge', 0)
            App.ActiveDocument.recompute()

            return
        except Exception as err:
            App.Console.PrintError("'ExtrudeFace' Failed. "
                                   "{err}\n".format(err=str(err)))
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            print(exc_type, fname, exc_tb.tb_lineno)
コード例 #49
0
def TestElbow():
    document = FreeCAD.activeDocument()
    elbow = Elbow(document)
    elbow.create(False)
    document.recompute()
コード例 #50
0
ファイル: CPipe.py プロジェクト: EdgarJRobles/dodo
 def Activated(self):
     import pCmd
     FreeCAD.activeDocument().openTransaction('Attach to tube')
     pCmd.attachToTube()
     FreeCAD.activeDocument().recompute()
     FreeCAD.activeDocument().commitTransaction()
コード例 #51
0
def makeBentShapeRebar(
    f_cover,
    b_cover,
    l_cover,
    r_cover,
    diameter,
    t_cover,
    bentLength,
    bentAngle,
    rounding,
    amount_spacing_check,
    amount_spacing_value,
    orientation="Bottom",
    structure=None,
    facename=None,
):
    """makeBentShapeRebar(FrontCover, BottomCover, LeftCover, RightCover,
    Diameter, TopCover, BentLength, BentAngle, Rounding, AmountSpacingCheck,
    AmountSpacingValue, Orientation, Structure, Facename):
    Adds the Bent-Shape reinforcement bar to the selected structural object.

    It takes four different orientations input i.e. 'Bottom', 'Top', 'Left',
    'Right'.
    """
    if not structure and not facename:
        selected_obj = FreeCADGui.Selection.getSelectionEx()[0]
        structure = selected_obj.Object
        facename = selected_obj.SubElementNames[0]
    face = structure.Shape.Faces[getFaceNumber(facename) - 1]
    # StructurePRM = getTrueParametersOfStructure(structure)
    FacePRM = getParametersOfFace(structure, facename)
    if not FacePRM:
        FreeCAD.Console.PrintError(
            "Cannot identify shape or from which base object structural "
            "element is derived\n")
        return
    # Get points of L-Shape rebar
    points = getpointsOfBentShapeRebar(
        FacePRM,
        l_cover,
        r_cover,
        b_cover,
        t_cover,
        bentLength,
        bentAngle,
        orientation,
        diameter,
        facenormalDirection(structure, facename),
    )
    import Part
    import Arch

    sketch = FreeCAD.activeDocument().addObject("Sketcher::SketchObject",
                                                "Sketch")
    sketch.MapMode = "FlatFace"
    sketch.Support = [(structure, facename)]
    FreeCAD.ActiveDocument.recompute()
    sketch.addGeometry(Part.LineSegment(points[0], points[1]), False)
    sketch.addGeometry(Part.LineSegment(points[1], points[2]), False)
    sketch.addGeometry(Part.LineSegment(points[2], points[3]), False)
    sketch.addGeometry(Part.LineSegment(points[3], points[4]), False)
    sketch.addGeometry(Part.LineSegment(points[4], points[5]), False)

    if amount_spacing_check:
        rebar = Arch.makeRebar(
            structure,
            sketch,
            diameter,
            amount_spacing_value,
            f_cover + diameter / 2,
            name="BentShapeRebar",
        )
        FreeCAD.ActiveDocument.recompute()
    else:
        size = (ArchCommands.projectToVector(structure.Shape.copy(),
                                             face.normalAt(0, 0))).Length
        rebar = Arch.makeRebar(
            structure,
            sketch,
            diameter,
            get_rebar_amount_from_spacing(size, diameter,
                                          amount_spacing_value),
            f_cover + diameter / 2,
            name="BentShapeRebar",
        )
    rebar.Rounding = rounding
    # Adds properties to the rebar object
    rebar.addProperty(
        "App::PropertyEnumeration",
        "RebarShape",
        "RebarDialog",
        QT_TRANSLATE_NOOP("App::Property", "Shape of rebar"),
    ).RebarShape = RebarTypes.tolist()
    rebar.RebarShape = "BentShapeRebar"
    rebar.setEditorMode("RebarShape", 2)
    rebar.addProperty(
        "App::PropertyDistance",
        "FrontCover",
        "RebarDialog",
        QT_TRANSLATE_NOOP("App::Property", "Front cover of rebar"),
    ).FrontCover = f_cover
    rebar.setEditorMode("FrontCover", 2)
    rebar.addProperty(
        "App::PropertyDistance",
        "LeftCover",
        "RebarDialog",
        QT_TRANSLATE_NOOP("App::Property", "Left Side cover of rebar"),
    ).LeftCover = l_cover
    rebar.setEditorMode("LeftCover", 2)
    rebar.addProperty(
        "App::PropertyDistance",
        "RightCover",
        "RebarDialog",
        QT_TRANSLATE_NOOP("App::Property", "Right Side cover of rebar"),
    ).RightCover = r_cover
    rebar.setEditorMode("RightCover", 2)
    rebar.addProperty(
        "App::PropertyDistance",
        "BottomCover",
        "RebarDialog",
        QT_TRANSLATE_NOOP("App::Property", "Bottom cover of rebar"),
    ).BottomCover = b_cover
    rebar.setEditorMode("BottomCover", 2)
    rebar.addProperty(
        "App::PropertyBool",
        "AmountCheck",
        "RebarDialog",
        QT_TRANSLATE_NOOP("App::Property", "Amount radio button is checked"),
    )
    rebar.setEditorMode("AmountCheck", 2)
    rebar.addProperty(
        "App::PropertyDistance",
        "TopCover",
        "RebarDialog",
        QT_TRANSLATE_NOOP("App::Property", "Top cover of rebar"),
    ).TopCover = t_cover
    rebar.setEditorMode("TopCover", 2)
    rebar.addProperty(
        "App::PropertyDistance",
        "TrueSpacing",
        "RebarDialog",
        QT_TRANSLATE_NOOP("App::Property", "Spacing between of rebars"),
    ).TrueSpacing = amount_spacing_value
    rebar.addProperty(
        "App::PropertyString",
        "Orientation",
        "RebarDialog",
        QT_TRANSLATE_NOOP("App::Property", "Shape of rebar"),
    ).Orientation = orientation
    rebar.setEditorMode("Orientation", 2)
    rebar.setEditorMode("TrueSpacing", 2)
    rebar.addProperty(
        "App::PropertyDistance",
        "BentLength",
        "RebarDialog",
        QT_TRANSLATE_NOOP("App::Property", "BentLength cover of rebar"),
    ).BentLength = bentLength
    rebar.setEditorMode("BentLength", 2)
    rebar.addProperty(
        "App::PropertyDistance",
        "BentAngle",
        "RebarDialog",
        QT_TRANSLATE_NOOP("App::Property", "Bent Angle of rebar"),
    ).BentAngle = bentAngle
    rebar.setEditorMode("BentAngle", 2)

    if amount_spacing_check:
        rebar.AmountCheck = True
    else:
        rebar.AmountCheck = False
        rebar.TrueSpacing = amount_spacing_value
    FreeCAD.ActiveDocument.recompute()
    return rebar
コード例 #52
0
ファイル: CPipe.py プロジェクト: EdgarJRobles/dodo
 def Activated(self):
     import pCmd
     FreeCAD.activeDocument().openTransaction('Mate')
     pCmd.alignTheTube()
     FreeCAD.activeDocument().commitTransaction()
     FreeCAD.activeDocument().recompute()
コード例 #53
0
    def draw(self):
        #helper Variables

        #determine total width of motor mount plate
        xMotorMountWidth = gv.xMotorBodyWidth + gv.motorToXRodClampSpacing + gv.xRodClampWidth

        xRodClampMountHoleSpacingVert = gv.xRodSpacing - 2 * gv.xRodAxisToMountHoleDist
        xRodClampMountHoleSpacingHoriz = gv.xRodClampWidth - 2 * gv.xRodClampEdgeToMountHoleDist

        #safety check
        #xRodSpacing must be wide enough for the motor to be mounted between the rods

        #Create Document
        try:
            App.getDocument('xEndMotorPlate').recompute()
            App.closeDocument("xEndMotorPlate")
            App.setActiveDocument("")
            App.ActiveDocument = None
        except:
            pass

        App.newDocument("xEndMotorPlate")
        App.setActiveDocument("xEndMotorPlate")
        App.ActiveDocument = App.getDocument("xEndMotorPlate")

        #Make the plate
        #Sketch points
        p1x = 0
        p1y = 0
        p2x = 0
        p2y = gv.xMotorMountPlateWidth
        p3x = xMotorMountWidth
        p3y = gv.xMotorMountPlateWidth
        p4x = xMotorMountWidth
        p4y = 0

        #Make Sketch
        App.activeDocument().addObject('Sketcher::SketchObject', 'Sketch')
        App.activeDocument().Sketch.Placement = App.Placement(
            App.Vector(0.000000, 0.000000, 0.000000),
            App.Rotation(0.000000, 0.000000, 0.000000, 1.000000))
        App.ActiveDocument.Sketch.addGeometry(
            Part.Line(App.Vector(p1x, p1y, 0), App.Vector(p2x, p2y, 0)))
        App.ActiveDocument.Sketch.addGeometry(
            Part.Line(App.Vector(p2x, p2y, 0), App.Vector(p3x, p3y, 0)))
        App.ActiveDocument.Sketch.addGeometry(
            Part.Line(App.Vector(p3x, p3y, 0), App.Vector(p4x, p4y, 0)))
        App.ActiveDocument.Sketch.addGeometry(
            Part.Line(App.Vector(p4x, p4y, 0), App.Vector(p1x, p1y, 0)))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 0, 2, 1, 1))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 1, 2, 2, 1))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 2, 2, 3, 1))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 3, 2, 0, 1))
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Vertical', 0))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Vertical', 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Horizontal', 3))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Horizontal', 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('Coincident', 0, 1, -1, 1))
        App.ActiveDocument.recompute()

        #Add dimensions
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('DistanceX', 3, -xMotorMountWidth))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch.addConstraint(
            Sketcher.Constraint('DistanceY', 2, -gv.xMotorMountPlateWidth))
        App.ActiveDocument.recompute()

        App.getDocument('xEndMotorPlate').recompute()

        #extrude x motor mount plate
        App.activeDocument().addObject("PartDesign::Pad", "Pad")
        App.activeDocument().Pad.Sketch = App.activeDocument().Sketch
        App.activeDocument().Pad.Length = 10.0
        App.ActiveDocument.recompute()
        App.ActiveDocument.Pad.Length = gv.xMotorMountPlateThickness
        App.ActiveDocument.Pad.Reversed = 0
        App.ActiveDocument.Pad.Midplane = 0
        App.ActiveDocument.Pad.Length2 = 100.000000
        App.ActiveDocument.Pad.Type = 0
        App.ActiveDocument.Pad.UpToFace = None
        App.ActiveDocument.recompute()

        #cut holes for xRodClamp
        #Sketch Points
        p1x = 0
        p1y = gv.xMotorMountPlateWidth / 2
        p2x = xMotorMountWidth
        p2y = gv.xMotorMountPlateWidth / 2
        p3x = gv.xMotorBodyWidth + gv.motorToXRodClampSpacing + gv.xRodClampEdgeToMountHoleDist
        p3y = gv.xRodAxisToMountHoleDist
        p4x = gv.xMotorBodyWidth + gv.motorToXRodClampSpacing + gv.xRodClampEdgeToMountHoleDist
        p4y = gv.xMotorMountPlateWidth - gv.xRodAxisToMountHoleDist
        p5x = xMotorMountWidth - gv.xRodClampEdgeToMountHoleDist
        p5y = gv.xMotorMountPlateWidth - gv.xRodAxisToMountHoleDist
        p6x = xMotorMountWidth - gv.xRodClampEdgeToMountHoleDist
        p6y = gv.xRodAxisToMountHoleDist
        p7x = gv.xMotorBodyWidth + gv.motorToXRodClampSpacing + gv.xRodClampEdgeToMountHoleDist
        p7y = gv.xMotorMountPlateWidth / 2
        p8x = gv.xMotorBodyWidth + gv.motorToXRodClampSpacing + gv.xRodClampWidth / 2
        p8y = gv.xMotorMountPlateWidth / 2

        #Make sketch
        App.activeDocument().addObject('Sketcher::SketchObject', 'Sketch001')
        App.activeDocument().Sketch001.Support = uf.getFace(
            App.ActiveDocument.Pad, None, None, None, None,
            gv.xMotorMountPlateThickness,
            0)  #(App.ActiveDocument.Pad,["Face6"])
        App.activeDocument().recompute()

        App.ActiveDocument.Sketch001.addExternal(
            "Pad",
            uf.getEdge(App.ActiveDocument.Pad, 0, 0,
                       gv.xMotorMountPlateWidth / 2, 0,
                       gv.xMotorMountPlateThickness, 0))
        App.ActiveDocument.Sketch001.addExternal(
            "Pad",
            uf.getEdge(App.ActiveDocument.Pad, xMotorMountWidth, 0,
                       gv.xMotorMountPlateWidth / 2, 0,
                       gv.xMotorMountPlateThickness, 0))
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Line(App.Vector(p1x, p1y, 0), App.Vector(p2x, p2y, 0)))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('PointOnObject', 0, 1, -3))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('PointOnObject', 0, 2, -4))
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Line(App.Vector(p3x, p3y, 0), App.Vector(p4x, p4y, 0)))
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Line(App.Vector(p4x, p4y, 0), App.Vector(p5x, p5y, 0)))
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Line(App.Vector(p5x, p5y, 0), App.Vector(p6x, p6y, 0)))
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Line(App.Vector(p6x, p6y, 0), App.Vector(p3x, p3y, 0)))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 1, 2, 2, 1))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 2, 2, 3, 1))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 3, 2, 4, 1))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 4, 2, 1, 1))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Horizontal', 2))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Horizontal', 4))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Vertical', 1))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Vertical', 3))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.toggleConstruction(0)
        App.ActiveDocument.Sketch001.toggleConstruction(4)
        App.ActiveDocument.Sketch001.toggleConstruction(3)
        App.ActiveDocument.Sketch001.toggleConstruction(2)
        App.ActiveDocument.Sketch001.toggleConstruction(1)
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Point(App.Vector(p7x, p7y, 0)))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('PointOnObject', 5, 1, 1))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('PointOnObject', 5, 1, 0))

        App.ActiveDocument.Sketch001.addGeometry(
            Part.Circle(App.Vector(p3x, p3y, 0), App.Vector(0, 0, 1),
                        gv.mountToPrintedDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 1, 1, 6, 3))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Circle(App.Vector(p4x, p4y, 0), App.Vector(0, 0, 1),
                        gv.mountToPrintedDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 7, 3, 1, 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Circle(App.Vector(p5x, p5y, 0), App.Vector(0, 0, 1),
                        gv.mountToPrintedDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 2, 2, 8, 3))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addGeometry(
            Part.Circle(App.Vector(p6x, p6y, 0), App.Vector(0, 0, 1),
                        gv.mountToPrintedDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Coincident', 9, 3, 3, 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Equal', 6, 7))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Equal', 7, 8))
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Equal', 8, 9))
        App.ActiveDocument.recompute()

        App.ActiveDocument.Sketch001.addGeometry(
            Part.Circle(App.Vector(p8x, p8y, 0), App.Vector(0, 0, 1),
                        gv.xEndIdlerHoleDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('PointOnObject', 10, 3, 0))
        App.ActiveDocument.recompute()

        #add dimensions
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('DistanceX', 4,
                                -xRodClampMountHoleSpacingHoriz))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Distance', 3, 2, -4,
                                gv.xRodClampEdgeToMountHoleDist))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('DistanceY', 3,
                                -xRodClampMountHoleSpacingVert))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Radius', 8, gv.mountToPrintedDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Radius', 10, gv.xEndIdlerHoleDia / 2))
        App.ActiveDocument.recompute()

        #add Symmetric constraints
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Symmetric', 1, 1, 1, 2, 5, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Symmetric', 1, 1, 2, 2, 10, 3))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch001.addConstraint(
            Sketcher.Constraint('Symmetric', -1, 1, -3, 2, 0, 1))
        App.ActiveDocument.recompute()

        #exit sketch
        App.getDocument('xEndMotorPlate').recompute()

        #Cut holes through all
        App.activeDocument().addObject("PartDesign::Pocket", "Pocket")
        App.activeDocument().Pocket.Sketch = App.activeDocument().Sketch001
        App.activeDocument().Pocket.Length = 5.0
        App.ActiveDocument.recompute()
        App.ActiveDocument.Pocket.Length = 5.000000
        App.ActiveDocument.Pocket.Type = 1
        App.ActiveDocument.Pocket.UpToFace = None
        App.ActiveDocument.recompute()

        #Cut holes for motor
        #Sketch Points
        p1x = 0
        p1y = gv.xMotorMountPlateWidth / 2
        p2x = xMotorMountWidth
        p2y = gv.xMotorMountPlateWidth / 2
        p3x = gv.xEndMotorMountHoleDia / 2 + gv.xEndMotorMountHolePadding
        p3y = gv.xMotorMountPlateWidth / 2 - gv.xMotorShaftToMountHoleDistX
        p4x = gv.xEndMotorMountHoleDia / 2 + gv.xEndMotorMountHolePadding
        p4y = gv.xMotorMountPlateWidth / 2 + gv.xMotorShaftToMountHoleDistX
        p5x = gv.xEndMotorMountHoleDia / 2 + gv.xEndMotorMountHolePadding + 2 * gv.xMotorShaftToMountHoleDistX
        p5y = gv.xMotorMountPlateWidth / 2 + gv.xMotorShaftToMountHoleDistX
        p6x = gv.xEndMotorMountHoleDia / 2 + gv.xEndMotorMountHolePadding + 2 * gv.xMotorShaftToMountHoleDistX
        p6y = gv.xMotorMountPlateWidth / 2 - gv.xMotorShaftToMountHoleDistX
        p7x = gv.xEndMotorMountHoleDia / 2 + gv.xEndMotorMountHolePadding
        p7y = gv.xMotorMountPlateWidth / 2
        p8x = gv.xMotorBodyWidth / 2
        p8y = gv.xMotorMountPlateWidth / 2

        #Make Sketch
        App.activeDocument().addObject('Sketcher::SketchObject', 'Sketch002')
        App.activeDocument().Sketch002.Support = uf.getFace(
            App.ActiveDocument.Pocket, None, None, None, None,
            gv.xMotorMountPlateThickness,
            0)  #(App.ActiveDocument.Pocket,["Face5"])
        App.activeDocument().recompute()

        App.ActiveDocument.Sketch002.addExternal(
            "Pocket",
            uf.getEdge(App.ActiveDocument.Pocket, 0, 0,
                       gv.xMotorMountPlateWidth / 2, 0,
                       gv.xMotorMountPlateThickness, 0))
        App.ActiveDocument.Sketch002.addExternal(
            "Pocket",
            uf.getEdge(App.ActiveDocument.Pocket, xMotorMountWidth, 0,
                       gv.xMotorMountPlateWidth / 2, 0,
                       gv.xMotorMountPlateThickness, 0))

        App.ActiveDocument.Sketch002.addGeometry(
            Part.Line(App.Vector(p1x, p1y, 0), App.Vector(p2x, p2y, 0)))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('PointOnObject', 0, 2, -4))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Symmetric', -1, 1, -3, 2, 0, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Horizontal', 0))
        App.ActiveDocument.recompute()

        App.ActiveDocument.Sketch002.addGeometry(
            Part.Line(App.Vector(p3x, p3y, 0), App.Vector(p4x, p4y, 0)))
        App.ActiveDocument.Sketch002.addGeometry(
            Part.Line(App.Vector(p4x, p4y, 0), App.Vector(p5x, p5y, 0)))
        App.ActiveDocument.Sketch002.addGeometry(
            Part.Line(App.Vector(p5x, p5y, 0), App.Vector(p6x, p6y, 0)))
        App.ActiveDocument.Sketch002.addGeometry(
            Part.Line(App.Vector(p6x, p6y, 0), App.Vector(p3x, p3y, 0)))

        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Coincident', 1, 2, 2, 1))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Coincident', 2, 2, 3, 1))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Coincident', 3, 2, 4, 1))
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Coincident', 4, 2, 1, 1))

        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Horizontal', 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Horizontal', 4))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Vertical', 3))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Vertical', 1))
        App.ActiveDocument.recompute()

        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Equal', 3, 4))
        App.ActiveDocument.recompute()
        App.ActiveDocument.recompute()

        App.ActiveDocument.Sketch002.toggleConstruction(0)
        App.ActiveDocument.Sketch002.toggleConstruction(2)
        App.ActiveDocument.Sketch002.toggleConstruction(3)
        App.ActiveDocument.Sketch002.toggleConstruction(4)
        App.ActiveDocument.Sketch002.toggleConstruction(1)
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addGeometry(
            Part.Point(App.Vector(p7x, p7y, 0)))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('PointOnObject', 5, 1, 0))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('PointOnObject', 5, 1, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint(
                'Distance', 1, 1, -3,
                gv.xEndMotorMountHoleDia / 2 + gv.xEndMotorMountHolePadding))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('DistanceX', 4,
                                -2 * gv.xMotorShaftToMountHoleDistX))
        App.ActiveDocument.Sketch002.addGeometry(
            Part.Circle(App.Vector(p3x, p3y, 0), App.Vector(0, 0, 1),
                        gv.xEndMotorMountHoleDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Coincident', 6, 3, 1, 1))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addGeometry(
            Part.Circle(App.Vector(p5x, p5y, 0), App.Vector(0, 0, 1),
                        gv.xEndMotorMountHoleDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Coincident', 7, 3, 2, 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addGeometry(
            Part.Circle(App.Vector(p8x, p8y, 0), App.Vector(0, 0, 1),
                        gv.xMotorPulleyDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('PointOnObject', 8, 3, 0))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Equal', 6, 7))
        App.ActiveDocument.recompute()

        #Add dimensions to holes
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Radius', 6, gv.xEndMotorMountHoleDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Radius', 8, gv.xMotorPulleyDia / 2))
        App.ActiveDocument.recompute()
        App.ActiveDocument.Sketch002.addConstraint(
            Sketcher.Constraint('Symmetric', 1, 1, 2, 2, 8, 3))
        App.ActiveDocument.recompute()

        #Cut 2 more holes if there are 4 motor mount holes
        if gv.xEndNumMountHoles == 4:
            App.ActiveDocument.Sketch002.addGeometry(
                Part.Circle(App.Vector(p4x, p4y, 0), App.Vector(0, 0, 1),
                            gv.xEndMotorMountHoleDia / 2))
            App.ActiveDocument.recompute()
            App.ActiveDocument.Sketch002.addConstraint(
                Sketcher.Constraint('Coincident', 9, 3, 1, 2))
            App.ActiveDocument.recompute()
            App.ActiveDocument.Sketch002.addGeometry(
                Part.Circle(App.Vector(p6x, p6y, 0), App.Vector(0, 0, 1),
                            gv.xEndMotorMountHoleDia / 2))
            App.ActiveDocument.recompute()
            App.ActiveDocument.Sketch002.addConstraint(
                Sketcher.Constraint('Coincident', 10, 3, 3, 2))
            App.ActiveDocument.recompute()
            App.ActiveDocument.Sketch002.addConstraint(
                Sketcher.Constraint('Equal', 10, 9))
            App.ActiveDocument.recompute()
            App.ActiveDocument.Sketch002.addConstraint(
                Sketcher.Constraint('Equal', 10, 7))

        #exit Sketch
        App.getDocument('xEndMotorPlate').recompute()

        #Cut holes
        App.activeDocument().addObject("PartDesign::Pocket", "Pocket001")
        App.activeDocument().Pocket001.Sketch = App.activeDocument().Sketch002
        App.activeDocument().Pocket001.Length = 5.0
        App.ActiveDocument.recompute()
        App.ActiveDocument.Pocket001.Length = 5.000000
        App.ActiveDocument.Pocket001.Type = 1
        App.ActiveDocument.Pocket001.UpToFace = None
        App.ActiveDocument.recompute()
コード例 #54
0
ファイル: CPipe.py プロジェクト: EdgarJRobles/dodo
 def Activated(self):
     import pCmd
     FreeCAD.activeDocument().openTransaction('Xtend1int')
     pCmd.extendTheTubes2intersection(both=False)
     FreeCAD.activeDocument().recompute()
     FreeCAD.activeDocument().commitTransaction()
コード例 #55
0
import os
import sys
sys.path.append(os.path.dirname(__file__))

from SectionList import *
from Case import *

if __name__ == '__main__':
    if not App.listDocuments().has_key("BananaPiM64Model"):
        App.open(
            "/home/heller/BananaPi_M64_Portable/3DModel/BananaPiM64Model.fcstd"
        )
    App.setActiveDocument("BananaPiM64Model")
    App.ActiveDocument = App.getDocument("BananaPiM64Model")
    doc = App.activeDocument()
    garbage = doc.findObjects('Drawing::FeatureViewPart')
    for g in garbage:
        doc.removeObject(g.Name)
    garbage = doc.findObjects('Drawing::FeaturePage')
    for g in garbage:
        doc.removeObject(g.Name)
    #############
    ##
    ## Top Block: hinge
    ##
    doc.addObject('Drawing::FeaturePage', 'TopBackBlockDrillSheetPage')
    doc.TopBackBlockDrillSheetPage.Template = "/home/heller/BananaPi_M64_Portable/3DModel/Letter_Portrait_ISO7200.svg"
    edt = doc.TopBackBlockDrillSheetPage.EditableTexts
    edt[0] = unicode("Robert Heller")
    edt[1] = unicode("Top Block Drill Sheet (back block hinge holes)")
コード例 #56
0
FreeCAD.ActiveDocument.ActiveObject.Solid = True
FreeCAD.ActiveDocument.ActiveObject.Ruled = False
FreeCAD.ActiveDocument.ActiveObject.Closed = False
FreeCAD.ActiveDocument.recompute()

FreeCAD.ActiveDocument.addObject('Part::Loft', 'OUTER_WING_2_L')
FreeCAD.ActiveDocument.ActiveObject.Sections = [
    FreeCAD.ActiveDocument.BSpline007, FreeCAD.ActiveDocument.BSpline008
]
FreeCAD.ActiveDocument.ActiveObject.Solid = True
FreeCAD.ActiveDocument.ActiveObject.Ruled = False
FreeCAD.ActiveDocument.ActiveObject.Closed = False
FreeCAD.ActiveDocument.recompute()

#centrebody fusion
FreeCAD.activeDocument().addObject("Part::MultiFuse", "CENTREBODY_FUSION_L")
FreeCAD.activeDocument().CENTREBODY_FUSION_L.Shapes = [
    FreeCAD.activeDocument().CENTREBODY_2_L,
    FreeCAD.activeDocument().CENTREBODY_1_L
]
FreeCAD.ActiveDocument.recompute()

##LEFT OUTER WING FUSION
#FreeCAD.activeDocument().addObject("Part::MultiFuse","LEFT_OUTER_WING_FUSION")
#FreeCAD.activeDocument().LEFT_OUTER_WING_FUSION.Shapes = [FreeCAD.activeDocument().LEFT_WINGLET,FreeCAD.activeDocument().OUTER_WING_2_L,FreeCAD.activeDocument().OUTER_WING_1_L]
#FreeCAD.ActiveDocument.recompute()
#
##LEFT WING + CENTREBODY FUSION
#FreeCAD.activeDocument().addObject("Part::MultiFuse","LEFT_WING_FUSION")
#FreeCAD.activeDocument().LEFT_WING_FUSION.Shapes = [FreeCAD.activeDocument().LEFT_OUTER_WING_FUSION,FreeCAD.activeDocument().CENTREBODY_FUSION_L]
#FreeCAD.ActiveDocument.recompute()
コード例 #57
0
 def methodA(self, obj):
     print "my Method A"
     FreeCAD.activeDocument().recompute()
コード例 #58
0
def export_one_part(modul, variant, with_plug=False):
    if not variant in modul.all_params:
        FreeCAD.Console.PrintMessage("Parameters for %s doesn't exist in 'M.all_params', skipping." % variant)
        return

    destination_dir="Connectors_Phoenix.3dshapes"
    if with_plug:
        destination_dir="Connectors_Phoenix__with_plug.3dshapes"
    ModelName = variant
    ModelName = ModelName.replace(".","_")
    FileName = modul.all_params[variant].file_name
    Newdoc = FreeCAD.newDocument(ModelName)
    App.setActiveDocument(ModelName)
    App.ActiveDocument=App.getDocument(ModelName)
    Gui.ActiveDocument=Gui.getDocument(ModelName)
    #App.setActiveDocument(ModelName)
    #Gui.ActiveDocument=Gui.getDocument(ModelName)
    (pins, body, insert, mount_screw, plug, plug_screws) = modul.generate_part(variant, with_plug)

    color_attr = body_color + (0,)
    show(body, color_attr)

    color_attr = pins_color + (0,)
    show(pins, color_attr)

    if insert is not None:
        color_attr = insert_color + (0,)
        show(insert, color_attr)
    if mount_screw is not None:
        color_attr = screw_color + (0,)
        show(mount_screw, color_attr)
    if plug is not None:
        color_attr = body_color + (0,)
        show(plug, color_attr)

        color_attr = screw_color + (0,)
        show(plug_screws, color_attr)

    doc = FreeCAD.ActiveDocument
    doc.Label=ModelName
    objs=FreeCAD.ActiveDocument.Objects
    FreeCAD.Console.PrintMessage(objs)

    i=0
    objs[i].Label = ModelName + "__body"
    i+=1
    objs[i].Label = ModelName + "__pins"
    i+=1
    if insert is not None:
        objs[i].Label = ModelName + "__thread_insert"
        i+=1
    if mount_screw is not None:
        objs[i].Label = ModelName + "__mount_screw"
        i+=1
    if plug is not None:
        objs[i].Label = ModelName + "__plug"
        i+=1
        objs[i].Label = ModelName + "__plug_screws"
    restore_Main_Tools()

    out_dir=destination_dir
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    used_color_keys = [body_color_key, pins_color_key]
    export_file_name=destination_dir+os.sep+FileName+'.wrl'

    export_objects = []
    i=0
    export_objects.append(expVRML.exportObject(freecad_object = objs[i],
            shape_color=body_color_key,
            face_colors=None))
    i+=1
    export_objects.append(expVRML.exportObject(freecad_object = objs[i],
            shape_color=pins_color_key,
            face_colors=None))
    i+=1
    if insert is not None:
        export_objects.append(expVRML.exportObject(freecad_object = objs[i],
                shape_color=insert_color_key,
                face_colors=None))
        used_color_keys.append(insert_color_key)
        i+=1
    if mount_screw is not None:
        export_objects.append(expVRML.exportObject(freecad_object = objs[i],
                shape_color=screw_color_key,
                face_colors=None))
        used_color_keys.append(screw_color_key)
        i+=1
    if plug is not None:
        export_objects.append(expVRML.exportObject(freecad_object = objs[i],
                shape_color=body_color_key,
                face_colors=None))
        i+=1
        export_objects.append(expVRML.exportObject(freecad_object = objs[i],
                shape_color=screw_color_key,
                face_colors=None))
    scale=1/2.54
    colored_meshes = expVRML.getColoredMesh(Gui, export_objects , scale)
    expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license)

    fusion = multiFuseObjs_wColors(FreeCAD, FreeCADGui,
                     ModelName, objs, keepOriginals=True)

    exportSTEP(doc,FileName,out_dir,fusion)
    L.addLicenseToStep(out_dir+'/', FileName+".step", LIST_license,\
        STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licPreProc)

    saveFCdoc(App, Gui, doc, FileName,out_dir)

    FreeCAD.activeDocument().recompute()
    # FreeCADGui.activateWorkbench("PartWorkbench")
    FreeCADGui.SendMsgToActiveView("ViewFit")
    FreeCADGui.activeDocument().activeView().viewAxometric()
コード例 #59
0
def get_bbox(obj, debug=False):
    """Return a BoundBox from any object that has a Coin RootNode.

    Normally the bounding box of an object can be taken
    from its `Part::TopoShape`.
    ::
        >>> print(obj.Shape.BoundBox)

    However, for objects without a `Shape`, such as those
    derived from `App::FeaturePython` like `Draft Text` and `Draft Dimension`,
    the bounding box can be calculated from the `RootNode` of the viewprovider.

    Parameters
    ----------
    obj: App::DocumentObject
        Any object that has a `ViewObject.RootNode`.

    Returns
    -------
    Base::BoundBox
        It returns a `BoundBox` object which has information like
        minimum and maximum values of X, Y, and Z, as well as bounding box
        center.

    None
        If there is a problem it will return `None`.
    """
    _name = "get_bbox"
    utils.print_header(_name, "Bounding box", debug=debug)

    found, doc = utils.find_doc(App.activeDocument())
    if not found:
        _err(_tr("No active document. Aborting."))
        return None

    if isinstance(obj, str):
        obj_str = obj

    found, obj = utils.find_object(obj, doc)
    if not found:
        _msg("obj: {}".format(obj_str))
        _err(_tr("Wrong input: object not in document."))
        return None

    if debug:
        _msg("obj: {}".format(obj.Label))

    if (not hasattr(obj, "ViewObject") or not obj.ViewObject
            or not hasattr(obj.ViewObject, "RootNode")):
        _err(_tr("Does not have 'ViewObject.RootNode'."))

    # For Draft Dimensions
    # node = obj.ViewObject.Proxy.node
    node = obj.ViewObject.RootNode

    view = Gui.ActiveDocument.ActiveView
    region = view.getViewer().getSoRenderManager().getViewportRegion()
    action = coin.SoGetBoundingBoxAction(region)

    node.getBoundingBox(action)
    bb = action.getBoundingBox()

    # xlength, ylength, zlength = bb.getSize().getValue()
    xmin, ymin, zmin = bb.getMin().getValue()
    xmax, ymax, zmax = bb.getMax().getValue()

    return App.BoundBox(xmin, ymin, zmin, xmax, ymax, zmax)
コード例 #60
0
ファイル: Tee.py プロジェクト: rkrenzler/ose-piping-workbench
def TestTee():
    document = FreeCAD.activeDocument()
    tee = Tee(document)
    tee.create(False)
    document.recompute()