-
Notifications
You must be signed in to change notification settings - Fork 436
Add Text box method #2025
Copy link
Copy link
Open
Description
I worked out a way to do text boxes. Happy to put in a PR if you have a place that this would be best in, This is a lazy method for doing text wrapping in the form of text boxes.
For example if you have a long string you want to put on the back of an object before printing. Rather then having to manually add the returns this will figure out where the line breaks would have to be and put them in.
I have not looked into your formating, but the example for a text box would look like this
def textbox(width,thickness,text,font,size,plane="XZ",halign="left"):
lines = text.split("\n")
endLines=[]
finalText=cq.Workplane("XZ")
for line in lines:
curLen=0
tempText = ""
bb=cq.Workplane("XZ").text(line,size,thickness,font=font).val().BoundingBox()
average_per_char=(bb.xmax - bb.xmin)/len(line)
characterCutOff=int(width/average_per_char)
for word in line.split(" "):
if len(tempText)+len(word)>characterCutOff:
endLines.append(tempText)
tempText = word+" "
else:
tempText+=word+" "
endLines.append(tempText)
final_string = "\n".join(endLines)
finalText=cq.Workplane(plane).text(final_string,size,thickness,font=font,halign=halign)
return finalText
show_object(textbox(200,0.3,"this is a long string, sort of a runon sentence, the point is to get extra lines.","impact",20))
If it is something that would be value added, let me know. If not i will keep it in an external library.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels