# Macro Apothem Based Prism GUI

Other languages:
English • ‎français • ‎italiano

### Apothem Based Prism

Description
A GUI dialog that creates an Apothem, (inradius) Based Prism from user input.
Author
Quick61
Macros recipes
How to install macros
How to customize toolbars
Version
1.0
Date last modification
2014-12-31

## Apothem Based Prism

This macro will present the user with a dialog to provide the distance between centers, the number of sides, and height and will create a prism based on the apothem, or inradius of a polygon. This can be extremely handy when one only knows the distance between flats. An example of this would be hexagonal stock of plastics or metal provided by vendors. Most vendors define such stock by the distance between flats. If one is using such stock in their projects, this Macro can be a real time saver.

## How To Use

Copy the Macro into your FreeCAD Macro directory. Then either run the macro from the Execute Macro dialog or create a shortcut to use from your custom toolbar.

When run, the Macro wil present the user with a dialog like seen below. First enter the desired distance between flats. This can be any number and can include a decimal value, it will not take fractional input. Next enter the number of sides. This number is a whole number and should be an even number as well for proper results. Lastly enter the height you wish the prism to be. Again, this can be any number and can include a decimal value. Click OK and the prism will be created in your document.

## The Macro

Macro_Apothem_Based_Prism_GUI.FCMacro

```# # # # # # # # # # #
#
# Apothem Based Prism
#
# This script will take the input of the distance between flats, (apothem, aka inradius),
# and the number of sidesfor a regular polygon along with a height and produce a
# correctly sized prism derived from the circumradius.
#
# # # # # # # # # # #

from PySide import QtGui, QtCore

class p():

def priSm(self):

try:
dbf = float(self.d1.text())
nos = int(self.d2.text())
hth = float(self.d3.text())
aR = dbf / 2
op1 = 180/float(nos)
cR = aR / coS
prism.Polygon=nos
prism.Height=hth
prism.Placement=Base.Placement(Base.Vector(0.00,0.00,0.00),Base.Rotation(0.00,0.00,0.00,1.00))
prism.Label='Prism'
App.ActiveDocument.recompute()
Gui.SendMsgToActiveView("ViewFit")
except:

self.close()

def close(self):
self.dialog.hide()

#
# Make dialog box and get input for distance between flats, number of sides, and height
#

def __init__(self):
self.dialog = None

self.dialog = QtGui.QDialog()
self.dialog.resize(280,110)

self.dialog.setWindowTitle("Apothem Based Prism")
la = QtGui.QVBoxLayout(self.dialog)

iN1 = QtGui.QLabel("Distance Between Flats")
self.d1 = QtGui.QLineEdit()

iN2 = QtGui.QLabel("Number Of Sides (Best results - use even numbers)")
self.d2 = QtGui.QLineEdit()

iN3 = QtGui.QLabel("Prism Height")
self.d3 = QtGui.QLineEdit()

okbox = QtGui.QDialogButtonBox(self.dialog)
okbox.setOrientation(QtCore.Qt.Horizontal)
okbox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
QtCore.QObject.connect(okbox, QtCore.SIGNAL("accepted()"), self.priSm)
QtCore.QObject.connect(okbox, QtCore.SIGNAL("rejected()"), self.close)
QtCore.QMetaObject.connectSlotsByName(self.dialog)
self.dialog.show()
self.dialog.exec_()

p() ```