Beispiel #1
0
def reorient_object(input_file_name, output_file_name, refinement_level):
	__objToExport__ = FreeCAD.getDocument("tmp").findObjects()

	# get the original file
	Import.insert(input_file_name, "tmp")

	# get bounding box
	bB = FreeCAD.getDocument("tmp").Objects[-1].Shape.BoundBox

	# create rotation parameters
	displacement = FreeCAD.Vector(2.0, 0.0, 0.0)
	centerRot = FreeCAD.Vector(bB.XMin, 0.5*(bB.YMin+bB.YMax), bB.ZMin)
	axisRot1 = FreeCAD.Vector(0.0, 0.0, 1.0)
	axisRot2 = FreeCAD.Vector(0.0, 1.0, 0.0)
	angleRot1 = 180.0
	angleRot2 = 90.0

	# import the draft module
	import Draft
	Draft.move(FreeCAD.getDocument("tmp").Objects[0], displacement, copy=False) # perform move
	Draft.rotate(FreeCAD.getDocument("tmp").Objects[0], angleRot1, centerRot,axis=axisRot1,copy=False) # perform first rotation
	Draft.rotate(FreeCAD.getDocument("tmp").Objects[0], angleRot2, centerRot,axis=axisRot2,copy=False) # perform second rotation

	# remove originalGeom
	originalGeom = FreeCAD.getDocument("tmp").Objects[-1].Name
	FreeCAD.getDocument("tmp").removeObject(originalGeom)

	print "Exporting RAW file..."
	Part.export(__objToExport__, output_file_name+".step")
	print "Output file " + output_file_name+".step" + " exported."
Beispiel #2
0
def Load_STEP_File(doc_status, material):
    import tkFileDialog
    import FreeCAD
    import Import
    import FreeCADGui
    import Draft
    import Part
    #prepares and opens STEP file with FreeCADs
    path_to_file = tkFileDialog.askopenfilename()
    if (path_to_file[-5:] == ".STEP" or path_to_file[-5:] == ".step"
            or path_to_file[-4:] == ".stp"):
        if (
                doc_status
        ):  #If a file was already open the document associated with it must be closed
            FreeCAD.closeDocument("Unnamed")
            print "Previous document closed"
        FreeCAD.newDocument("Unnamed")
        FreeCAD.setActiveDocument("Unnamed")
        try:
            Import.insert(
                path_to_file, "Unnamed"
            )  #FreeCAD attempts to open file - If the format is wrong it will be detected
            print "File read successfuly"
            list_of_objects = []
            for obj in FreeCAD.ActiveDocument.Objects:
                list_of_objects.append(Volumes.Volume(obj, material, 0.1, 1))
            return list_of_objects
        except:
            print "Error reading file. Format might be incorrect."
            return 0
    else:
        print "Error with file extension"
        return 0
def process_nonchanging_domains(nonchanging_file_name, output_file_name):
    if len(nonchanging_file_name) != 0:

        __objs_original__ = FreeCAD.getDocument("tmp").findObjects()
        len_original = len(__objs_original__)
        print "Loading non-changing component..."
        Import.insert(nonchanging_file_name, "tmp")

        # get objects
        __objs__ = FreeCAD.getDocument("tmp").findObjects()

        # create fusion object
        FreeCAD.getDocument("tmp").addObject("Part::MultiFuse", "FusionTool")

        # add objs to FusionTool
        FreeCAD.getDocument(
            "tmp").FusionTool.Shapes = __objs__[0:len(__objs__)]

        # compute
        FreeCAD.getDocument("tmp").recompute()

        # make one solid
        Part.show(Part.makeSolid(FreeCAD.getDocument("tmp").Objects[-1].Shape))

        # remove all except the last
        __objs__ = FreeCAD.getDocument("tmp").findObjects()
        for i in range(0, len(__objs__) - 1):
            FreeCAD.getDocument("tmp").removeObject(__objs__[i].Name)

        print "Exporting BOOLEANED file..."
        __objs__ = FreeCAD.getDocument("tmp").findObjects()
        Part.export(__objs__, output_file_name + "_BOOLEANED.step")
        print "Output file " + output_file_name + "_BOOLEANED.step" + " exported."
