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."
Beispiel #2
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."
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()
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 #6
0
    return vertices


def generate_quad(vertices):
    edges = 4 * [None]
    for i in range(4):
        edges[i] = Part.makeLine(tuple(vertices[i]),tuple(vertices[(i+1)%4]))

    wires = 4 * [None]
    wires[0] = Part.Wire([edges[0],edges[3]])
    wires[1] = Part.Wire([edges[2],edges[1]])
    wires[2] = Part.Wire([wires[0],wires[1]])
    Part.show(wires[2])

doc = FreeCAD.newDocument("tmp")
print "Document created"

pts, quads = parse_all_from_folder('./PetersSchemeInput/cantilever')
print "Stuff parsed"

for quad in quads:
    vertices = get_vertices(quad, pts)
    generate_quad(vertices)

print "points plotted"

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

Import.export(__objs__, "./torus_mesh.step")
print ".step exported"
Beispiel #7
0
    pts = parse_csv_into_matrix(folder_path+'/verts_fine.csv',float)

    return pts


def generate_point(vertex):
    free_cad_vect = FreeCAD.Vector(vertex[0],vertex[1],vertex[2])
    Part.show(Part.Vertex(free_cad_vect))


doc = FreeCAD.newDocument("tmp")
print "Document created"

pts = parse_all_from_folder('./PetersSchemeInput/torus')
print "Stuff parsed"

i=0
for vertex in pts:
    i+=1
    if i % 1000 == 0:
        print i
    generate_point(vertex)

print "points plotted"

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

Import.export(__objs__, "./torus_pointcloud.step")
print ".step exported"
Beispiel #8
0
	def createNetwork(self, bcsModelFile):
		rules, state = Import.import_model(bcsModelFile)
		for rule in rules:
			self.addEdge(rule.getLeftHandSide(), rule.getRightHandSide(), rule)
		self.introduceNewAgents(state)
		return state
