feeling so frustrated :( (cant use point-List to get every point to make sketch and do cutting entity)

feeling so frustrated :( (cant use point-List to get every point to make sketch and do cutting entity)

AkusoWang
Participant Participant
388 Views
1 Reply
Message 1 of 2

feeling so frustrated :( (cant use point-List to get every point to make sketch and do cutting entity)

AkusoWang
Participant
Participant

I did 6 hour to solve this problem, feel pretty frustrated. I cant find the example about it.

Could anyone help me solve this problem please!

I build first a entity and want to make the every point from list. Every time only use one point to make a sketch and extrude a hole from entity. 

Problem:  it show me always, that it cant find a entity to make cutting with new sketch, it seems like, that after get first point,making sketch and extrude, it cant really remove thie frist point from list, and second time it get the same point, so that cant make new cutting with the sketch anymore. 

 

import adsk.fusion, adsk.cam, random,  math, adsk.core, os, traceback

app = adsk.core.Application.get()   
ui = app.userInterface
doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
design = adsk.fusion.Design.cast(app.activeProduct)
rootComp = design.rootComponent
x0 = random.uniform(10, 20)
y0 = random.uniform(10, 20)
L = random.uniform(10, 20)
sketch = rootComp.sketches.add(rootComp.xZConstructionPlane)
lines = sketch.sketchCurves.sketchLines
rec_center =adsk.core.Point3D.create(0, 0, 0)
lines.addCenterPointRectangle(rec_center, adsk.core.Point3D.create(x0, y0, 0))
prof = sketch.profiles.item(0)
extrudes = rootComp.features.extrudeFeatures
extrude_NewBody = adsk.fusion.FeatureOperations.NewBodyFeatureOperation
extrude_Cut =adsk.fusion.FeatureOperations.CutFeatureOperation

distance = adsk.core.ValueInput.createByReal(L)
extrudeInput = extrudes.addSimple(prof, distance, extrude_NewBody)
face1_end = extrudeInput.endFaces.item(0)

sketch3 = rootComp.sketches.add(rootComp.xZConstructionPlane)
sketchPoints = sketch3.sketchPoints

pt_List = []
for i in range(5):
    pt_List.append(sketchPoints.add(adsk.core.Point3D.create(6, 0, 0)))
    pt_List.append(sketchPoints.add(adsk.core.Point3D.create(4, 2, 0)))
    pt_List.append(sketchPoints.add(adsk.core.Point3D.create(2, 0, 0)))
    pt_List.append(sketchPoints.add(adsk.core.Point3D.create(0, 4, 0)))
    pt_List.append(sketchPoints.add(adsk.core.Point3D.create(4, 0, 0)))

for i in range(5):
    pt = random.sample(pt_List, 1)[0]
    pt_List.remove(pt)

    for curve in sketch3.sketchCurves:
        if curve.geometry.center.isEqualTo(pt.geometry):
            pt = random.sample(pt_List, 1)[0]
            pt_List.remove(pt)
            break
    circle = sketch3.sketchCurves.sketchCircles
    circle.addByCenterRadius(pt.geometry, 0.5)
    
    prof = sketch3.profiles.item(0)
    extrudes = rootComp.features.extrudeFeatures
    extrudeInput = extrudes.createInput(prof, extrude_Cut)
    extrudeInput.setDistanceExtent(True, adsk.core.ValueInput.createByReal(L)) 
    extrudes.add(extrudeInput)

 

 

king2012hl_0-1680571000373.png

Thank you!

 

0 Likes
Accepted solutions (1)
389 Views
1 Reply
Reply (1)
Message 2 of 2

AkusoWang
Participant
Participant
Accepted solution

I solve finaly this problem. OMG

 

for i in range(5):
    sketchName ="sketch_hole{}".format(i+1)
    sketch_hole.name = sketchName

    pt = random.sample(pt_List, 1)[0]
    pt_List.remove(pt)

    for curve in sketch_hole.sketchCurves:
        if curve.geometry.center.isEqualTo(pt.geometry):
            pt = random.sample(pt_List, 1)[0]
            pt_List.remove(pt)
            break
    circle = sketch_hole.sketchCurves.sketchCircles
    circle.addByCenterRadius(pt.geometry, 0.5)
    
    prof = sketch_hole.profiles.item(0)
    extrudes = rootComp.features.extrudeFeatures
    extrudeInput = extrudes.createInput(prof, extrude_Cut)
    extrudeInput.setDistanceExtent(True, adsk.core.ValueInput.createByReal(-L)) 
    extrudes.add(extrudeInput)
    sketch_hole = rootComp.sketches.add(rootComp.xZConstructionPlane)

king2012hl_0-1680572531085.png

 

 

0 Likes