iuuuuu1 2022-10-28 16:21 采纳率: 50%
浏览 107
已结题

python嵌套循环

将下面进行一个嵌套循环,n添加一个外循环【0,50】,内部的 range依次增加24,n的内部循环是1200/1201,n1的内部循环是1201/1202,依次加一。
用代码块功能插入代码,请勿粘贴截图

-

for n in range(1, 25):
    Fill1 = hsf.add_new_fill()
    hybridBody1 = hb1.item("几何图形集.3")
    hybridShape1 = hybridBody1.hybrid_shapes
    reference11 = part.create_reference_from_object(hybridShape1.item("样条线." + f"{n}"))
    Fill1.add_bound(reference11)
    reference12 = part.create_reference_from_object(hybridShape1.item("样条线." + f"{n + 1200}"))
    Fill1.add_bound(reference12)
    reference13 = part.create_reference_from_object(hybridShape1.item("样条线." + f"{n + 24}"))
    Fill1.add_bound(reference13)
    reference14 = part.create_reference_from_object(hybridShape1.item("样条线." + f"{n + 1201}"))
    Fill1.add_bound(reference14)
    Fill1.Continuity = 0
    hb.append_hybrid_shape(Fill1)

for n1 in range(25, 49):
    Fill1 = hsf.add_new_fill()
    hybridBodies1 = part.hybrid_bodies
    hybridBody1 = hb1.item("几何图形集.3")
    hybridShape1 = hybridBody1.hybrid_shapes
    reference11 = part.create_reference_from_object(hybridShape1.item("样条线." + f"{n1}"))
    Fill1.add_bound(reference11)
    reference12 = part.create_reference_from_object(hybridShape1.item("样条线." + f"{n1 + 1201}"))
    Fill1.add_bound(reference12)
    reference13 = part.create_reference_from_object(hybridShape1.item("样条线." + f"{n1 + 24}"))
    Fill1.add_bound(reference13)
    reference14 = part.create_reference_from_object(hybridShape1.item("样条线." + f"{n1 + 1202}"))
    Fill1.add_bound(reference14)
    Fill1.Continuity = 0
    hb.append_hybrid_shape(Fill1)
#
for n2 in range(49,73):
    Fill1 = hsf.add_new_fill()
    hybridBodies1 = part.hybrid_bodies
    hybridBody1 = hb1.item("几何图形集.3")
    hybridShape1 = hybridBody1.hybrid_shapes
    reference11 = part.create_reference_from_object(hybridShape1.item("样条线." + f"{n2}"))
    Fill1.add_bound(reference11)
    reference12 = part.create_reference_from_object(hybridShape1.item("样条线." + f"{n2 + 1202}"))
    Fill1.add_bound(reference12)
    reference13 = part.create_reference_from_object(hybridShape1.item("样条线." + f"{n2 + 24}"))
    Fill1.add_bound(reference13)
    reference14 = part.create_reference_from_object(hybridShape1.item("样条线." + f"{n2 + 1203}"))
    Fill1.add_bound(reference14)
    Fill1.Continuity = 0
    hb.append_hybrid_shape(Fill1)

for n3 in range(73, 97):
    Fill1 = hsf.add_new_fill()
    hybridBodies1 = part.hybrid_bodies
    hybridBody1 = hb1.item("几何图形集.3")
    hybridShape1 = hybridBody1.hybrid_shapes
    reference11 = part.create_reference_from_object(hybridShape1.item("样条线." + f"{n3}"))
    Fill1.add_bound(reference11)
    reference12 = part.create_reference_from_object(hybridShape1.item("样条线." + f"{n3 + 1203}"))
    Fill1.add_bound(reference12)
    reference13 = part.create_reference_from_object(hybridShape1.item("样条线." + f"{n3 + 24}"))
    Fill1.add_bound(reference13)
    reference14 = part.create_reference_from_object(hybridShape1.item("样条线." + f"{n3 + 1204}"))
    Fill1.add_bound(reference14)
    Fill1.Continuity = 0
    hb.append_hybrid_shape(Fill1)
for n4 in range(97, 121):
    Fill1 = hsf.add_new_fill()
    hybridBodies1 = part.hybrid_bodies
    hybridBody1 = hb1.item("几何图形集.3")
    hybridShape1 = hybridBody1.hybrid_shapes
    reference11 = part.create_reference_from_object(hybridShape1.item("样条线." + f"{n4}"))
    Fill1.add_bound(reference11)
    reference12 = part.create_reference_from_object(hybridShape1.item("样条线." + f"{n4 + 1204}"))
    Fill1.add_bound(reference12)
    reference13 = part.create_reference_from_object(hybridShape1.item("样条线." + f"{n4 + 24}"))
    Fill1.add_bound(reference13)
    reference14 = part.create_reference_from_object(hybridShape1.item("样条线." + f"{n4 + 1205}"))
    Fill1.add_bound(reference14)
    Fill1.Continuity = 0
    hb.append_hybrid_shape(Fill1)
