Can't get sketchText.eplode() method to return curves in Python

Can't get sketchText.eplode() method to return curves in Python

design_oneBETU4
Participant Participant
235 Views
6 Replies
Message 1 of 7

Can't get sketchText.eplode() method to return curves in Python

design_oneBETU4
Participant
Participant

I'm trying to use the python api to explode text objects.

I can access the sketch, and sketchText objects fine, but when I try to explode

 

for txt in new_sketch.sketchTexts:
            curves = txt.explode()
 
I get no curves ('curves' list is empty - len is 0 in debugger)
 
Am I being stupid here?
0 Likes
Accepted solutions (1)
236 Views
6 Replies
Replies (6)
Message 2 of 7

BrianEkins
Mentor
Mentor

I'm unable to reproduce this. I get back a list of the curves. You didn't mention this, but there is one weird behavior of your code. The content of the SketchTexts collection is changing as it iterates over the sketch texts. This is because when you explore the text, it's no longer text so that the collection count will go down by one. One way to handle this is to create a list of the collection's contents and then iterate over the list. Its size won't change.

 

I don't know what you want to do with the curves, but another way to get the curves that make up the text, without disturbing the text, is to use the asCurves method.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 3 of 7

design_oneBETU4
Participant
Participant

Hi Brian

 

Looks like the 'reducing collection' is part of the problem - however there is still an issue of 'not actually exploding'

 

More info;

 

I am creating my sketch by copying text items from another sketch (so as I can export text as a DXF without destrying the original sketch)

 

If I explode the original sketch programatically - it works - curves are created

If I copy the text items to the new sketch and explode - no curves are returned

If I copy the text items to a new sketch, open it - edit it - close it - and then explode programatically - it works

 

So it seems that I am 'not doing something important' having once copied the text items to the new sketch

 

Minimal example of it not working - attached

Requires one sketch with one text item to run

Should create a new sketch with the item copied across (comment out the 'explode' loop at the end to see that it has created the new sketch with a text item)

 

Any help or insight gratefully accepted!

 

Ian B

0 Likes
Message 4 of 7

BrianEkins
Mentor
Mentor

I can confirm there is a problem. It's strange because if I explode the text using the API, after your script has run, it works as expected, but doing it in your script doesn't work.

The behavior I'm seeing is that after the explode, the text is completely gone, so it makes sense that the list is empty since there aren't any curves to return. I'll make sure a bug is logged and let you know if I find any workaround.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 5 of 7

BrianEkins
Mentor
Mentor
Accepted solution

I found a workaround. It seems like when the API copies the text into the new sketch, it's not in a finished state. Performing any edit operation on the sketch gets it into a good state. If you add the following line to just before you do the explode, it will work. Any change to the text fixes the problem, and this change seems the least likely to change anything.

 
txt.isHorizontalFlip = txt.isHorizontalFlip
 
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 6 of 7

design_oneBETU4
Participant
Participant

Hi Brian - well it's nice to know I'm not completely mad!
Thank you.

 

I'm trying to approach it another way in the meantime. Using asCurve() to get a list of curves.

Ive tried adding them to my new sketch using include() - but however I approach it, it throws an exception.

I can't find any example sof how I should be using it - are there any that you know of?

 

Whilst stalled on that I am trying the 'very long hand' process of reading through the list of curves and re-creating them in the new sketch using .sketchFittedSpline.add() - but this is incredibley slow (minutes per sketch - for ony ~200 curves). There must be an easier way of copying a curve from one sketch to another - I feel like there are a few pages missing from my manual. Are there any good references on this stuff - the api reference has examples for everything apart from the methods I wish to use 😞

 

Cheers

 

Ian B

0 Likes
Message 7 of 7

design_oneBETU4
Participant
Participant

Indeed - that works around it!
Seems that explode doesn't then delete the SketchText - but I can handle that 🙂

Many thanks

 

Ian B.

0 Likes