<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Sketch with text via API not exporting text but will manually in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/sketch-with-text-via-api-not-exporting-text-but-will-manually/m-p/11840020#M4158</link>
    <description>&lt;P&gt;You are a wonder to behold!&amp;nbsp; You have nailed the issue, I have been working on this and you just brought it to a resolution, bless you!!&amp;nbsp; Yes, so right you are I spoke with the developers and they will explode the text in sketches so the API will not have too.&amp;nbsp; Would not have gotten here without your help, thank you!!&lt;/P&gt;</description>
    <pubDate>Wed, 22 Mar 2023 18:03:09 GMT</pubDate>
    <dc:creator>marylou.forsyth</dc:creator>
    <dc:date>2023-03-22T18:03:09Z</dc:date>
    <item>
      <title>Sketch with text via API not exporting text but will manually</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/sketch-with-text-via-api-not-exporting-text-but-will-manually/m-p/11836803#M4156</link>
      <description>&lt;P&gt;Good day programmers!&amp;nbsp; I am asking for help as I am just not seeing what steps I am missing.&amp;nbsp; Please let me give the background.&amp;nbsp; We open a model via API script, we read in new parameters to update the model to, and update the model.&amp;nbsp; All processing is done via the API script.&amp;nbsp; My customer has requested a specific type of processing done, where the model has a few sketches, to delete all sketches not named in a list, and export the model as a DXF.&amp;nbsp; The logic I wrote to address this can be identified as the DXF_Type_BPB (for it needs to be a DXF export with only the Body, Pen_lines and Bend_Lines {BPB})&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The logic goes through and removes the sketches not needed, then exports out a file with just the pen-line (so I can verify in testing which actually looks great) and then exports out the body and the one sketch Pen_Line.&amp;nbsp; My problem is when the second export happens, I don't see the text.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The manual export (fullPath + sketch.name + 'dxf') which is looking ok to me appears as this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="marylouforsyth_0-1679412485239.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1191446iD3B07A92CB42A395/image-size/medium?v=v2&amp;amp;px=400" role="button" title="marylouforsyth_0-1679412485239.png" alt="marylouforsyth_0-1679412485239.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;and at the top you can see the text data 'HV something'.&lt;/P&gt;&lt;P&gt;The export with the body, Pen_line though only creates this as I must be missing something major:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="marylouforsyth_1-1679412590961.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1191447iEFE6AC200DBB72FC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="marylouforsyth_1-1679412590961.png" alt="marylouforsyth_1-1679412590961.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Here is the code (please ignore the section that says else: DXF_Type_BPB == False ) AND please forgive the horrible loop where I flush out the un-needed sketches, it will be re-written.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I thought this line was going to give what I needed but sadly no:&lt;/P&gt;&lt;P&gt;[sketchEntities.add(ent) for ent in sketch.sketchTexts]&lt;/P&gt;&lt;P&gt;One more thing, there is logic to adjust the scaling but thats been working fine.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#we call this right before the code in question --&amp;gt; : updateParametricModel(tag,value,userParams,False)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;else: # its a punch so export the drawing scaled correctly&lt;BR /&gt;global DXF_Type_BPB&lt;BR /&gt;# flag if problem of no cam found when making a DXF&lt;BR /&gt;Stop_it = False&lt;/P&gt;&lt;P&gt;folder = "W:\\SharedData\\Fusion_360\\DXF\\"&lt;BR /&gt;fullPath = os.path.join(folder, order)&lt;BR /&gt;&lt;BR /&gt;if (DXF_Type_BPB == True):&lt;BR /&gt;Total_Count_Sketches = 0&lt;BR /&gt;targetSketches = ['Pen_Line','Pen_line','pen_line','Bend_Line','Bend_line','bend_line']&lt;BR /&gt;DFX_Generated = True&lt;BR /&gt;design : adsk.fusion.Design = app.activeProduct&lt;BR /&gt;root: adsk.fusion.Component = design.rootComponent&lt;BR /&gt;master: adsk.fusion.Sketch = root.sketches.add(root.xYConstructionPlane)&lt;BR /&gt;rootComp: adsk.fusion.Component = design.rootComponent&lt;/P&gt;&lt;P&gt;#### Check names of all sketches&lt;BR /&gt;#sketches = rootComp.sketches&lt;BR /&gt;#sketch_names = []&lt;BR /&gt;#i1 = 0&lt;BR /&gt;#for sk in sketches:&lt;BR /&gt;# print(str(sketches.item(i1).name))&lt;BR /&gt;# i1 = i1 + 1&lt;BR /&gt;#####&lt;/P&gt;&lt;P&gt;sketches = rootComp.sketches&lt;BR /&gt;sketch_names = []&lt;BR /&gt;Kludge_Counter = 0&lt;BR /&gt;Not_done = False&lt;BR /&gt;while Not_done == False:&lt;BR /&gt;Kludge_Counter = Kludge_Counter + 1&lt;BR /&gt;if (Kludge_Counter &amp;gt; 20):&lt;BR /&gt;Not_done = True&lt;BR /&gt;i1 = 0&lt;BR /&gt;for sk in sketches:&lt;BR /&gt;sketch = sketches.item(i1)&lt;BR /&gt;if (sketch.name in targetSketches):&lt;BR /&gt;#sketch_names.append(sketches.item(i1).name)&lt;BR /&gt;print(str(sketches.item(i1).name))&lt;BR /&gt;i1 = i1 + 1&lt;BR /&gt;else:&lt;BR /&gt;print(str(sketches.item(i1).name))&lt;BR /&gt;sketch.deleteMe()&lt;BR /&gt;break&lt;BR /&gt;# This matches the manually exported DXF,&lt;BR /&gt;# so things are great up to here ...I think...&lt;BR /&gt;sketch.saveAsDXF(fullPath + sketch.name + '.dxf')&lt;/P&gt;&lt;P&gt;####&lt;BR /&gt;sketches = rootComp.sketches&lt;BR /&gt;sketch_names = []&lt;BR /&gt;i1 = 0&lt;BR /&gt;for sk in sketches:&lt;BR /&gt;print(str(sketches.item(i1).name))&lt;BR /&gt;# nope master.project(sk)&lt;BR /&gt;i1 = i1 + 1&lt;BR /&gt;#####&lt;/P&gt;&lt;P&gt;sketchEntities: adsk.core.ObjectCollection = adsk.core.ObjectCollection.create()&lt;BR /&gt;for sketch in rootComp.sketches:&lt;BR /&gt;myname = sketch.name&lt;BR /&gt;print(myname)&lt;BR /&gt;[sketchEntities.add(ent) for ent in sketch.sketchCurves]&lt;BR /&gt;[sketchEntities.add(ent) for ent in sketch.sketchPoints]&lt;BR /&gt;[sketchEntities.add(ent) for ent in sketch.sketchTexts]&lt;/P&gt;&lt;P&gt;# Create new Sketch&lt;BR /&gt;master: adsk.fusion.Sketch = rootComp.sketches.add(rootComp.xYConstructionPlane)&lt;BR /&gt;master.name = 'Master'&lt;BR /&gt;# Project Body&lt;BR /&gt;targetBody: adsk.fusion.BRepBody = rootComp.bRepBodies[0]&lt;BR /&gt;project_result: adsk.core.ObjectCollection = master.project(targetBody)&lt;BR /&gt;if project_result.count &amp;lt; 1:&lt;BR /&gt;print('Failure of the body project')&lt;/P&gt;&lt;P&gt;# Include sketchEntities&lt;BR /&gt;master.include(sketchEntities)&lt;/P&gt;&lt;P&gt;# Project sketchEntities&lt;BR /&gt;master.project(sketchEntities)&lt;/P&gt;&lt;P&gt;else: # (DXF_Type_BPB == False)&lt;BR /&gt;design : adsk.fusion.Design = app.activeProduct&lt;BR /&gt;# new logic 2 statements added 02-28-2023&lt;BR /&gt;document = app.activeDocument&lt;BR /&gt;design = document.design&lt;BR /&gt;try:&lt;BR /&gt;rootComp = design.rootComponent&lt;BR /&gt;except:&lt;BR /&gt;msg = 'This model contains no CAM object, no DXF can be generated'&lt;BR /&gt;if (run_from_list == False):&lt;BR /&gt;# inform operator issue no cam object found&lt;BR /&gt;ui.messageBox(msg)&lt;BR /&gt;Stop_it = True&lt;BR /&gt;_flags.append(msg)&lt;BR /&gt;else:&lt;BR /&gt;# set a flag so we skip all further processing&lt;BR /&gt;Stop_it = True&lt;BR /&gt;print(msg)&lt;/P&gt;&lt;P&gt;if (Stop_it == False):&lt;BR /&gt;master: adsk.fusion.Sketch = rootComp.sketches.add(rootComp.xYConstructionPlane)&lt;BR /&gt;targetBody: adsk.fusion.BRepBody = rootComp.bRepBodies[0]&lt;BR /&gt;master.project(targetBody)&lt;/P&gt;&lt;P&gt;if (Stop_it == False):&lt;BR /&gt;# Scale the model if its in inches&lt;BR /&gt;if(in_inches == True):&lt;BR /&gt;basePt = master.sketchPoints.item(0)&lt;BR /&gt;scaleFactor = adsk.core.ValueInput.createByString("10 mm")&lt;BR /&gt;#scales = rootComp.features.scaleFeatures&lt;BR /&gt;scales = rootComp.features.scaleFeatures&lt;BR /&gt;#Create an uniformed input for scale feature input&lt;BR /&gt;inputUniformColl = adsk.core.ObjectCollection.create()&lt;BR /&gt;inputUniformColl.add(master)&lt;BR /&gt;scaleUniformInput = scales.createInput(inputUniformColl, basePt, scaleFactor)&lt;BR /&gt;scaleUniform = scales.add(scaleUniformInput)&lt;BR /&gt;&lt;BR /&gt;# Special scaling for the other tool for MM models, updated 12-8-22&lt;BR /&gt;if(in_inches == False):&lt;BR /&gt;basePt = master.sketchPoints.item(0)&lt;BR /&gt;scaleFactor = adsk.core.ValueInput.createByString("1.0 in/64.516")&lt;BR /&gt;#scales = rootComp.features.scaleFeatures&lt;BR /&gt;scales = rootComp.features.scaleFeatures&lt;BR /&gt;#Create an uniformed input for scale feature input&lt;BR /&gt;inputUniformColl = adsk.core.ObjectCollection.create()&lt;BR /&gt;inputUniformColl.add(master)&lt;BR /&gt;scaleUniformInput = scales.createInput(inputUniformColl, basePt, scaleFactor)&lt;BR /&gt;scaleUniform = scales.add(scaleUniformInput)&lt;/P&gt;&lt;P&gt;# write the merged file&lt;BR /&gt;master.saveAsDXF(fullPath + '.dxf')&lt;BR /&gt;msg = '!! DXF file has been written !!'&lt;BR /&gt;DFX_Generated = True&lt;BR /&gt;#print(msg)&lt;BR /&gt;futil.log(msg)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will drag and drop as this is hard to read.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your time and assistance, I have looked and tried so many different things but I just can't resolve this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2023 15:40:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/sketch-with-text-via-api-not-exporting-text-but-will-manually/m-p/11836803#M4156</guid>
      <dc:creator>marylou.forsyth</dc:creator>
      <dc:date>2023-03-21T15:40:10Z</dc:date>
    </item>
    <item>
      <title>Re: Sketch with text via API not exporting text but will manually</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/sketch-with-text-via-api-not-exporting-text-but-will-manually/m-p/11838081#M4157</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/13108168"&gt;@marylou.forsyth&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to include your code in the forum, this is a good way to display it.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.png" style="width: 770px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1191682iD71C017E838EAF00/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.png" alt="1.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I tried, the project/include method was not available for SketchText objects.&lt;/P&gt;
