本文整理汇总了Python中ImportGui类的典型用法代码示例。如果您正苦于以下问题:Python ImportGui类的具体用法?Python ImportGui怎么用?Python ImportGui使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ImportGui类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ImportElement
def ImportElement():
doc=FreeCAD.ActiveDocument;
FreeCAD.Console.PrintMessage("Try to import...\n");
(fname1,fdir1) = QtGui.QFileDialog.getOpenFileName(None,'Open file','');
ImportGui.insert(fname1,doc.Name);
doc.recompute();
ob1=doc.Objects[-1];
# create groupe and add element to it
if (hasattr(doc,'OpticalSystem')==False):
gr1=doc.addObject("App::DocumentObjectGroup","OpticalSystem");
gr1.newObject("App::DocumentObjectGroup","Rays");
gr1_e=gr1.newObject("App::DocumentObjectGroup","Elements");
gr1_e.addObject(ob1);
else:
gr1_e=getattr(doc,'Elements');
gr1_e.addObject(ob1);
# end if
ob1.Label="IMPR";
ob1.ViewObject.ShapeColor=(0.5,0.5,0.5);
ob1.ViewObject.Transparency=80;
An=ob1.Placement.Rotation.toEuler();
P1=ob1.Placement.Base;
l1=["","Imported",ob1.Name,ob1.Label, \
P1.x,P1.y,P1.z, \
An[2],An[1],An[0],None,None,None,1.,1.52,None,None];
# add lens to list of optical system elements
OptElementsGui.AddToOSData(l1,"Element");
doc.recompute();
if (str(FreeCADGui.ActiveDocument.activeView())=='View3DInventor'):
FreeCADGui.activeDocument().activeView().viewRear();
FreeCADGui.activeDocument().activeView().viewRotateRight();
FreeCADGui.activeDocument().activeView().fitAll();
# end if
FreeCAD.Console.PrintMessage("Element is imported\n");
示例2: place_steps
def place_steps(doc,placement,board_thickness):
""" place_steps(doc,placement,board_thickness)->place step models on board
list of models and path to step files is set at start of this script
model_tab_filename= "" & step_path="" """
model_file=pythonopen(model_tab_filename, "r")
model_lines=model_file.readlines()
model_file.close()
model_dict=[]
if IDF_diag==1:
model_file=pythonopen(IDF_diag_path+"/missing_models.lst", "w")
keys=[]
#prev_step="*?.*?" #hope nobody will insert this step filename
step_dict=[]
for model_line in model_lines:
model_records=split_records(model_line)
if len(model_records)>1 and model_records[0] and not model_records[0] in keys:
keys.append(model_records[0])
model_dict.append((str(model_records[0]).replace('"',''),str(model_records[1]).replace('"','')))
model_dict=dict(model_dict)
validkeys=filter(lambda x:x in [place_item[2] for place_item in placement], model_dict.keys())
FreeCAD.Console.PrintMessage("Step models to be loaded for footprints: "+str(validkeys)+"\n")
grp=doc.addObject("App::DocumentObjectGroup", "Step Lib")
for validkey in validkeys:
ImportGui.insert(step_path+model_dict[validkey],FreeCAD.ActiveDocument.Name)
#partName=FreeCAD.ActiveDocument.ActiveObject.Name
impPart=FreeCAD.ActiveDocument.ActiveObject
#impPart.Shape=FreeCAD.ActiveDocument.ActiveObject.Shape
#impPart.ViewObject.DiffuseColor=FreeCAD.ActiveDocument.ActiveObject.ViewObject.DiffuseColor
impPart.ViewObject.Visibility=0
impPart.Label=validkey
grp.addObject(impPart)
step_dict.append((validkey,impPart))
FreeCAD.Console.PrintMessage("Reading step file "+str(model_dict[validkey])+" for footprint "+str(validkey)+"\n")
step_dict=dict(step_dict)
grp=doc.addObject("App::DocumentObjectGroup", "Step Models")
for place_item in placement:
if place_item[2] in step_dict:
step_model=doc.addObject("Part::Feature",place_item[0]+"_s")
FreeCAD.Console.PrintMessage("Adding STEP model "+str(place_item[0])+"\n")
#if prev_step!=place_item[2]:
# model0=Part.read(step_path+"/"+model_dict[place_item[2]])
# prev_step=place_item[2]
step_model.Shape=step_dict[place_item[2]].Shape
step_model.ViewObject.DiffuseColor=step_dict[place_item[2]].ViewObject.DiffuseColor
z_pos=0
rotateY=0
if place_item[6]=='BOTTOM':
rotateY=pi
z_pos=-board_thickness
placmnt=Base.Placement(Base.Vector(place_item[3],place_item[4],z_pos),toQuaternion(rotateY,place_item[5]*pi/180,0))
step_model.Placement=placmnt
grp.addObject(step_model)
else:
if IDF_diag==1:
model_file.writelines(str(place_item[0])+" "+str(place_item[2])+"\n")
model_file.close()
示例3: export
def export(objs,filename):
"""exporting to file folder"""
#sayz(filename)
sayz("stpZ version "+___stpZversion___)
ext = os.path.splitext(os.path.basename(filename))[1]
fname=os.path.splitext(os.path.basename(filename))[0]
basepath=os.path.split(filename)[0]
tempdir = tempfile.gettempdir() # get the current temporary directory
filepath = os.path.join(basepath,fname) + u'.stp'
filepath_base = os.path.join(basepath,fname)
namefpath = os.path.join(basepath,fname)
outfpath = os.path.join(basepath,fname)+u'.stpZ'
outfpath_stp = os.path.join(basepath,fname)+u'.stp'
outfpath_base = basepath
#outfpath_str = mkz_string(os.path.join(basepath,fname))
outfpath_str = os.path.join(basepath,fname)
if os.path.exists(outfpath_stp):
sayzw("File cannot be compressed because a file with the same name exists '"+ outfpath_stp +"'")
QtGui.QApplication.restoreOverrideCursor()
reply = QtGui.QMessageBox.information(None,"info", "File cannot be compressed because\na file with the same name exists\n'"+ outfpath_stp + "'")
else:
ImportGui.export(objs,outfpath_stp)
if 0: #os.path.exists(namefpath):
sayzw("File cannot be compressed because a file with the same name exists '" + namefpath + "'")
QtGui.QApplication.restoreOverrideCursor()
reply = QtGui.QMessageBox.information(None,"info", "File cannot be compressed because\na file with the same name exists\n'"+ namefpath+ "'")
else:
with six.builtins.open(outfpath_stp, 'rb') as f_in:
file_content = f_in.read()
new_f_content = file_content
f_in.close()
with gz.open(outfpath_str, 'wb') as f_out:
f_out.write(new_f_content)
f_out.close()
if os.path.exists(outfpath):
os.remove(outfpath)
os.rename(outfpath_str, outfpath)
os.remove(outfpath_stp)
else:
os.rename(outfpath_str, outfpath)
os.remove(outfpath_stp)
示例4: exportSTEP
def exportSTEP(doc,modelName, dir):
## Export to STEP
## Get cwd
## outdir=os.path.dirname(os.path.realpath(__file__))+dir
outdir=dir
FreeCAD.Console.PrintMessage('\r\n'+outdir)
StepFileName=outdir+'/'+modelName+'.step'
objs=[]
objs=GetListOfObjects(FreeCAD, doc)
import ImportGui
FreeCAD.Console.PrintMessage('\r\n'+StepFileName)
# FreeCAD.Console.PrintMessage(objs)
FreeCAD.Console.PrintMessage('\r\n'+outdir)
ImportGui.export(objs,StepFileName)
return 0
示例5: exportSTEP
def exportSTEP(doc,modelName, dir, objectToExport=None):
## Export to STEP
## Get cwd
## outdir=os.path.dirname(os.path.realpath(__file__))+dir
outdir=dir
FreeCAD.Console.PrintMessage('\r\n'+outdir)
StepFileName=outdir+os.sep+modelName+'.step'
objs=[]
if objectToExport is None:
objs=GetListOfObjects(FreeCAD, doc)
else:
objs.append(objectToExport)
import ImportGui
FreeCAD.Console.PrintMessage('\r\n'+StepFileName)
# FreeCAD.Console.PrintMessage(objs)
FreeCAD.Console.PrintMessage('\r\n'+outdir)
ImportGui.export(objs,StepFileName)
return 0
示例6: exportVRML
def exportVRML(doc,modelName,scale,dir):
## Export to VRML scaled 1/2.54
#VrmlFileName='.//'+doc.Label+'.wrl'
## outdir=os.path.dirname(os.path.realpath(__file__))+dir
outdir=dir
FreeCAD.Console.PrintMessage('\r\n'+outdir)
VrmlFileName=outdir+'/'+modelName+'.wrl'
StepFileName=outdir+'/'+modelName+'.step'
objs=[]
objs=GetListOfObjects(FreeCAD, doc)
#objs.append(FreeCAD.getDocument(doc.Name).getObject("Fusion001"))
FreeCAD.ActiveDocument.addObject('Part::Feature','Vrml_model').Shape=objs[0].Shape
FreeCAD.ActiveDocument.ActiveObject.Label='Vrml_model'
FreeCADGui.ActiveDocument.ActiveObject.ShapeColor=FreeCADGui.getDocument(doc.Name).getObject(objs[0].Name).ShapeColor
FreeCADGui.ActiveDocument.ActiveObject.LineColor=FreeCADGui.getDocument(doc.Name).getObject(objs[0].Name).LineColor
FreeCADGui.ActiveDocument.ActiveObject.PointColor=FreeCADGui.getDocument(doc.Name).getObject(objs[0].Name).PointColor
FreeCADGui.ActiveDocument.ActiveObject.DiffuseColor=FreeCADGui.getDocument(doc.Name).getObject(objs[0].Name).DiffuseColor
FreeCAD.ActiveDocument.recompute()
newObj=FreeCAD.getDocument(doc.Name).getObject('Vrml_model')
#scale to export vrml start
Draft.scale(newObj,delta=FreeCAD.Vector(scale,scale,scale),center=FreeCAD.Vector(0,0,0),legacy=True)
FreeCAD.activeDocument().recompute()
#we need to remove object to export only scaled model
FreeCAD.getDocument(doc.Name).removeObject(objs[0].Name)
__objs__=[]
__objs__.append(FreeCAD.getDocument(doc.Name).getObject("Vrml_model"))
FreeCADGui.export(__objs__,VrmlFileName)
FreeCAD.activeDocument().recompute()
#restoring step module
import ImportGui
ImportGui.insert(StepFileName,doc.Name)
FreeCAD.Console.PrintMessage(FreeCAD.ActiveDocument.ActiveObject.Label+" exported and scaled to Vrml\r\n")
del __objs__
return 0
示例7: gmshmesh
def gmshmesh(compound, NG2D, name=""):
'''
export, mesh compound at gmsh, reimport as .unv
(3d to be implemented)
'''
if name =="": name="m_"+compound.Label
#
ImportGui.export([FreeCAD.activeDocument().getObject(compound.Name)], "/tmp/tmpNO2c.step")
#
command="/usr/bin/gmsh /tmp/tmpNO2c.step -2 -format unv -o /tmp/"+name+".unv -algo "+str(NG2D.gmshalgoname)+" -clmax " +str(NG2D.NGParamSetMaxSize)+" -clmin "+str(NG2D.NGParamSetMinSize)+" -string Geometry.OCCSewFaces=1;"
#command="/usr/bin/gmsh /tmp/tmpNO2c.step -2 -format unv -o /tmp/Compound019_Mesh.unv -algo auto -string Geometry.OCCSewFaces=1;"
#command="g"
#
#print command
output = subprocess.check_output([command, '-1'], shell=True, stderr=subprocess.STDOUT,)
FreeCAD.Console.PrintMessage(output)
#
Fem.insert("/tmp/"+name+".unv", FreeCAD.ActiveDocument.Name)
#Fem.insert("/tmp/Compound019_Mesh.unv", FreeCAD.ActiveDocument.Name)
femmesh=FreeCAD.ActiveDocument.Objects[len(FreeCAD.ActiveDocument.Objects)-1]
FreeCADGui.ActiveDocument.getObject(femmesh.Name).DisplayMode = "Wireframe"
return femmesh
示例8: insert
def insert(filename,doc):
sayz("stpZ version "+___stpZversion___)
with gzip_utf8.open(filename, 'rb') as f:
file_content = f.read()
ext = os.path.splitext(os.path.basename(filename))[1]
fname=os.path.splitext(os.path.basename(filename))[0]
basepath=os.path.split(filename)[0]
filepath = os.path.join(basepath,fname + u'.stp')
tempdir = tempfile.gettempdir() # get the current temporary directory
tempfilepath = os.path.join(tempdir,fname + u'.stp')
with builtin.open(tempfilepath, 'w') as f: #py3
f.write(file_content)
ImportGui.insert(tempfilepath, doc)
#ImportGui.open(tempfilepath)
try:
os.remove(tempfilepath)
except OSError:
sayzerr("error on removing "+tempfilepath+" file")
pass
示例9: exit
# Set the directory variable before running
import FreeCAD
import ImportGui
import FreeCADGui
import os
# directory = "/home/mikael/kicad_ws/osrf_hw/kicad_3dmodels/BGA"
directory = os.getcwd()
print directory
if not os.path.isdir(directory):
print "ERROR directory " + directory + " doesn't exist"
exit(1)
for root, subdirs, files in os.walk(directory):
for filename in files:
if filename.lower().endswith(".stp") or filename.lower().endswith(".step"):
file_path = os.path.join(root, filename)
ImportGui.open(file_path)
wrlname = file_path[0 : file_path.rfind(file_path[file_path.rfind(".") :])] + ".wrl"
Gui.export(App.ActiveDocument.findObjects("Part::Feature"), wrlname)
App.closeDocument(App.ActiveDocument.Name)
exit(1)
示例10: saveFCdoc
Gui.SendMsgToActiveView("ViewFit")
Gui.activeDocument().activeView().viewAxometric()
# Save the doc in Native FC format
saveFCdoc(App, Gui, doc, ModelName,out_dir, False)
check_Model=False
if save_memory == True or check_Model==True:
doc=FreeCAD.ActiveDocument
FreeCAD.closeDocument(doc.Name)
step_path=os.path.join(out_dir,ModelName+u'.step')
if check_Model==True:
#ImportGui.insert(step_path,ModelName)
ImportGui.open(step_path)
docu = FreeCAD.ActiveDocument
if cq_cad_tools.checkUnion(docu) == True:
FreeCAD.Console.PrintMessage('step file is correctly Unioned\n')
else:
FreeCAD.Console.PrintError('step file is NOT Unioned\n')
stop
FC_majorV=int(FreeCAD.Version()[0])
FC_minorV=int(FreeCAD.Version()[1])
if FC_majorV == 0 and FC_minorV >= 17:
for o in docu.Objects:
if hasattr(o,'Shape'):
chks=cq_cad_tools.checkBOP(o.Shape)
print 'chks ',chks
print cq_cad_tools.mk_string(o.Label)
if chks != True:
示例11: runGeometryCheck
def runGeometryCheck(App, Gui, step_path, log,
modelName, save_memory=True, stop_on_first_error = True):
FC_majorV=int(FreeCAD.Version()[0])
FC_minorV=int(FreeCAD.Version()[1])
try:
FC_subV=int(FreeCAD.Version()[2].split(" ")[0])
except Exception:
FC_subV = 0
if FC_majorV == 0 and FC_minorV == 16 and FC_subV < 6712:
raise FreeCADVersionError('0.16-6712', 'old 0.16 releases have a bug in the step exporter.')
geometry_error_container = GeometryError()
ImportGui.open(step_path)
docu = FreeCAD.ActiveDocument
docu.Label = modelName
log.write('\n## Checking {:s}\n'.format(modelName))
if checkUnion(docu):
FreeCAD.Console.PrintMessage('step file is correctly Unioned\n')
log.write('\t- Union check: [ pass ]\n')
else:
#FreeCAD.Console.PrintError('step file is NOT Unioned\n')
log.write('\t- Union check: [ FAIL ]\n')
geometry_error_container.append(NotUnionedError(modelName))
#stop
if FC_majorV == 0 and FC_minorV >= 17:
if docu.Objects == 0:
FreeCAD.Console.PrintError('Step import seems to fail. No objects to check\n')
for o in docu.Objects:
if hasattr(o,'Shape'):
o.Shape.fixTolerance(1e-4)
chks=checkBOP(o.Shape)
#print 'chks ',chks
if chks != True:
#msg='shape \''+o.Name+'\' \''+ mk_string(o.Label)+'\' is INVALID!\n'
msg = 'shape "{name:s}" "{label:s}" is INVALID\n'.format(name=o.Name, label=o.Label)
#FreeCAD.Console.PrintError(msg)
#FreeCAD.Console.PrintWarning(chks[0])
geometry_error_container.append(BOBError(modelName, o.Name, o.Label, chks[0]))
log.write('\t- Geometry check: [ FAIL ]\n')
log.write('\t\t- Effected shape: "{name:s}" "{label:s}"\n'.format(name=o.Name, label=o.Label))
#stop
else:
#msg='shape \''+o.Name+'\' \''+ mk_string(o.Label)+'\' is valid\n'
msg = 'shape "{name:s}" "{label:s}" is valid\n'.format(name=o.Name, label=o.Label)
FreeCAD.Console.PrintMessage(msg)
log.write('\t- Geometry check: [ pass ]\n')
else:
log.write('\t- Geometry check: [ skipped ]\n')
log.write('\t\t- Geometry check needs FC 0.17+\n')
raise FreeCADVersionError('0.17', 'Geometry check needs FC 0.17')
if stop_on_first_error and geometry_error_container.error_encountered:
raise geometry_error_container
if save_memory == True:
saveFCdoc(App, Gui, docu, 'temp', './', False)
docu = FreeCAD.ActiveDocument
FreeCAD.closeDocument(docu.Name)
if geometry_error_container.error_encountered:
raise geometry_error_container
示例12: importPart
def importPart( filename, partName=None, doc_assembly=None ):
if doc_assembly == None:
doc_assembly = FreeCAD.ActiveDocument
updateExistingPart = partName != None
if updateExistingPart:
FreeCAD.Console.PrintMessage("updating part %s from %s\n" % (partName,filename))
else:
FreeCAD.Console.PrintMessage("importing part from %s\n" % filename)
doc_already_open = filename in [ d.FileName for d in FreeCAD.listDocuments().values() ]
debugPrint(4, "%s open already %s" % (filename, doc_already_open))
if doc_already_open:
doc = [ d for d in FreeCAD.listDocuments().values() if d.FileName == filename][0]
close_doc = False
else:
if filename.lower().endswith('.fcstd'):
doc = Fcstd_File_Parser( filename )
close_doc = False
else: #trying shaping import http://forum.freecadweb.org/viewtopic.php?f=22&t=12434&p=99772#p99772x
import ImportGui
doc = FreeCAD.newDocument( os.path.basename(filename) )
shapeobj = ImportGui.insert(filename,doc.Name)
close_doc = True
visibleObjects = [ obj for obj in doc.Objects
if hasattr(obj,'ViewObject') and obj.ViewObject.isVisible()
and hasattr(obj,'Shape') and len(obj.Shape.Faces) > 0 and 'Body' not in obj.Name] # len(obj.Shape.Faces) > 0 to avoid sketches, skip Body
debugPrint(3, '%s objects %s' % (doc.Name, doc.Objects))
if any([ 'importPart' in obj.Content for obj in doc.Objects]) and not len(visibleObjects) == 1:
subAssemblyImport = True
debugPrint(2, 'Importing subassembly from %s' % filename)
tempPartName = 'import_temporary_part'
obj_to_copy = doc_assembly.addObject("Part::FeaturePython",tempPartName)
obj_to_copy.Proxy = Proxy_muxAssemblyObj()
obj_to_copy.ViewObject.Proxy = ImportedPartViewProviderProxy()
obj_to_copy.Shape = muxObjects(doc)
if (not updateExistingPart) or \
(updateExistingPart and getattr( doc_assembly.getObject(partName),'updateColors',True)):
muxMapColors(doc, obj_to_copy)
else:
subAssemblyImport = False
if len(visibleObjects) != 1:
if not updateExistingPart:
msg = "A part can only be imported from a FreeCAD document with exactly one visible part. Aborting operation"
QtGui.QMessageBox.information( QtGui.QApplication.activeWindow(), "Value Error", msg )
else:
msg = "Error updating part from %s: A part can only be imported from a FreeCAD document with exactly one visible part. Aborting update of %s" % (partName, filename)
QtGui.QMessageBox.information( QtGui.QApplication.activeWindow(), "Value Error", msg )
#QtGui.QMessageBox.warning( QtGui.QApplication.activeWindow(), "Value Error!", msg, QtGui.QMessageBox.StandardButton.Ok )
return
obj_to_copy = visibleObjects[0]
if updateExistingPart:
obj = doc_assembly.getObject(partName)
prevPlacement = obj.Placement
if not hasattr(obj, 'updateColors'):
obj.addProperty("App::PropertyBool","updateColors","importPart").updateColors = True
importUpdateConstraintSubobjects( doc_assembly, obj, obj_to_copy )
else:
partName = findUnusedObjectName( doc.Label + '_', document=doc_assembly )
try:
obj = doc_assembly.addObject("Part::FeaturePython",partName)
except UnicodeEncodeError:
safeName = findUnusedObjectName('import_', document=doc_assembly)
obj = doc_assembly.addObject("Part::FeaturePython", safeName)
obj.Label = findUnusedLabel( doc.Label + '_', document=doc_assembly )
obj.addProperty("App::PropertyFile", "sourceFile", "importPart").sourceFile = filename
obj.addProperty("App::PropertyFloat", "timeLastImport","importPart")
obj.setEditorMode("timeLastImport",1)
obj.addProperty("App::PropertyBool","fixedPosition","importPart")
obj.fixedPosition = not any([i.fixedPosition for i in doc_assembly.Objects if hasattr(i, 'fixedPosition') ])
obj.addProperty("App::PropertyBool","updateColors","importPart").updateColors = True
obj.Shape = obj_to_copy.Shape.copy()
if updateExistingPart:
obj.Placement = prevPlacement
else:
# for Fcstd_File_Parser not all properties are implemented...
for p in obj_to_copy.ViewObject.PropertiesList: #assuming that the user may change the appearance of parts differently depending on the assembly.
if hasattr(obj.ViewObject, p) and p not in ['DiffuseColor']:
try:
setattr(obj.ViewObject, p, getattr(obj_to_copy.ViewObject, p))
except Exception as msg:
FreeCAD.Console.PrintWarning('Unable to setattr(obj.ViewObject, %s, %s)\n' % (p, getattr(obj_to_copy.ViewObject, p) ))
obj.ViewObject.Proxy = ImportedPartViewProviderProxy()
if getattr(obj,'updateColors',True) and hasattr( obj_to_copy.ViewObject, 'DiffuseColor'):
obj.ViewObject.DiffuseColor = copy.copy( obj_to_copy.ViewObject.DiffuseColor )
#obj.ViewObject.Transparency = copy.copy( obj_to_copy.ViewObject.Transparency ) # .Transparency property
tsp = copy.copy( obj_to_copy.ViewObject.Transparency ) # .Transparency workaround for FC 0.17 @ Nov 2016
if tsp < 100 and tsp!=0:
obj.ViewObject.Transparency = tsp+1
if tsp == 100:
obj.ViewObject.Transparency = tsp-1
obj.ViewObject.Transparency = tsp # .Transparency workaround end
obj.Proxy = Proxy_importPart()
obj.timeLastImport = os.path.getmtime( filename )
#clean up
if subAssemblyImport:
doc_assembly.removeObject(tempPartName)
if close_doc:
FreeCAD.closeDocument( doc.Name )
#.........这里部分代码省略.........
示例13: get_layer_tail
subsystem_grp = doc.addObject("App::DocumentObjectGroup", subsystem)
subsystem_grp.Label = subsystem
for step,vv in v.items():
step_name = get_layer_tail(step)
step_grp = doc.addObject("App::DocumentObjectGroup", step_name)
step_grp.Label = step_name
subsystem_grp.addObject(step_grp)
for partkind,vvv in vv.items():
partkind_name = "%s::%s" % (step_name,partkind)
partkind_grp = doc.addObject("App::DocumentObjectGroup", partkind_name)
partkind_grp.Label = partkind_name
step_grp.addObject(partkind_grp)
filename = get_part_filename(subsystem, step_name, partkind)
FreeCAD.Console.PrintMessage(filename + "\n")
preimport_obj_count = len(doc.Objects)
ImportGui.insert(os.path.join(step_dir, filename), doc.Name)
# group new objects
for i in range(preimport_obj_count, len(doc.Objects)):
obj = doc.Objects[i]
if obj.TypeId == 'Part::Feature':
partkind_grp.addObject(obj)
FreeCAD.Gui.SendMsgToActiveView("ViewFit")
if not subsystem == "1.frame-bottom":
subsystem_grp.ViewObject.Visibility=False
doc.recompute()
示例14:
exp_objects = []
for obj in FreeCAD.ActiveDocument.Objects:
# select all but indivudial Spheres and Sketch
if (obj.Name.find("Pin") == -1) and (obj.Name.find("Sketch") == -1):
Gui.Selection.addSelection(obj)
exp_objects.append(obj)
else:
FreeCAD.ActiveDocument.removeObject(obj.Name)
App.activeDocument().addObject("Part::MultiFuse","Fusion2")
App.activeDocument().Fusion2.Shapes = exp_objects
App.ActiveDocument.recompute()
for obj in exp_objects:
FreeCAD.ActiveDocument.removeObject(obj.Name)
exp_objects= []
exp_objects.append(FreeCAD.ActiveDocument.getObject("Fusion2"))
ImportGui.export(exp_objects,os.path.join(directory, name + '.step'))
del exp_objects
# Scale to mil before export to VRML for KiCAD use
Draft.scale(FreeCAD.ActiveDocument.ActiveObject,
FreeCAD.Vector(MMTOMIL, MMTOMIL, MMTOMIL))
FreeCAD.ActiveDocument.removeObject("Fusion2")
### Export as a VRML model
exp_objects = []
exp_objects.append(FreeCAD.ActiveDocument.getObject("Scale"))
FreeCADGui.export(exp_objects,os.path.join(directory, name + '.wrl'))
del exp_objects
exit(1)
示例15:
App.ActiveDocument.recompute()
sk2.addConstraint(Sketcher.Constraint("DistanceY", 4, 2, 0, 2, 1.750603))
sk2.setDatum(18, App.Units.Quantity(str(data[10]) + " mm"))
App.ActiveDocument.recompute()
sk2.addConstraint(Sketcher.Constraint("Coincident", 6, 3, -1, 1))
App.ActiveDocument.recompute()
poc = App.activeDocument().addObject("PartDesign::Pocket", "Pocket")
poc.Sketch = sk2
poc.Length = data[10]
poc.Label = name
FreeCADGui.getDocument(App.ActiveDocument.Name).getObject("Pocket").LineColor = (0.0, 0.0, 0.0)
FreeCADGui.getDocument(App.ActiveDocument.Name).getObject("Pocket").ShapeColor = (0.31, 0.73, 0.76)
Gui.getDocument(App.ActiveDocument.Name).getObject("Sketch").Visibility = False
Gui.getDocument(App.ActiveDocument.Name).getObject("Sketch001").Visibility = False
Gui.getDocument(App.ActiveDocument.Name).getObject("Revolve").Visibility = False
App.ActiveDocument.recompute()
Gui.SendMsgToActiveView("ViewFit")
App.ActiveDocument.saveAs(directory + name + ".FCStd")
__objs__ = []
__objs__.append(FreeCAD.getDocument(App.ActiveDocument.Name).getObject("Pocket"))
ImportGui.export(__objs__, directory + name + ".step")
Mesh.export(__objs__, directory + name + ".stl")
del __objs__
App.closeDocument(App.ActiveDocument.Name)
print "End"