C#ATIA

↑タイトル詐欺 主にFusion360API 偶にCATIA V5 VBA(絶賛ネタ切れ中)

Fusion360APIでLine Arc Nurbsを作成してみる1

こちらの続き
Fusion360APIでNURBS曲線を作成してみる3 - C#ATIA

Line Arc Nurbsの各種入ったIgesをこちらにUpしました。
GrabCAD - CAD library
(ファイル名:nurbs_curve_3d_sample1.igs)

閉じた円弧はArc3Dでは都合悪いかも知れませんが(未テスト)
siren側で2つの開いた円弧に分割しているような気がするので後回し。
Nurbs以外の曲線が現実的に存在しているものか不明なので無視。

一応途中ですが、こんな感じです。
f:id:kandennti:20170816190312p:plain
実は円弧に苦労しています。

コードは全く駄目なものですが、自宅で続きをやるかもしれないので記載。

#FusionAPI_python
#Author-kantoku
#Description-CurvesTest1
#Line Arc Nurbs作成テスト

import adsk.core, adsk.fusion, traceback

_app = adsk.core.Application.get()
_ui = _app.userInterface

def run(context):
    try:
        global _app, _ui
        des = adsk.fusion.Design.cast(_app.activeProduct)
        comp = des.rootComponent
        
        geos = []
        
        lin_ary = ["Siren::Line",[[1,2,3],[7, 8, 9]]]
        geos.append(create_Line(lin_ary).asNurbsCurve)
        
        arc_ary = ["Siren::Circle",
                   [[9.999999998279, 10.999999997875, 11.999999999064],
                    [24.682458367311, 23.30947502125, 21.936491673766],
                    [4.9999999978654, 14.99999999931, 25.000000001367]]]
        geos.append(create_Arc(arc_ary))
        
        
        nsc_ary = ["Siren::BSCurve",
                   [[10, -20, -10], 
                    [9.587310041, -19.66378473, -7.111170289], 
                    [9.066687233, -19.24725683, -4.318376656], 
                    [8.414915532, -18.73943189, -1.64725845], 
                    [7.064932775, -17.72835072, 2.46828599], 
                    [5.183948194, -16.46330539, 5.802194902], 
                    [4.342483009, -15.92222727, 6.978456889], 
                    [2.558949274, -14.84247725, 8.853440155], 
                    [0.4455897088, -13.72427175, 9.964573277], 
                    [-0.6232459496, -13.19898599, 10.30174101], 
                    [-2.929444025, -12.16203711, 10.59962188], 
                    [-5.413111131, -11.2518361, 10.14198332], 
                    [-6.714932791, -10.8317392, 9.723113911], 
                    [-10.15600129, -9.869701012, 8.217440862], 
                    [-13.65008051, -9.267637855, 5.788366698], 
                    [-15.79519881, -9.037527212, 4.03034148], 
                    [-17.91158269, -8.933957503, 2.08841731], 
                    [-20, -8.944926835, 0]],
                    5,
                    [0, 17.39738523, 28.8962564, 
                     39.23864718, 50.07377854, 67.53908293],
                    [6, 3, 3, 3, 3, 6],
                    [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]
        geos.append(create_BSCurve(nsc_ary))
        
        #スケッチ作成
        sk = comp.sketches.add(comp.xYConstructionPlane)
        
        #円弧テスト
        pos = arc_ary[1]
        Arcs = sk.sketchCurves.sketchArcs
        Arcs.addByThreePoints(
            create_Point(pos[0]), 
            create_Point(pos[1]), 
            create_Point(pos[2]))
            
        for geo in geos:
            if geo.classType() == "adsk::core::Arc3D":
                #これNG
                a = geo.center
                b = geo.startPoint
                c = geo.endAngle - geo.startAngle
                #fs = sk.sketchCurves.sketchArcs.addByCenterStartSweep(a, b, c)
            else:
                fs = sk.sketchCurves.sketchFittedSplines.addByNurbsCurve(geo)
                sk.include(fs)
                fs.deleteMe()
        
        _ui.messageBox('done')
    except:
        if _ui:
            _ui.messageBox('エラー\n{}'.format(traceback.format_exc()))
#使ってない
def curve_Factory(lst):
    for cv_info in lst:
        cv_type = cv_info(0)
        if cv_type == "Siren::Line":
            pass
        elif cv_type == "Siren::Circle":
            pass
        elif cv_type == "Siren::BSCurve":
            pass
        else:
            pass

def create_Point(pos):
    return adsk.core.Point3D.create(
        pos[0] * 0.1, pos[1] * 0.1, pos[2] * 0.1)
                
def create_Line(lst):
    pos = lst[1]
    return adsk.core.Line3D.create(
        create_Point(pos[0]), 
        create_Point(pos[1]))

def create_Arc(lst):
    pos = lst[1]
    return adsk.core.Arc3D.createByThreePoints(
        create_Point(pos[0]), 
        create_Point(pos[1]), 
        create_Point(pos[2]))

def create_BSCurve(lst):
    poles = [create_Point(pos) for pos in lst[1]]
    degree = lst[2]
    knots = []
    for i, m in enumerate(lst[4]):
        for k in range(0, m):
            knots.append(lst[3][i])
    weights = lst[5]
    
    return adsk.core.NurbsCurve3D.createRational(
        poles, degree, knots, weights, False)

本当は・・・拡張メソッド作れそうだからその方法かな?