Win = Windows()
Units.Current = UnitTypes.Inches
MyPart = CurrentPart()
question = True
ScriptName = 'Equal Distant Points On Spline'
t = 0
while question == True:
# create dialog window and show to user
Options = []
Options.append([None, WindowsInputTypes.Image, "MLogo.png", 40])
Options.append(['Source Sketch', WindowsInputTypes.Sketch, None])
Values = Win.OptionsDialog("Select Sketch That Contains Spline", Options, 340)
if Values == None:
sys.exit()
# get user inputs
SketchSelect = str(Values[1])
#Acivate Sketch
MySketch = MyPart.GetSketch(SketchSelect)
#List of Figures in sketch
Fig = len(MySketch.Figures)
#input the spline figure to subdivide
bsplines = []
print "\n\n\n\n\n Begin of Sketch Figure List"
for index, figure in enumerate(MySketch.Figures):
if isinstance(figure, Bspline):
print "Bspline # " + str(index+1) + "---" + str(figure)
bsplines.append(str(index+1))
print " End of Sketch Figure List"
Options = []
Options.append(['Enter the figure number of the Bspline to divide', WindowsInputTypes.StringList, bsplines])
Values = Win.OptionsDialog(ScriptName, Options, 170)
if Values == None:
sys.exit()
FigureNumber = int(bsplines[Values[0]])
LOS = MySketch.Figures[FigureNumber-1].Length
SINFO = str(MySketch.Figures[FigureNumber-1])
Win.InfoDialog("Length "+ str(round(LOS, 2))+" Inches"+ "\n"+ SINFO, "Info for BSpline # "+str(FigureNumber))
Options.append(['Number of equal distant divides along Bspline', WindowsInputTypes.Integer, None])
Values = Win.OptionsDialog("Select Figure and Number of Divides Along Bspline", Options, 170)
if Values == None:
sys.exit()
Segments = Values[1]
if Segments < 2:
Win.ErrorDialog("Specify at least 2 segments", "ERROR")
sys.exit()
#Divide Bspline into equal lengths
SP = MySketch.Figures[FigureNumber-1].Subdivide(Segments)
SPBegin = MySketch.Figures[FigureNumber-1].GetPointAt(0.0)
SPEnd = MySketch.Figures[FigureNumber-1].GetPointAt(1)
WOS = MySketch.Figures[FigureNumber-1].Weights
OOS = MySketch.Figures[FigureNumber-1].Order
CPS = MySketch.Figures[FigureNumber-1].ControlPoints
KVS = MySketch.Figures[FigureNumber-1].KnotVectors
#print "my weights are"
#print WOS
#print "order number"
#print OOS
#print "control points"
#print CPS
#print "knot Vectors"
#print KVS
#Set the range number requires X and Y List to be doubled
NumberOfDivides = Segments-1
previous_points = MyPart.GetUserData("mohrcomposites.data.spline_"+str(FigureNumber))
previous_points = None
if previous_points is not None:
#I WANTED TO REMOVE THE PREVIOUS POINTS BUT THERE IS NOT FUNCTION ON SKETCH!!!!
Win.ErrorDialog("You already subdivided bspline " + str(FigureNumber) + ". Segments:" + str(previous_points["segments"]), "ERROR")
else:
points=[]
for i in range(0, NumberOfDivides):
MySketch.AddPoint(SP[t], (SP[t+1]))
t = t+2
t = 0
MySketch.AddPoint(SPBegin[0], SPBegin[1])
MySketch.AddPoint(SPEnd[0], SPEnd[1])
# MyPart.SetUserData("mohrcomposites.data.spline_"+str(FigureNumber),{"points":points})
MyPart.SetUserData("mohrcomposites.data.spline_"+str(FigureNumber),{"segments":Segments})
Win.InfoDialog("Bspline "+str(FigureNumber)+" selected "+"\nDivided in "+str(Segments)+" sections","COMPLETED")
question = Win.QuestionDialog("Continue Dividing Splines?", "Finished?")
sys.exit()
### 'Equal Distant Points On Spline'
### https://www.alibre.com/forum/index.php?threads/figures.23994/
Win = Windows()
Units.Current = UnitTypes.Inches
MyPart = CurrentPart()
question = True
ScriptName = 'Equal Distant Points On Spline'
t = 0
while question == True:
# create dialog window and show to user
Options = []
Options.append([None, WindowsInputTypes.Image, "MLogo.png", 40])
Options.append(['Source Sketch', WindowsInputTypes.Sketch, None])
Values = Win.OptionsDialog("Select Sketch That Contains Spline", Options, 340)
if Values == None:
print('User Canceled')
sys.exit()
if not any(Values):
print('Nothing Selected')
sys.exit()
# get user inputs
MySketch = Values[1]
#input the spline figure to subdivide
bsplines = []
print "\n\n\n\n\n Begin of Sketch Figure List"
for index, figure in enumerate(MySketch.Figures):
if isinstance(figure, Bspline):
print "Bspline # " + str(index+1) + "---" + str(figure)
bsplines.append(index+1)
print " End of Sketch Figure List"
if not any(bsplines):
print('No bsplines in this sketch')
sys.exit()
Options = []
Options.append(['Enter the figure number of the Bspline to divide', WindowsInputTypes.Integer, 1])
Values = Win.OptionsDialog(ScriptName, Options, 170)
if Values == None:
print('User Canceled')
sys.exit()
if not any(Values):
print('Nothing Selected')
sys.exit()
if Values[0] not in bsplines:
print('Not a valid bspline figure')
sys.exit()
FigureNumber = Values[0]
LOS = MySketch.Figures[FigureNumber-1].Length
SINFO = str(MySketch.Figures[FigureNumber-1])
InfoString = "Info for BSpline # " + str(FigureNumber) + "\nLength "+ str(round(LOS, 2))+" Inches"+ "\n"+ str(SINFO)
Options = []
Options.append(['Label', WindowsInputTypes.Label, InfoString])
Options.append(['Number of equal distant divides along Bspline', WindowsInputTypes.Integer, 2])
Options.append(['Erase Spline figure when done', WindowsInputTypes.Boolean, 0])
Values = Win.OptionsDialog("Select Figure and Number of Divides Along Bspline", Options, 170)
if Values == None:
print('User Canceled')
sys.exit()
if not any(Values):
print('Nothing Selected')
sys.exit()
Segments = Values[1]
EraseSpline = Values[2]
if Segments < 2:
Win.ErrorDialog("Specify at least 2 segments", "ERROR")
sys.exit()
#Divide Bspline into equal lengths
SplineFigure = MySketch.Figures[FigureNumber-1]
SP = SplineFigure.Subdivide(Segments)
SPBegin = SplineFigure.GetPointAt(0.0)
SPEnd = SplineFigure.GetPointAt(1)
WOS = SplineFigure.Weights
OOS = SplineFigure.Order
CPS = SplineFigure.ControlPoints
KVS = SplineFigure.KnotVectors
#print "my weights are"
#print WOS
#print "order number"
#print OOS
#print "control points"
#print CPS
#print "knot Vectors"
#print KVS
#Set the range number requires X and Y List to be doubled
NumberOfDivides = Segments-1
previous_points = MyPart.GetUserData("mohrcomposites.data.spline_"+str(FigureNumber))
previous_points = None
if previous_points is not None:
#I WANTED TO REMOVE THE PREVIOUS POINTS BUT THERE IS NOT FUNCTION ON SKETCH!!!!
Win.ErrorDialog("You already subdivided bspline " + str(FigureNumber) + ". Segments:" + str(previous_points["segments"]), "ERROR")
else:
points=[]
for i in range(0, NumberOfDivides):
MySketch.AddPoint(SP[t], (SP[t+1]))
t = t+2
t = 0
MySketch.AddPoint(SPBegin[0], SPBegin[1])
MySketch.AddPoint(SPEnd[0], SPEnd[1])
# If EraseSpline was selected this will use the undocumented
# Alibre Script / AlibreX API connection to delete the
# spline figure from the sketch.
if EraseSpline:
objSplineFigure = SplineFigure.FigureObject()
objSketch = objSplineFigure.Sketch
try:
objSketch.BeginChange()
except:
print "Unexpected error:", sys.exc_info()[0]
pass
objSplineFigure.Delete()
try:
objSketch.EndChange()
except:
print "Unexpected error:", sys.exc_info()[0]
pass
# MyPart.SetUserData("mohrcomposites.data.spline_"+str(FigureNumber),{"points":points})
MyPart.SetUserData("mohrcomposites.data.spline_"+str(FigureNumber),{"segments":Segments})
Win.InfoDialog("Bspline "+str(FigureNumber)+" selected "+"\nDivided in "+str(Segments)+" sections","COMPLETED")
question = Win.QuestionDialog("Continue Dividing Splines?", "Finished?")
sys.exit()
print(dir(whatever_object))
#or
print(help(whatever_object))