def create_grating(slit_l,slit_h,slit_p,strut_w,num_col,num_row,fillet,col_or_ash):
    # Input Dimensions #
    strut_h = slit_h
    film_mrgn = strut_w*10
    film_w = (slit_l + strut_w)*num_col-strut_w+2*film_mrgn
    film_h = (slit_h + slit_p)*num_row-strut_h+2*film_mrgn
    
    # Create new document #
    doc = FreeCAD.newDocument("myDoc")
    
    # Create Film #
    film = Draft.makeRectangle(film_w,film_h)
    film.Label = 'myFilm'
    move_film = FreeCAD.Vector(-film_mrgn,-film_mrgn,0)
    Draft.move(film,move_film)
    
    # Create single slit #
    slit = Draft.makeRectangle(slit_l,slit_h)
    slit.Label = 'mySlit'
    long_slit = (slit_l+strut_w)*num_col-strut_w
    
    # Fillet #
    slit.FilletRadius = slit_h/2.01*fillet
        
    if col_or_ash == 1:
        '''COLUMNAR FORM'''
        # Slit Matrix #
        array = Draft.makeArray(slit,FreeCAD.Vector(slit_l+strut_w,0,0),\
                                FreeCAD.Vector(0,slit_h+slit_p,0),num_col,num_row)
        grating = cut_soowon(film,array)
        
    elif col_or_ash == 2:
        '''ASHLAR FORM'''
        # Slit Matrix #
        row_arr1 = int(math.ceil(num_row/2.))
        row_arr2 = int(math.floor(num_row/2.))
        
        array1 = Draft.makeArray(slit,FreeCAD.Vector(slit_l+strut_w,0,0),\
                                 FreeCAD.Vector(0,2*(slit_h+slit_p),0),num_col,row_arr1)
        array2 = Draft.makeArray(slit,FreeCAD.Vector(slit_l+strut_w,0,0),\
                                 FreeCAD.Vector(0,2*(slit_h+slit_p),0),num_col-1,row_arr2)
        #edge_l = (slit_l-strut_w)/2
        #edge = Draft.makeRectangle(edge_l,slit_h)
        #edge.FilletRadius = slit_h/2.01*fillet
        #edge_array = Draft.makeArray(edge,FreeCAD.Vector(long_slit-edge_l,0,0),\
        #                             FreeCAD.Vector(0,2*(slit_h+slit_p),0),2,row_arr2)
        
        move_array2 = FreeCAD.Vector((slit_l+strut_w)/2,slit_h+slit_p,0)
        #move_edge_array = FreeCAD.Vector(0,slit_h+slit_p,0)
        Draft.move(array2,move_array2)
        #Draft.move(edge_array,move_edge_array)

        step1 = cut_soowon(film,array1)
        grating = cut_soowon(step1,array2)
        #step2 = cut_soowon(step1,array2)
        #grating = cut_soowon(step2,edge_array)

    elif col_or_ash == 3:
        num_strut = num_col - 1
        grating = film
        for x in xrange(1,num_row+1):
            
            pseudo_strut = random.randint(num_strut-int(math.ceil(num_strut/2.)),\
                                          num_strut+int(math.ceil(num_strut/2.)))
            new_slit_l = (long_slit- pseudo_strut*strut_w)/(pseudo_strut+1)
            new_slit = Draft.makeRectangle(new_slit_l,slit_h)
            new_slit.FilletRadius = slit_h/2.01*fillet

            move_new_slit = FreeCAD.Vector(0,(x-1)*(slit_h+slit_p),0)
            Draft.move(new_slit,move_new_slit)
            array = Draft.makeArray(new_slit,FreeCAD.Vector(new_slit_l+strut_w,0,0), \
                                             FreeCAD.Vector(0,slit_h+slit_p,0),(pseudo_strut+1),1)
            grating = cut_soowon(grating,array)

    elif col_or_ash == 4:
        '''This function randomize the starting point of the strut on columnar form but maintaining
        strut density'''
        sigma = 0.01 #Standard Deviation: 10 nm #
        for x in xrange(1,num_row+1):
            first_slit_l = random.gauss(slit_l, sigma)
            if first_slit_l < slit_l:
                last_slit_l = slit_l - first_slit_l
            else:
                last_slit_l = 2*slit_l - first_slit_l
                first_slit_l = first_slit_l - slit_l

            first_slit = Draft.makeRectangle(first_slit_l,slit_h)

            move_first = FreeCAD.Vector(0, (x-1)*(slit_h+slit_p) ,0)

            Draft.move(first_slit,move_first)
            
            middle_array = Draft.makeArray(slit,FreeCAD.Vector(slit_l+strut_w,0,0),\
                                 FreeCAD.Vector(0,1,0),num_col-1,1)

            move_middle = FreeCAD.Vector(first_slit_l+strut_w,(x-1)*(slit_h+slit_p),0)

            Draft.move(middle_array,move_middle)

            last_slit = Draft.makeRectangle(last_slit_l,slit_h)

            move_last = FreeCAD.Vector(first_slit_l+(strut_w+slit_l)*(num_col-1)+strut_w,\
                                       (x-1)*(slit_h+slit_p),0)

            Draft.move(last_slit,move_last)
            film = cut_soowon(film,first_slit)
            film = cut_soowon(film,middle_array)
            film = cut_soowon(film,last_slit)
        grating = film

    elif col_or_ash == 5:
        '''RANDOMIZED ASHLAR'''
        sigma = 0.01 #Standard Deviation: 10 nm #
        num_arr1 = int(math.ceil(num_row/2.))
        num_arr2 = num_row - num_arr1

        for x in xrange(1,num_arr1+1):
#            first_slit_l = random.uniform(slit_l-2*strut_w , slit_l+2*strut_w)
#            (long_slit - first_slit_l)
#            if first_slit_l < slit_l:
#                last_slit_l = slit_l - first_slit_l
#            else:
#                last_slit_l = 2*slit_l - first_slit_l
#                first_slit_l = first_slit_l - slit_l

#            first_slit = Draft.makeRectangle(first_slit_l,slit_h)

#            move_first = FreeCAD.Vector(0, (x-1)*2*(slit_h+slit_p) ,0)