def process_nonchanging_domains(nonchanging_file_name, output_file_name):
	if len(nonchanging_file_name) != 0:

		__objs_original__ = FreeCAD.getDocument("tmp").findObjects()
		len_original =len(__objs_original__)
		print "Loading non-changing component..."
		Import.insert(nonchanging_file_name, "tmp")

		# get objects
		__objs__ = FreeCAD.getDocument("tmp").findObjects()

		# create fusion object
		FreeCAD.getDocument("tmp").addObject("Part::MultiFuse", "FusionTool")

		# add objs to FusionTool
		FreeCAD.getDocument("tmp").FusionTool.Shapes = __objs__[0: len(__objs__)]

		# compute
		FreeCAD.getDocument("tmp").recompute()

		# make one solid
		Part.show(Part.makeSolid(FreeCAD.getDocument("tmp").Objects[-1].Shape))

		# remove all except the last
		__objs__ = FreeCAD.getDocument("tmp").findObjects()
		for i in range(0, len(__objs__) - 1):
			FreeCAD.getDocument("tmp").removeObject(__objs__[i].Name)

		print "Exporting BOOLEANED file..."
		__objs__ = FreeCAD.getDocument("tmp").findObjects()
		Part.export(__objs__, output_file_name+"_BOOLEANED.step")
		print "Output file " + output_file_name+"_BOOLEANED.step" + " exported."
def process_nonchanging_domains(nonchanging_file_name, output_file_name, refinement_level):
	if len(nonchanging_file_name) != 0:
		print "Loading non-changing component..."
		Import.insert(nonchanging_file_name, "tmp")
		
		#import Draft
		#scaleFactor = 2**refinement_level
		#scaleVector = FreeCAD.Vector(scaleFactor, scaleFactor, scaleFactor)
		#Draft.scale(FreeCAD.getDocument("tmp").Objects[0], scaleVector)#, center=FreeCAD.Vector(1,1,1),copy=False) # perfom scaling

		# get objects
		__objs__ = FreeCAD.getDocument("tmp").findObjects()

		# create fusion object
		FreeCAD.getDocument("tmp").addObject("Part::MultiFuse", "FusionTool")

		# add objs to FusionTool
		FreeCAD.getDocument("tmp").FusionTool.Shapes = __objs__[0: len(__objs__)]

		# compute
		FreeCAD.getDocument("tmp").recompute()

		# make one solid
		Part.show(Part.makeSolid(FreeCAD.getDocument("tmp").Objects[-1].Shape))

		# remove all except the last
		__objs__ = FreeCAD.getDocument("tmp").findObjects()
		for i in range(0, len(__objs__) - 1):
			FreeCAD.getDocument("tmp").removeObject(__objs__[i].Name)

		print "Exporting BOOLEANED file..."
		__objs__ = FreeCAD.getDocument("tmp").findObjects()
		Part.export(__objs__, output_file_name+"_BOOLEANED.step")
		print "Output file " + output_file_name+"_BOOLEANED.step" + " exported."
