- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Can someone recommend an approach to creating an outline (offset) around every text character in a sketch?
Here's what I'm trying to do. If I have sketched text like "test", I want to be able to create an outline around each character in "test".
So far my Python script explodes the sketch text, then I try looping through the profiles to create the offset for each character. The first offset gets created correctly as you can see in the screenshot. The problem is after that the profiles get recalculated automatically, which is messing things up.
Any suggestion on how to accomplish this? I suspect I shouldn't be trying to do this through the profiles as they're constantly recalculated.
Here's the error:
My code:
import adsk.core, adsk.fusion, traceback, time
def run(context):
ui = None
try:
text_height = 02.1
app = adsk.core.Application.get()
ui = app.userInterface
doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
design = adsk.fusion.Design.cast( app.activeProduct )
#Prompts the user for the new Text
(returnValue, cancelled) = ui.inputBox( 'What text?', 'New text:', )
# Get the root component of the active design.
rootComp = design.rootComponent
allOccs = rootComp.occurrences
transform = adsk.core.Matrix3D.create()
# Create a component under root component
occ1 = allOccs.addNewComponent(transform)
subComp1 = occ1.component
# this will be the component for the text
subComp1.name = '{} - Arial'.format( returnValue )
# Create a sketch in subComp 1
sketches1 = subComp1.sketches
sketch1 = sketches1.add(rootComp.xYConstructionPlane)
# Get sketch texts
sketchTexts = sketch1.sketchTexts
# Create sketch text input
point = adsk.core.Point3D.create(1.0, 1.0, 0)
sketchTextInput = sketchTexts.createInput( returnValue, 1.0, point)
sketchTextInput.fontName = 'Arial'
sketchTextInput.height = text_height
# Create sketch text
sketchText = sketchTexts.add(sketchTextInput)
# Explode the text
sketchCurves = sketchText.explode()
curvesForOffset = adsk.core.ObjectCollection.create()
i = 0
profile = adsk.fusion.Profile.cast(None)
for profile in sketch1.profiles:
curvesForOffset.clear() # clear the collection
loop = profile.profileLoops.item(0)
curves = loop.profileCurves
for curve in curves:
curve = adsk.fusion.ProfileCurve.cast(curve)
entity = curve.sketchEntity
curvesForOffset.add( entity )
if curvesForOffset.count > 0:
sketch1.offset(curvesForOffset, adsk.core.Point3D.create(0,0,0), .3 )
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Solved! Go to Solution.