- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Good day programmers! I am asking for help as I am just not seeing what steps I am missing. Please let me give the background. We open a model via API script, we read in new parameters to update the model to, and update the model. All processing is done via the API script. 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. 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})
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. My problem is when the second export happens, I don't see the text.
The manual export (fullPath + sketch.name + 'dxf') which is looking ok to me appears as this:
and at the top you can see the text data 'HV something'.
The export with the body, Pen_line though only creates this as I must be missing something major:
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.
I thought this line was going to give what I needed but sadly no:
[sketchEntities.add(ent) for ent in sketch.sketchTexts]
One more thing, there is logic to adjust the scaling but thats been working fine.
#we call this right before the code in question --> : updateParametricModel(tag,value,userParams,False)
else: # its a punch so export the drawing scaled correctly
global DXF_Type_BPB
# flag if problem of no cam found when making a DXF
Stop_it = False
folder = "W:\\SharedData\\Fusion_360\\DXF\\"
fullPath = os.path.join(folder, order)
if (DXF_Type_BPB == True):
Total_Count_Sketches = 0
targetSketches = ['Pen_Line','Pen_line','pen_line','Bend_Line','Bend_line','bend_line']
DFX_Generated = True
design : adsk.fusion.Design = app.activeProduct
root: adsk.fusion.Component = design.rootComponent
master: adsk.fusion.Sketch = root.sketches.add(root.xYConstructionPlane)
rootComp: adsk.fusion.Component = design.rootComponent
#### Check names of all sketches
#sketches = rootComp.sketches
#sketch_names = []
#i1 = 0
#for sk in sketches:
# print(str(sketches.item(i1).name))
# i1 = i1 + 1
#####
sketches = rootComp.sketches
sketch_names = []
Kludge_Counter = 0
Not_done = False
while Not_done == False:
Kludge_Counter = Kludge_Counter + 1
if (Kludge_Counter > 20):
Not_done = True
i1 = 0
for sk in sketches:
sketch = sketches.item(i1)
if (sketch.name in targetSketches):
#sketch_names.append(sketches.item(i1).name)
print(str(sketches.item(i1).name))
i1 = i1 + 1
else:
print(str(sketches.item(i1).name))
sketch.deleteMe()
break
# This matches the manually exported DXF,
# so things are great up to here ...I think...
sketch.saveAsDXF(fullPath + sketch.name + '.dxf')
####
sketches = rootComp.sketches
sketch_names = []
i1 = 0
for sk in sketches:
print(str(sketches.item(i1).name))
# nope master.project(sk)
i1 = i1 + 1
#####
sketchEntities: adsk.core.ObjectCollection = adsk.core.ObjectCollection.create()
for sketch in rootComp.sketches:
myname = sketch.name
print(myname)
[sketchEntities.add(ent) for ent in sketch.sketchCurves]
[sketchEntities.add(ent) for ent in sketch.sketchPoints]
[sketchEntities.add(ent) for ent in sketch.sketchTexts]
# Create new Sketch
master: adsk.fusion.Sketch = rootComp.sketches.add(rootComp.xYConstructionPlane)
master.name = 'Master'
# Project Body
targetBody: adsk.fusion.BRepBody = rootComp.bRepBodies[0]
project_result: adsk.core.ObjectCollection = master.project(targetBody)
if project_result.count < 1:
print('Failure of the body project')
# Include sketchEntities
master.include(sketchEntities)
# Project sketchEntities
master.project(sketchEntities)
else: # (DXF_Type_BPB == False)
design : adsk.fusion.Design = app.activeProduct
# new logic 2 statements added 02-28-2023
document = app.activeDocument
design = document.design
try:
rootComp = design.rootComponent
except:
msg = 'This model contains no CAM object, no DXF can be generated'
if (run_from_list == False):
# inform operator issue no cam object found
ui.messageBox(msg)
Stop_it = True
_flags.append(msg)
else:
# set a flag so we skip all further processing
Stop_it = True
print(msg)
if (Stop_it == False):
master: adsk.fusion.Sketch = rootComp.sketches.add(rootComp.xYConstructionPlane)
targetBody: adsk.fusion.BRepBody = rootComp.bRepBodies[0]
master.project(targetBody)
if (Stop_it == False):
# Scale the model if its in inches
if(in_inches == True):
basePt = master.sketchPoints.item(0)
scaleFactor = adsk.core.ValueInput.createByString("10 mm")
#scales = rootComp.features.scaleFeatures
scales = rootComp.features.scaleFeatures
#Create an uniformed input for scale feature input
inputUniformColl = adsk.core.ObjectCollection.create()
inputUniformColl.add(master)
scaleUniformInput = scales.createInput(inputUniformColl, basePt, scaleFactor)
scaleUniform = scales.add(scaleUniformInput)
# Special scaling for the other tool for MM models, updated 12-8-22
if(in_inches == False):
basePt = master.sketchPoints.item(0)
scaleFactor = adsk.core.ValueInput.createByString("1.0 in/64.516")
#scales = rootComp.features.scaleFeatures
scales = rootComp.features.scaleFeatures
#Create an uniformed input for scale feature input
inputUniformColl = adsk.core.ObjectCollection.create()
inputUniformColl.add(master)
scaleUniformInput = scales.createInput(inputUniformColl, basePt, scaleFactor)
scaleUniform = scales.add(scaleUniformInput)
# write the merged file
master.saveAsDXF(fullPath + '.dxf')
msg = '!! DXF file has been written !!'
DFX_Generated = True
#print(msg)
futil.log(msg)
I will drag and drop as this is hard to read.
Thank you for your time and assistance, I have looked and tried so many different things but I just can't resolve this.
Solved! Go to Solution.