def process_allowed_domains(allowed_domains_file_name, output_file_name, refinement_level):
	if len(allowed_domains_file_name) != 0:
		print "Checking allowed domains..."
		# take the intersection of allowed domains
		# read in step file for allowed domains
		Import.insert(allowed_domains_file_name, "tmp")
		__objs__ = FreeCAD.getDocument("tmp").findObjects()

		# get bounding box of the allowed domains
		# NOTE: ASSUMING ALLOWED DOMAINS ARE ALL FUSED IN ONE OBJECT.
		#import Draft
		#scaleFactor = 2**refinement_level
		#scaleVector = FreeCAD.Vector(scaleFactor, scaleFactor, scaleFactor)
		#Draft.scale(FreeCAD.getDocument("tmp").Objects[0], scaleVector)#, center=FreeCAD.Vector(1,1,1),copy=False) # perfom scaling

		# create mega BB object
		create_mega_bounding_box_object()

		# cut out allowed domains from mega BB object
		FreeCAD.getDocument("tmp").addObject("Part::Cut", "Cut_megaBB")
		FreeCAD.getDocument("tmp").Cut_megaBB.Base = FreeCAD.getDocument("tmp").Objects[-2]
		FreeCAD.getDocument("tmp").Cut_megaBB.Tool = FreeCAD.getDocument("tmp").Objects[-3]
		FreeCAD.getDocument("tmp").recompute()
		#Part.show(Part.makeSolid(FreeCAD.getDocument("tmp").Objects[-1].Shape))

		# cut out not-allowed parts
		FreeCAD.getDocument("tmp").addObject("Part::Cut", "Cut_allowed")
		FreeCAD.getDocument("tmp").Cut_allowed.Base = FreeCAD.getDocument("tmp").Objects[0]
		FreeCAD.getDocument("tmp").Cut_allowed.Tool = FreeCAD.getDocument("tmp").Objects[-2]
		FreeCAD.getDocument("tmp").recompute()
		Part.show(Part.makeSolid(FreeCAD.getDocument("tmp").Objects[-1].Shape))

		# remove everything except the last cut-object
		__objs__ = FreeCAD.getDocument("tmp").findObjects()
		for i in range(0, len(__objs__) - 1):
			FreeCAD.getDocument("tmp").removeObject(__objs__[i].Name)

		# update __objs__
		__objs__ = FreeCAD.getDocument("tmp").findObjects()

		print __objs__

		if len(__objs__) > 1:
			# create a fuse object and union all "Common"s
			FreeCAD.getDocument("tmp").addObject("Part::MultiFuse", "Fuse")
			FreeCAD.getDocument("tmp").Fuse.Shapes = __objs__[1: len(__objs__)]
			print FreeCAD.getDocument("tmp").Fuse.Shapes
			FreeCAD.getDocument("tmp").recompute()

			# remove "Commons"s
			for i in range(0, len(__objs__)):
				FreeCAD.getDocument("tmp").removeObject(__objs__[i].Name)

		# update __objs__
		__objs__ = FreeCAD.getDocument("tmp").findObjects()
Beispiel #7
0
def process_allowed_domains(allowed_domains_file_name, output_file_name):
    if len(allowed_domains_file_name) != 0:
        print "Checking allowed domains..."
        # take the intersection of allowed domains
        # read in step file for allowed domains

        __objs_original__ = FreeCAD.getDocument("tmp").findObjects()

        Import.insert(allowed_domains_file_name, "tmp")
        __objs__ = FreeCAD.getDocument("tmp").findObjects()

        # create mega BB object
        create_mega_bounding_box_object()

        # cut out allowed domains from mega BB object
        FreeCAD.getDocument("tmp").addObject("Part::Cut", "Cut_megaBB")
        FreeCAD.getDocument("tmp").Cut_megaBB.Base = FreeCAD.getDocument(
            "tmp").Objects[-2]
        FreeCAD.getDocument("tmp").Cut_megaBB.Tool = FreeCAD.getDocument(
            "tmp").Objects[-3]
        FreeCAD.getDocument("tmp").recompute()
        #Part.show(Part.makeSolid(FreeCAD.getDocument("tmp").Objects[-1].Shape))

        # cut out not-allowed parts
        FreeCAD.getDocument("tmp").addObject("Part::Cut", "Cut_allowed")
        FreeCAD.getDocument("tmp").Cut_allowed.Base = FreeCAD.getDocument(
            "tmp").Objects[0]
        FreeCAD.getDocument("tmp").Cut_allowed.Tool = FreeCAD.getDocument(
            "tmp").Objects[-2]
        FreeCAD.getDocument("tmp").recompute()
        __objs__ = FreeCAD.getDocument("tmp").findObjects()
        Part.show(Part.makeSolid(FreeCAD.getDocument("tmp").Objects[-1].Shape))

        # remove everything except the last cut-object
        __objs__ = FreeCAD.getDocument("tmp").findObjects()
        for i in range(0, len(__objs__) - 1):
            FreeCAD.getDocument("tmp").removeObject(__objs__[i].Name)

        # update __objs__
        __objs__ = FreeCAD.getDocument("tmp").findObjects()

        if len(__objs__) > 1:
            # create a fuse object and union all "Common"s
            FreeCAD.getDocument("tmp").addObject("Part::MultiFuse", "Fuse")
            FreeCAD.getDocument("tmp").Fuse.Shapes = __objs__[1:len(__objs__)]
            print FreeCAD.getDocument("tmp").Fuse.Shapes
            FreeCAD.getDocument("tmp").recompute()

            # remove "Commons"s
            for i in range(0, len(__objs__)):
                FreeCAD.getDocument("tmp").removeObject(__objs__[i].Name)

        # update __objs__
        __objs__ = FreeCAD.getDocument("tmp").findObjects()
