C#ATIA

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

フィレットの元のエッジを探せ!!2

こちらの続きです。
フィレットの元のエッジを探せ!!1 - C#ATIA

前回の物を修正しました。

# Fusion360API Python script

import traceback
import adsk.fusion
import adsk.core


def run(context):
    ui = adsk.core.UserInterface.cast(None)
    try:
        app: adsk.core.Application = adsk.core.Application.get()
        ui = app.userInterface
        des: adsk.fusion.Design = app.activeProduct
        root: adsk.fusion.Component = des.rootComponent

        msg: str = 'Select'
        selFilter: str = 'Features'
        sel: adsk.core.Selection = selectEnt(msg, selFilter)
        if not sel:
            return

        useFeats = getReferenced_Fillet(sel.entity)

        [app.log(f.name) for  f in useFeats]


    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


def selectEnt(
        msg: str,
        filterStr: str) -> adsk.core.Selection:

    try:
        app: adsk.core.Application = adsk.core.Application.get()
        ui: adsk.core.UserInterface = app.userInterface
        sel = ui.selectEntity(msg, filterStr)
        return sel
    except:
        return None


def getReferenced_Fillet(self) -> list:
        app: adsk.core.Application = adsk.core.Application.get()
        des: adsk.fusion.Design = app.activeProduct

        def getEdgeTokenSet(edgeSets: adsk.fusion.FilletEdgeSets) -> set:
            tokens = set()
            # 
            try:
                for edgeset in edgeSets:
                    [tokens.add(e.entityToken) for e in edgeset.edges]
            except:
                pass

            return tokens

        # *****
        timeline: adsk.fusion.Timeline = des.timeline
        backupMarker = timeline.markerPosition

        timeObj: adsk.fusion.TimelineObject = self.timelineObject
        timeObj.rollTo(True)

        edgeTokenSet = getEdgeTokenSet(self.edgeSets)

        timeObjs = [timeline.item(idx) for idx in range(timeline.markerPosition)]

        useFeats = []
        for timeObj in timeObjs:
            timeEnt: adsk.fusion.Feature = timeObj.entity
            if not hasattr(timeEnt, 'bodies'):
                continue

            timeObj.rollTo(False)
            tmpTokenSet = set()
            for body in timeEnt.bodies:
                [tmpTokenSet.add(e.entityToken) for e in body.edges]

            intersection = edgeTokenSet.intersection(tmpTokenSet)
            if len(intersection) > 0:
                useFeats.append(timeEnt)
                [edgeTokenSet.discard(token) for token in intersection]

            if len(edgeTokenSet) < 1:
                break

        timeline.markerPosition = backupMarker

        return useFeats

フィレットを付けている元のエッジのentityTokenを調べ、
タイムラインの先頭から、該当するentityTokenを持っている
最初のフィーチャが、エッジを作ったフィーチャだと
判断しており、恐らく正しいと思います。

但し、

フィレットのタイプが "フィレット"で、エッジを指定している時のみ
だけです。
タイプ ”フィレット” で面を指定しているものは情報がとれません。
タイプ ”ルールドフィレット” "フルラウンドフィレット" も情報がとれません。
(上記のスクリプトではエラーになります)
役立たず とまでは言いませんが、先が思いやられる・・・。

フィレットにとって "子" 側の要素って何だろう?
もう、定義からして迷う・・・。