for n5 in range(121, 145):
    Fill1 = hsf.add_new_fill()
    hybridBodies1 = part.hybrid_bodies
    hybridBody1 = hb1.item("几何图形集.3")
    hybridShape1 = hybridBody1.hybrid_shapes
    reference11 = part.create_reference_from_object(hybridShape1.item("样条线." + f"{n5}"))
    Fill1.add_bound(reference11)
    reference12 = part.create_reference_from_object(hybridShape1.item("样条线." + f"{n5 + 1205}"))
    Fill1.add_bound(reference12)
    reference13 = part.create_reference_from_object(hybridShape1.item("样条线." + f"{n5 + 24}"))
    Fill1.add_bound(reference13)
    reference14 = part.create_reference_from_object(hybridShape1.item("样条线." + f"{n5 + 1206}"))
    Fill1.add_bound(reference14)
    Fill1.Continuity = 0
    hb.append_hybrid_shape(Fill1)

我尝试得结果

for a in range(50):
    for n in range(24*a+1, 24*(a+1)+1):
    # for n in range(1, 25):
        Fill1 = hsf.add_new_fill()
        hybridBodies1 = part.hybrid_bodies
        hybridBody1 = hb1.item("几何图形集.3")
        hybridShape1 = hybridBody1.hybrid_shapes
        reference11 = part.create_reference_from_object(hybridShape1.item("样条线." + f"{n}"))
        Fill1.add_bound(reference11)
        reference14 = part.create_reference_from_object(hybridShape1.item("样条线." + f"{n + 1200 }"+f"{'a'}"))
        Fill1.add_bound(reference14)
        reference12 = part.create_reference_from_object(hybridShape1.item("样条线." + f"{n + 174}"))
        Fill1.add_bound(reference12)
        reference13 = part.create_reference_from_object(hybridShape1.item("样条线." + f"{n + 1201 }"+f"{'a'}"))
        Fill1.add_bound(reference13)
        Fill1.Continuity = 0
        hb.append_hybrid_shape(Fill1)

  • 写回答

4条回答 默认 最新

  • 请叫我问哥 Python领域新星创作者 2022-10-28 20:29
    关注
    for n in range(51):
        for i in range(n*24+1,(n+1)*24+1):
        Fill1 = hsf.add_new_fill()
        hybridBody1 = hb1.item("几何图形集.3")
        hybridShape1 = hybridBody1.hybrid_shapes
        reference11 = part.create_reference_from_object(hybridShape1.item("样条线." + f"{i}"))
        Fill1.add_bound(reference11)
        reference12 = part.create_reference_from_object(hybridShape1.item("样条线." + f"{i + 1200 + n}"))
        Fill1.add_bound(reference12)
        reference13 = part.create_reference_from_object(hybridShape1.item("样条线." + f"{i + 24}"))
        Fill1.add_bound(reference13)
        reference14 = part.create_reference_from_object(hybridShape1.item("样条线." + f"{i + 1201 + n}"))
        Fill1.add_bound(reference14)
        Fill1.Continuity = 0
        hb.append_hybrid_shape(Fill1)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

问题事件

  • 系统已结题 11月5日
  • 已采纳回答 10月28日
  • 修改了问题 10月28日
  • 修改了问题 10月28日
  • 展开全部

悬赏问题

  • ¥30 Hyper-v虚拟机相关问题,求解答。
  • ¥15 TSM320F2808PZA芯片 Bootloader
  • ¥45 谷歌浏览器出现开发者工具无法显示已创建的,但您可以调试已部署的代码。 状态代码 404, net::ERR HTTP RESPONSE CODE FAILURE
  • ¥15 chatgpt网页版侧边栏和模型切换点击没反应怎么办
  • ¥15 如何解决蓝牙通话音频突发失真问题
  • ¥15 安装opengauss数据库报错
  • ¥15 【急】在线问答CNC雕刻机的电子电路与编程
  • ¥60 在mc68335芯片上移植ucos ii 的成功工程文件
  • ¥15 笔记本外接显示器正常,但是笔记本屏幕黑屏
  • ¥15 Python pandas