def process_allowed_domains(allowed_domains_file_name, output_file_name):
	if len(allowed_domains_file_name) != 0:
		print "Checking allowed domains..."
		# take the intersection of allowed domains
		# read in step file for allowed domains
		
		__objs_original__ = FreeCAD.getDocument("tmp").findObjects()

		Import.insert(allowed_domains_file_name, "tmp")
		__objs__ = FreeCAD.getDocument("tmp").findObjects()

		# create mega BB object
		create_mega_bounding_box_object()

		# cut out allowed domains from mega BB object
		FreeCAD.getDocument("tmp").addObject("Part::Cut", "Cut_megaBB")
		FreeCAD.getDocument("tmp").Cut_megaBB.Base = FreeCAD.getDocument("tmp").Objects[-2]
		FreeCAD.getDocument("tmp").Cut_megaBB.Tool = FreeCAD.getDocument("tmp").Objects[-3]
		FreeCAD.getDocument("tmp").recompute()
		#Part.show(Part.makeSolid(FreeCAD.getDocument("tmp").Objects[-1].Shape))

		# cut out not-allowed parts
		FreeCAD.getDocument("tmp").addObject("Part::Cut", "Cut_allowed")
		FreeCAD.getDocument("tmp").Cut_allowed.Base = FreeCAD.getDocument("tmp").Objects[0]
		FreeCAD.getDocument("tmp").Cut_allowed.Tool = FreeCAD.getDocument("tmp").Objects[-2]
		FreeCAD.getDocument("tmp").recompute()
		__objs__ = FreeCAD.getDocument("tmp").findObjects()
		Part.show(Part.makeSolid(FreeCAD.getDocument("tmp").Objects[-1].Shape))

		# remove everything except the last cut-object
		__objs__ = FreeCAD.getDocument("tmp").findObjects()
		for i in range(0, len(__objs__) - 1):
			FreeCAD.getDocument("tmp").removeObject(__objs__[i].Name)

		# update __objs__
		__objs__ = FreeCAD.getDocument("tmp").findObjects()

		if len(__objs__) > 1:
			# create a fuse object and union all "Common"s
			FreeCAD.getDocument("tmp").addObject("Part::MultiFuse", "Fuse")
			FreeCAD.getDocument("tmp").Fuse.Shapes = __objs__[1: len(__objs__)]
			print FreeCAD.getDocument("tmp").Fuse.Shapes
			FreeCAD.getDocument("tmp").recompute()

			# remove "Commons"s
			for i in range(0, len(__objs__)):
				FreeCAD.getDocument("tmp").removeObject(__objs__[i].Name)

		# update __objs__
		__objs__ = FreeCAD.getDocument("tmp").findObjects()
