こちらの続きです。
スケッチの点を元にボディを複製したい1 - C#ATIA
前回はTemporaryBRepManagerとBaseFeatureを利用して
配置を行ったのですが、ひょっとしたらCustom Featuresに
した時に上手く行かないと、精神的ダメージが大きいので
他の方法も検討しておこうと思い、CopyPasteBodyと
MoveFeatureで同様の処理を行うものも作ってみました。
Custom Featuresは、TemporaryBRepManagerとBaseFeatureは
対応しているんですけどね。
# 将来的に body skt は同一コンポーネントの制限を行いたい def execUserPattern( body :adsk.fusion.BRepBody, skt :adsk.fusion.Sketch): # get points - 次回xyPlane上に制限する? origin :adsk.fusion.SketchPoint = skt.originPoint p :adsk.fusion.SketchPoint pnts = [p.worldGeometry for p in skt.sketchPoints if p != origin] # body cog VERYHI = adsk.fusion.CalculationAccuracy.VeryHighCalculationAccuracy prop :adsk.fusion.PhysicalProperties = body.getPhysicalProperties(VERYHI) bodyCenter :adsk.core.Point3D = prop.centerOfMass # get sketch axis _, _, _, zAxis = skt.transform.getAsCoordinateSystem() # projection body cog infinite :adsk.core.InfiniteLine3D = adsk.core.InfiniteLine3D.create(bodyCenter, zAxis) plane :adsk.core.Plane = skt.referencePlane.geometry bodyProjectionCog :adsk.core.Point3D = plane.intersectWithLine(infinite) # get matrix mats = [] for p in pnts: vec :adsk.core.Vector3D = bodyProjectionCog.vectorTo(p) mat = adsk.core.Matrix3D.create() mat.translation = vec mats.append(mat) # BaseFeature comp :adsk.fusion.Component = body.parentComponent # baseFeat : adsk.fusion.BaseFeature = comp.features.baseFeatures.add() #ここ # start edit # baseFeat.startEdit() #ここ # CopyPasteBody copyBodies :adsk.fusion.CopyPasteBodies = comp.features.copyPasteBodies # move moves :adsk.fusion.MoveFeatures = comp.features.moveFeatures objs :adsk.core.ObjectCollection = adsk.core.ObjectCollection.create() for mat in mats: objs.clear() objs.add(body) copyPasteFeat = copyBodies.add(objs) objs.clear() objs.add(copyPasteFeat.bodies[0]) moveIpt :adsk.fusion.MoveFeatureInput = moves.createInput(objs, mat) moves.add(moveIpt) # baseFeat.finishEdit() #ここ
実行結果は同じなのですが、タイムラインが違います。
コピペして移動。コピペして・・・・となります。
上記のコードで ”#ここ” の記載している3行のコメント化を
外すとBaseFeature内での作業になるのですが、エラーになります。
BaseFeature内でCopyPasteBodyはエラーになるようです。
知らなかった。逆にGUIではBaseFeature内で行わないと
出来ないのに。調べ方が足りないかも。