&lt;P&gt;Therefore, I created a sample that explodes and then projects the data.&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;# Fusion360API Python script

import traceback
import adsk.core as core
import adsk.fusion as fusion

def run(context):
    ui = core.UserInterface.cast(None)
    try:
        app: core.Application = core.Application.get()
        ui = app.userInterface
        des: fusion.Design = app.activeProduct
        root: fusion.Component = des.rootComponent

        path = r'C:\temp\test.dxf'

        targetSketchNames = ['PEN_LINE','BEND_LINE']

        try:
            app.executeTextCommand(u'Transaction.Start export_project_sketch')

            export_project_sketch(
                targetSketchNames,
                root.xYConstructionPlane,
                path,
            )
        except:
            pass
        finally:
            app.executeTextCommand(u'Transaction.Abort')

        ui.messageBox('Done')

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


def export_project_sketch(
    targetSketchNames: list,
    supportPlane: fusion.ConstructionPlane,
    path: str,
) -&amp;gt; None:

    def get_sketch_entities(
        skt: fusion.Sketch,
    ) -&amp;gt; list:

        lst = [c for c in skt.sketchCurves]
        lst.extend([p for p in skt.sketchPoints])

        return lst

    def explode_sketchTexts(
        skt: fusion.Sketch,
    ) -&amp;gt; None:

        skt.isComputeDeferred = True

        sktTxtLst = [t for t in skt.sketchTexts]
        [t.explode() for t in sktTxtLst]
            
        skt.isComputeDeferred = False
    # *******

    app: core.Application = core.Application.get()
    des: fusion.Design = app.activeProduct
    root: fusion.Component = des.rootComponent

    sktLst = [skt for skt in root.sketches if skt.name.upper() in targetSketchNames]
    if len(sktLst) &amp;lt; 1:
        return

    [explode_sketchTexts(skt) for skt in sktLst]

    sktEnts = []
    [sktEnts.extend(get_sketch_entities(skt)) for skt in sktLst]
    if len(sktEnts) &amp;lt; 1:
        return

    sketchEntities: core.ObjectCollection = core.ObjectCollection.create()
    [sketchEntities.add(e) for e in sktEnts]

    master: fusion.Sketch = root.sketches.add(supportPlane)
    master.name = 'Master'

    master.project(sketchEntities)
    master.saveAsDXF(path)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since it would be inconvenient if the original data were left exploded, we used a transaction of text commands to return the data to the state before processing.&lt;BR /&gt;However, since explode is very time-consuming, I do not think it will be useful in practice.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2023 03:53:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/sketch-with-text-via-api-not-exporting-text-but-will-manually/m-p/11838081#M4157</guid>
      <dc:creator>kandennti</dc:creator>
      <dc:date>2023-03-22T03:53:55Z</dc:date>
    </item>
    <item>
      <title>Re: Sketch with text via API not exporting text but will manually</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/sketch-with-text-via-api-not-exporting-text-but-will-manually/m-p/11840020#M4158</link>
      <description>&lt;P&gt;You are a wonder to behold!&amp;nbsp; You have nailed the issue, I have been working on this and you just brought it to a resolution, bless you!!&amp;nbsp; Yes, so right you are I spoke with the developers and they will explode the text in sketches so the API will not have too.&amp;nbsp; Would not have gotten here without your help, thank you!!&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2023 18:03:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/sketch-with-text-via-api-not-exporting-text-but-will-manually/m-p/11840020#M4158</guid>
      <dc:creator>marylou.forsyth</dc:creator>
      <dc:date>2023-03-22T18:03:09Z</dc:date>
    </item>
  </channel>
</rss>