#            Draft.move(first_slit,move_first)


            rand_start = random.uniform(-strut_w , strut_w)
            
            array = Draft.makeArray(slit,FreeCAD.Vector(slit_l+strut_w,0,0),\
                                FreeCAD.Vector(0,1,0),num_col,1)
            move_array = FreeCAD.Vector(rand_start,(x-1)*2*(slit_h+slit_p),0)
            Draft.move(array,move_array)
            film = cut_soowon(film,array)
            
#            middle_array = Draft.makeArray(slit,FreeCAD.Vector(slit_l+strut_w,0,0),\
#                                 FreeCAD.Vector(0,1,0),num_col-1,1)

#            middle = FreeCAD.Vector(0,(x-1)*2*(slit_h+slit_p),0)
#            move_middle = FreeCAD.Vector(first_slit_l+strut_w,(x-1)*2*(slit_h+slit_p),0)

#            Draft.move(middle_array,move_middle)

#            last_slit = Draft.makeRectangle(last_slit_l,slit_h)

#            move_last = FreeCAD.Vector(first_slit_l+(strut_w+slit_l)*(num_col-1)+strut_w,\
#                                       (x-1)*2*(slit_h+slit_p),0)

#            Draft.move(last_slit,move_last)
#            film = cut_soowon(film,first_slit)
#            film = cut_soowon(film,middle_array)
#            film = cut_soowon(film,last_slit)
            
            
        for x in xrange(1,num_arr2+1):
            '''edge_l = (slit_l-strut_w)/2
            
            first_slit_l = random.uniform(edge_l-2*strut_w, edge_l+2*strut_w)
            first_slit = Draft.makeRectangle(first_slit_l,slit_h)
            move_first = FreeCAD.Vector(0, (2*x-1)*(slit_h+slit_p) ,0) # move slit to the 2nd layer. Then, move up to every other layer.
            Draft.move(first_slit,move_first)
            
            middle_array = Draft.makeArray(slit,FreeCAD.Vector(slit_l+strut_w,0,0),\
                                 FreeCAD.Vector(0,1,0),num_col-1,1) # Number of slit is going to be one less then the number of column.
            move_middle = FreeCAD.Vector(first_slit_l+strut_w,(2*x-1)*(slit_h+slit_p),0)
            Draft.move(middle_array,move_middle)

            last_slit_l = slit_l - strut_w - first_slit_l
            last_slit = Draft.makeRectangle(last_slit_l,slit_h)
            move_last = FreeCAD.Vector(first_slit_l+(strut_w+slit_l)*(num_col-1)+strut_w,\
                                       (2*x-1)*(slit_h+slit_p),0)
            Draft.move(last_slit,move_last)
            film = cut_soowon(film,first_slit)
            film = cut_soowon(film,middle_array)
            film = cut_soowon(film,last_slit)'''
            rand_start = random.uniform(-strut_w , strut_w)
            
            array = Draft.makeArray(slit,FreeCAD.Vector(slit_l+strut_w,0,0),\
                                FreeCAD.Vector(0,1,0),num_col-1,1)
            move_array = FreeCAD.Vector(rand_start+(slit_l+strut_w)/2,(2*x-1)*(slit_h+slit_p),0)
            Draft.move(array,move_array)
            film = cut_soowon(film,array)
        grating = film

    # Generate geometry #
    FreeCAD.ActiveDocument.recompute()
    
    # Export #
    __objs__=[]
    __objs__.append(grating)
    Import.export(__objs__,"C:/Users/Soowon Kim/Desktop/grating.step")
    del __objs__
Beispiel #10
0
            #Part.show(Part.Vertex(control_point))

    Part.show(patch.toShape())


doc = FreeCAD.newDocument("tmp")
print "Document created"

bq_idx, bq_pts, bc_idx, bc_pts = parse_all_from_folder('./TorusFairBezier')
print "Stuff parsed"

deg = 2
for patch in bq_idx:
    vertices = get_vertices(patch, bq_pts)
    generate_bezier_patch(deg, vertices)

print "biquadratic patches plotted"

deg = 3
patch=bc_idx
for patch in bc_idx:
    vertices = get_vertices(patch, bc_pts)
    generate_bezier_patch(deg, vertices)

print "bicubic patches plotted"

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

Import.export(__objs__, "./FairTorus.step")
print ".step exported"