Hi All
Please take a look at what I thought was a simple script using rs.AddAlignedDimension when the script runs all 90 degree dims are ok as are the 45 and 135 degree but the 225 and 315 are not aligned but are square dimensions.
I have listed the script and attached model with the points I was using.
curves.3dm (159.5 KB)
#! python3
import Rhino
import Rhino.UI
import scriptcontext as sc
import System
import Eto.Drawing as drawing
import Eto.Forms as forms
import rhinoscriptsyntax as rs
from System.Drawing import Color
from decimal import Decimal
import math
pi = math.pi
import operator
#surfaces = []
JobNum = []
#Plane = []
NewLayer = []
Font = []
#Tol = []
#Thk = []
#maxDist = []
#VecScale = []
ModScale = []
NumDp = []
Spoints = []
Names = []
number = 1
Origls = []
curves = []
#Geo Vectors Points dialog class
class GeoAssociateDialog(forms.Dialog[bool]):
# Dialog box Class initializer
def __init__(self):
# call base class initializer
super().__init__()
# Initialize dialog box
self.Title = "Geo Label Curve Length"
self.Padding = drawing.Padding(10)
self.Resizable = False
# Create Radio Button List Control
#self.m_radiobuttonlist = forms.RadioButtonList()
#self.m_radiobuttonlist.DataStore = ['No Plane', 'Fit Plane']
#self.m_radiobuttonlist.Orientation = forms.Orientation.Horizontal
#self.m_radiobuttonlist.SelectedIndex = 0
# Create controls for the dialog
self.m_label1 = forms.Label()
self.m_label1.Text = "Job Number:"
self.m_JobNum_textbox = forms.TextBox()
self.m_JobNum_textbox.Text = "SC-000"
#self.m_JobNum_textbox = forms.TextBox(Text = "")
self.m_label2 = forms.Label()
self.m_label2.Text = "New Layer:"
self.m_NewLayer_textbox = forms.TextBox()
self.m_NewLayer_textbox.Text = "Curve Length"
#self.m_NewLayer_textbox = forms.TextBox(Text = "")
#self.m_label3 = forms.Label()
#self.m_label3.Text = "maxDist mm:"
#self.m_maxDist_textbox = forms.TextBox()
#self.m_maxDist_textbox.Text = ""
#self.m_label4 = forms.Label()
#self.m_label4.Text = "Thickness mm:"
#self.m_Thickness_textbox = forms.TextBox()
#self.m_Thickness_textbox.Text = ""
self.m_label5 = forms.Label()
self.m_label5.Text = "Font Size mm:"
self.m_Font_textbox = forms.TextBox()
self.m_Font_textbox.Text = ""
#self.m_label6 = forms.Label()
#self.m_label6.Text = "Vector Scale:"
#self.m_VectScale_textbox = forms.TextBox()
#self.m_VectScale_textbox.Text = "3"
#self.m_label7 = forms.Label()
#self.m_label7.Text = "Tol mm:"
#self.m_Tol_textbox = forms.TextBox()
#self.m_Tol_textbox.Text = "8"
self.m_label8 = forms.Label()
self.m_label8.Text = "Model Space Scale:"
self.m_ModScale_textbox = forms.TextBox()
self.m_ModScale_textbox.Text = "15"
self.m_NumDp_combobox = forms.ComboBox()
self.m_NumDp_combobox.DataStore = ['NumDP0', 'NumDP1', 'NumDP2']
self.m_NumDp_combobox.SelectedIndex = 0
self.m_label = forms.Label()
self.m_label.Text = "Decimal Places:"
# Create the default button
self.DefaultButton = forms.Button()
self.DefaultButton.Text = 'OK'
self.DefaultButton.Click += self.OnOKButtonClick
# Create the abort button
self.AbortButton = forms.Button()
self.AbortButton.Text = 'Cancel'
self.AbortButton.Click += self.OnCloseButtonClick
# Create a table layout and add all the controls
layout = forms.DynamicLayout()
layout.Spacing = drawing.Size(5, 5)
#layout.AddRow(self.m_JobNum_textbox)
#layout.AddRow(self.m_label, self.m_radiobuttonlist)
#layout.AddRow(self.m_label, self.m_Layers_listbox)
#layout.AddRow(self.m_JobNum_textbox)
layout.AddRow(self.m_label1, self.m_JobNum_textbox)
#layout.AddRow(self.m_NewLayer_textbox)
layout.AddRow(self.m_label2, self.m_NewLayer_textbox)
#layout.AddRow(self.m_label3, self.m_maxDist_textbox)
#layout.AddRow(self.m_label4, self.m_Thickness_textbox)
layout.AddRow(self.m_label5, self.m_Font_textbox)
#layout.AddRow(self.m_label6, self.m_VectScale_textbox)
#layout.AddRow(self.m_label7, self.m_Tol_textbox)
layout.AddRow(self.m_label8, self.m_ModScale_textbox)
layout.AddRow(self.m_label, self.m_NumDp_combobox)
layout.AddRow(None) # spacer
layout.AddRow(self.DefaultButton, self.AbortButton)
# Set the dialog content
self.Content = layout
self.Load += self.OnFormLoad
self.Closing += self.OnFormClosing
# Start of the class functions
# Get the value of the textbox
#def GetText20(self):
#return self.m_Layers_listtbox.SelectedIndex
def GetText1(self):
return self.m_JobNum_textbox.Text
def GetPlane(self):
return self.self.m_radiobuttonlist.SelectedIndex
def GetText2(self):
return self.m_NewLayer_textbox.Text
def GetText3(self):
return self.m_maxDist_textbox.Text
def GetText4(self):
return self.m_Thickness_textbox.Text
def GetText5(self):
return self.m_Font_textbox.Text
def GetText6(self):
return self.m_VectScale_textbox.Text
def GetText7(self):
return self.m_Tol_textbox.Text
def GetText8(self):
return self.m_ModScale_textbox.Text
# Get/set the value of the combobox
def GetNumDp(self):
return self.m_NumDp_combobox.SelectedIndex
#def SetNumDp(self, index):
#self.m_NumDp_combobox.SelectedIndex = Rhino.RhinoMath.Clamp(index, 0, 2)
# Close button click handler
def OnCloseButtonClick(self, sender, e):
self.Close(False)
# OK button click handler
def OnOKButtonClick(self, sender, e):
self.Close(True)
def OnFormLoad(self, sender, e):
# set previous or default text for "Job Number"
if sc.sticky.has_key("Job Number"):
# set last used text if found in sticky
self.m_JobNum_textbox.Text = sc.sticky["Job Number"]
else:
# set default text if not not found in sticky
self.m_JobNum_textbox.Text = "SC-000"
#if sc.sticky.has_key("Plane"):
#self.m_radiobuttonlist.SelectedIndex = sc.sticky["Plane"]
#else:
#self.m_radiobuttonlist.SelectedIndex = 0
if sc.sticky.has_key("New Layer"):
# set last used text if found in sticky
self.m_NewLayer_textbox.Text = sc.sticky["New Layer"]
else:
# set default text if not not found in sticky
self.m_NewLayer_textbox.Text = "Curve Length"
#if sc.sticky.has_key("maxDist"):
# set last used text if found in sticky
#self.m_maxDist_textbox.Text = sc.sticky["maxDist"]
#else:
# set default text if not not found in sticky
#self.m_maxDist_textbox.Text = "50"
#if sc.sticky.has_key("Thickness"):
# set last used text if found in sticky
#self.m_Thickness_textbox.Text = sc.sticky["Thickness"]
#else:
# set default text if not not found in sticky
#self.m_Thickness_textbox.Text = "0"
if sc.sticky.has_key("Font Size"):
# set last used text if found in sticky
self.m_Font_textbox.Text = sc.sticky["Font Size"]
else:
# set default text if not not found in sticky
self.m_Font_textbox.Text = "100"
#if sc.sticky.has_key("Vect Scale"):
# set last used text if found in sticky
#self.m_VectScale_textbox.Text = sc.sticky["Vect Scale"]
#else:
# set default text if not not found in sticky
#self.m_VectScale_textbox.Text = "3"
#if sc.sticky.has_key("Tol"):
# set last used text if found in sticky
#self.m_Tol_textbox.Text = sc.sticky["Tol"]
#else:
# set default text if not not found in sticky
#self.m_Tol_textbox.Text = "8"
if sc.sticky.has_key("Model Space Scale"):
# set last used text if found in sticky
self.m_ModScale_textbox.Text = sc.sticky["Model Space Scale"]
else:
# set default text if not not found in sticky
self.m_ModScale_textbox.Text = "1"
def OnFormClosing(self, sender, e):
# store the text from the text box in sticky (it can be empty)
sc.sticky["Job Number"] = self.m_JobNum_textbox.Text
#sc.sticky["Plane"] = self.m_radiobuttonlist.SelectedIndex
# store the text from the text box in sticky (it can be empty)
sc.sticky["New Layer"] = self.m_NewLayer_textbox.Text
# store the text from the text box in sticky (it can be empty)
#sc.sticky["maxDist"] = self.m_maxDist_textbox.Text
# store the text from the text box in sticky (it can be empty)
#sc.sticky["Thickness"] = self.m_Thickness_textbox.Text
# store the text from the text box in sticky (it can be empty)
sc.sticky["Font Size"] = self.m_Font_textbox.Text
# store the text from the text box in sticky (it can be empty)
#sc.sticky["Vect Scale"] = self.m_VectScale_textbox.Text
# store the text from the text box in sticky (it can be empty)
#sc.sticky["Tol"] = self.m_Tol_textbox.Text
# store the text from the text box in sticky (it can be empty)
sc.sticky["Model Space Scale"] = self.m_ModScale_textbox.Text
def RadialDimensions():
# Utility function to show the dialog box
# The script that will be using the dialog.
dialog = GeoAssociateDialog();
#Open the dialogue
rc = dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)
if not rc: return
#Plane = str(dialog.m_radiobuttonlist.SelectedIndex)
#print ("Plane Fit", Plane)
JobNum = str(dialog.m_JobNum_textbox.Text)
print ("JobNum", JobNum)
NewLayer = str(dialog.m_NewLayer_textbox.Text)
print ("NewLayer", NewLayer)
#maxDist = str(dialog.m_maxDist_textbox.Text)
#print ("maxDist", maxDist)
#Thk = str(dialog.m_Thickness_textbox.Text)
#print ("Thickness", Thk)
Font = int(dialog.m_Font_textbox.Text)
print ("Font", Font)
#VecScale = str(dialog.m_VectScale_textbox.Text)
#print ("VecScale", VecScale)
#Tol = str(dialog.m_Tol_textbox.Text)
#print ("Tolerance to Design", Tol)
ModScale = int(dialog.m_ModScale_textbox.Text)
print ("Model Space Scale", ModScale)
NumDp = int(dialog.m_NumDp_combobox.SelectedIndex)
print ("Number of Decimal Places", NumDp)
#surfaces = []
rs.AddLayer(str(JobNum))
rs.AddLayer(str(NewLayer),Color.Yellow, parent = str(JobNum))
rs.CurrentLayer(str(NewLayer))
#objs = rs.GetObjects("Pick some curves", rs.filter.curve)
rs.CurrentDimStyle("Default")
rs.DimStyleScale("Default", ModScale)
#rs.ObjectLayer(obj, NewLayer)
if NumDp == 0:
#rs.CurrentDimStyle("Dp0")
#rs.DimStyleScale("Dp0", modscale)
rs.DimStyleLinearPrecision("Default", 0)
#precision = 3
#rs.UnitDistanceDisplayPrecision( 0 )
elif NumDp == 1:
#rs.CurrentDimStyle("Dp1")
#rs.DimStyleScale("Dp1", modscale)
rs.DimStyleLinearPrecision("Default", 1)
#precision = 3
#rs.UnitDistanceDisplayPrecision( 1 )
elif NumDp == 2:
#rs.CurrentDimStyle("Dp2")
#rs.DimStyleScale("Dp2", modscale)
rs.DimStyleLinearPrecision("Default", 2)
#precision = 3
#rs.UnitDistanceDisplayPrecision( 2 )
#print("Object identifier: {}".format(objectId))
cpId = rs.GetObject("Pick the centre point", rs.filter.point)
cpIdc = rs.PointCoordinates(cpId)
if not cpIdc:
return
#print(cpIdc)
rdIds = rs.GetObjects("Pick the radial points", rs.filter.point)
#rdIds = rs.GetPointCoordinates("Pick the radial points")
if not rdIds:
return
print(rdIds)
rs.CurrentView("Top")
if rdIds:
for rdId in rdIds:
rdIdc = rs.PointCoordinates(rdId)
mid = rs.PointAdd(rdIdc, cpIdc)/2
rs.AddPoint(mid)
aDim = rs.AddAlignedDimension( cpIdc, rdIdc, mid, "Default" )
#point = rs.CurveMidPoint(obj)
print ("End of Radial Dimensions")
# Check to see if this file is being executed as the "main" python
# script instead of being used as a module by some other python script
# This allows us to use the module which ever way we want.
if __name__ == "__main__":
rc = RadialDimensions()