Beispiel #9
0
def reorient_object(input_file_name, output_file_name):
    __objToExport__ = FreeCAD.getDocument("tmp").findObjects()

    # get the original file
    Import.insert(input_file_name, "tmp")

    # get bounding box
    bB = FreeCAD.getDocument("tmp").Objects[-1].Shape.BoundBox

    # create rotation parameters
    #print "XMin:", bB.XMin, "XMax:", bB.XMax, "YMin:", bB.YMin, "YMax:", bB.YMax, "ZMin:", bB.ZMin, "ZMax:", bB.ZMax
    displacement = FreeCAD.Vector(-bB.ZMin, bB.YMin, -bB.XMin)
    centerRot = FreeCAD.Vector(bB.XMin, 0.5 * (bB.YMin + bB.YMax), bB.ZMin)
    axisRot1 = FreeCAD.Vector(0.0, 0.0, 1.0)
    axisRot2 = FreeCAD.Vector(0.0, 1.0, 0.0)
    angleRot1 = 180.0
    angleRot2 = 90.0

    # import the draft module
    import Draft
    Draft.move(FreeCAD.getDocument("tmp").Objects[0], displacement,
               copy=False)  # perform move
    Draft.rotate(FreeCAD.getDocument("tmp").Objects[0],
                 angleRot1,
                 centerRot,
                 axis=axisRot1,
                 copy=False)  # perform first rotation
    Draft.rotate(FreeCAD.getDocument("tmp").Objects[0],
                 angleRot2,
                 centerRot,
                 axis=axisRot2,
                 copy=False)  # perform second rotation

    # remove originalGeom
    originalGeom = FreeCAD.getDocument("tmp").Objects[-1].Name
    FreeCAD.getDocument("tmp").removeObject(originalGeom)

    print "Exporting RAW file..."
    Part.export(__objToExport__, output_file_name + ".step")
    print "Output file " + output_file_name + ".step" + " exported."

    return bB.YMax
Beispiel #10
0
def Load_STEP_File(doc_status,material):
    from GUIMeshLibs import Volumes
    import tkinter.filedialog
    import FreeCAD
    import Import
    import FreeCADGui
    import Draft
    import Part
    #prepares and opens STEP file with FreeCADs
    path_to_file = tkinter.filedialog.askopenfilename()
    if( path_to_file[-5:]==".STEP" or path_to_file[-5:]==".step"or path_to_file[-4:]==".stp"):
        if (doc_status):    #If a file was already open the document associated with it must be closed
            FreeCAD.closeDocument("Unnamed")
            print("Previous document closed")
        FreeCAD.newDocument("Unnamed")
        FreeCAD.setActiveDocument("Unnamed")
        try: 
            Import.insert(path_to_file,"Unnamed") #FreeCAD attempts to open file - If the format is wrong it will be detected
            print("File read successfuly")
            list_of_objects=[]
            for obj in FreeCAD.ActiveDocument.Objects:
                try:
                        if(obj.TypeId=="Part::Feature"):
                                obj.Label=obj.Label.replace(" ","_")
                                obj.Label=obj.Label.replace(".","_")
                                obj.Label=obj.Label.replace("---","_")
                                list_of_objects.append(Volumes.Volume(obj,material,0.1,1))
                except:
                        continue
            return list_of_objects
        except:
            print("Error reading file. Format might be incorrect.")
            return 0
    else:
        print("Error with file extension")
        return 0
Beispiel #11
0
                        required=False)
    parser.add_argument("-g",
                        "--use-design-global-origin",
                        help="Flag to use global origin.",
                        required=False,
                        action="store_true")
    parser.add_argument("-v",
                        "--verbose",
                        help="Print meshlabscript outputs.",
                        required=False,
                        action="store_true")
    args = parser.parse_args()
    # Open file
    doc = FreeCAD.newDocument("temp")
    FreeCAD.setActiveDocument("temp")
    freecadimport.insert(args.cadfile, "temp")

    # Gather the unique shapes, and clone parts
    unique_objs = []
    parts = {}
    num_objs = 0
    for obj in doc.Objects:
        new_shape = True
        if obj.TypeId == "Part::Feature":
            num_objs += 1
            for uobj in unique_objs:
                if uobj.Shape.isPartner(obj.Shape):
                    new_shape = False
                    parts[uobj.Label]["placements"] += [[
                        obj.Label, obj.Placement
                    ]]