コード例 #1
0
 def make_outline(self, fp): 
     self.updating = True 
     
     if fp.Method == 'normal': 
         outline = fp.Part.Shape.makeOffsetShape(fp.BeamWidth / 2, 1e-7)
     elif fp.Method == '2D':
         outline = fp.Part.Shape.makeOffset2D(fp.BeamWidth / 2) 
         fp.Normal = self.getNormal(fp.Part) 
     elif fp.Method == '3D':
         outline = fp.Part.Shape.makeOffsetShape(fp.BeamWidth / 2, 1e-7)
         fp.Normal = self.getNormal(fp.Part) 
     else:
         face = self.get_biggest_face(fp.Part)
         if face:
             outline = face.makeOffset2D(fp.BeamWidth / 2)
             fp.Normal = face.normalAt(0, 0)
         elif fp.Method == 'auto':
             try:
                 outline = fp.Part.Shape.makeOffset2D(fp.BeamWidth / 2) 
             except Exception as ex:
                 outline = fp.Part.Shape.makeOffsetShape(fp.BeamWidth / 2, 1e-7)   
                 
             fp.Normal = self.getNormal(fp.Part)   
         
     fp.Shape = Part.Compound(outline.Wires);
     fp.Label = fp.Part.Label + ' offset'
     fp.Placement = outline.Placement
     
     if fp.Placement.Rotation.Axis.z < 0:
         fp.Placement.Rotation.Axis = fp.Placement.Rotation.Axis * -1
     
     if fp.Method != 'normal':      
         if fp.Normal.z < 0:
             fp.Normal = fp.Normal * -1
             
         rotation_to_apply = Rotation(fp.Normal, Vector(0, 0, 1))    
         new_rotation = rotation_to_apply.multiply(fp.Placement.Rotation)
         fp.Placement.Rotation = new_rotation
     
         self.rotate_biggest_side_up(fp)
         
     self.updating = False
コード例 #2
0
 def rotate_biggest_side_up(self, fp):
     bbox = fp.Shape.optimalBoundingBox()
     xmin = bbox.XLength
     angle = 0.0
     r = fp.Placement.Rotation
     r_best = r
     step = 180 / 16
     while angle + step < 180:   
         angle = angle + step 
         rotation_to_apply = Rotation()
         rotation_to_apply.Axis = Vector(0, 0, 1)             
         rotation_to_apply.Angle = math.radians(angle)              
         fp.Placement.Rotation = rotation_to_apply.multiply(r)
         bbox = fp.Shape.optimalBoundingBox()
 
         if xmin > bbox.XLength:
             xmin = bbox.XLength
             r_best = fp.Placement.Rotation
              
     fp.Placement.Rotation = r_best