Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

python error: filter out rigidgroup entities that were removed, but still tracked in history

kymC6Q8L
Enthusiast

python error: filter out rigidgroup entities that were removed, but still tracked in history

kymC6Q8L
Enthusiast
Enthusiast

 

Hi there,

 

Im running into a problem that is driving me a little batty.

when i run the below code, i get a bunch of rigidgroup entities that have been removed, they no longer show up in the current tree, they do appear in the history ...

 

app = adsk.core.Application.get()
ui  = app.userInterface
# get active design
product = app.activeProduct
design = adsk.fusion.Design.cast(product)
exportMgr = design.exportManager
# get root component in this design
rootComp = design.rootComponent
# get all occurrences within the root component
rootOcc = rootComp.occurrences


all_rgs = rootOcc.allRigidGroups

 

is there a way i can filter these out?

the problem occurs is that i would like to get occurrences of each rigidgroup, but i cant run 

rigidGroup.occurrences

inside or outside of a try block, with out a stack track:

Failed:

Traceback (most recent call last):

File "F:/dev/SDFusion.py", line 184, in notify

exporter.getAllBodiesInRigidGroup(name,rig)

File "F:\dev\exporter.py", line 228, in getAllBodiesInRigidGroup

self.getBodies(name,rigidGroup.occurrences,0)

File "C:\Users/dev/AppData/Local/Autodesk/webdeploy/production/dc406fd0d566a1ba77afee542432c1e031a68604/Api/Python/packages\adsk\fusion.py", line 29480, in _get_occurrences

return _fusion.RigidGroup__get_occurrences(self)

RuntimeError: 2 : InternalValidationError : pJointOcc

 

Talking with the person who created the file, the rigid group was removed, but the history still keeps it around in the document, since it will take a bunch of time for some one to process all the files to history type clean up, i was wondering what i can do on the code side.

 

furthermore `rigidGroup.isValid` returns True and `rigidGroup.isSuppressed` fails with a similar stacktrace.

 

Let me know what i can do to work around this issue?

 

Cheers

Kym

0 Likes
Reply
482 Views
7 Replies
Replies (7)

kandennti
Mentor
Mentor

Hi @kymC6Q8L .

 

I don't understand what it means and could not try it because it is only a part of it.

1.png
One thing I noticed is that there is no allRigidGroups property in rootComp.occurrences.


Isn't it this way?

all_rgs = rootComp.allRigidGroups
0 Likes

kymC6Q8L
Enthusiast
Enthusiast
Sorry,
rootComp.allRigidGroups() is the correct call.







0 Likes

kandennti
Mentor
Mentor

@kymC6Q8L .

 

Since "allRigidGroups" is a property, the "()" is unnecessary.

I did not understand what "getAllBodiesInRigidGroup" does.

 

I did a quick test here and didn't see any problems.

# 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
        app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)

        des: adsk.fusion.Design = app.activeProduct
        root: adsk.fusion.Component = des.rootComponent

        # create occ
        for _ in range(3):
            root.occurrences.addNewComponent(
                adsk.core.Matrix3D.create()
            )

        # create rigid group
        objs: adsk.core.ObjectCollection = adsk.core.ObjectCollection.create()
        [objs.add(o) for o in root.occurrences]

        grp: adsk.fusion.RigidGroup = root.rigidGroups.add(objs, True)
        dumpRigidGroups('--- RigidGroup Create ---')

        # suppressed
        grp.isSuppressed = True
        dumpRigidGroups('--- RigidGroup Suppressed ---')

        # remove
        grp.deleteMe()
        dumpRigidGroups('--- RigidGroup Remove ---')

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

def dumpRigidGroups(msg):
    app: adsk.core.Application = adsk.core.Application.get()
    des: adsk.fusion.Design = app.activeProduct
    root: adsk.fusion.Component = des.rootComponent

    app.log('\n' + msg)
    grp: adsk.fusion.RigidGroup = None
    for grp in root.rigidGroups:
        app.log(f'RigidGroup Name:{grp.name}')
        for occ in grp.occurrences:
            app.log(f'  Occurrence Name:{occ.name}')

 

Here are the results of our trial.

 
--- RigidGroup Create ---
 RigidGroup Name:剛性グループ1
   Occurrence Name:コンポーネント1:1
   Occurrence Name:コンポーネント2:1
   Occurrence Name:コンポーネント3:1
 
--- RigidGroup Suppressed ---
 RigidGroup Name:剛性グループ1
   Occurrence Name:コンポーネント1:1
   Occurrence Name:コンポーネント2:1
   Occurrence Name:コンポーネント3:1
 
--- RigidGroup Remove ---
0 Likes

kandennti
Mentor
Mentor

Sorry, I didn't check enough.
It seems that the "adsk.fusion.RigidGroup.isSuppressed" property is not working properly.

 

I was mistaken.
The isSuppressed property is functioning correctly.

0 Likes

kymC6Q8L
Enthusiast
Enthusiast

Thanks for taking more time to look at this.

 

getAllBodiesInRigidGroup

 

 

is a method from the SDF exporter add in found here(https://github.com/Roboy/SDFusion), it finds all the rigid groups in the project, then finds all the bodies that are connected to it, moves them to a new component so that you can then export out a single stl for all the geometry of that group. For simulation purposes it doesnt need to know about all the individual pieces that make up the geometry, it just needs one, between 2 joints.

 

Im trying to build out a file that represents the problem im running into , I cant pass the direct file due to Nda's.

 

I tried to dig a litte further on my own as to what is happeneing.

 

i wrote a another simple snippet to give an idea of the issue, wondering if this is the correct behavour:

 

import adsk.core
import adsk.fusion



def main():
    app = adsk.core.Application.get()
    ui  = app.userInterface
    product = app.activeProduct
    design = adsk.fusion.Design.cast(product)
    rootComp = design.rootComponent
    rootOcc = rootComp.occurrences



    rgs =  rootComp.allRigidGroups

    # iterate through each
    for rg in rgs:

        print(f'parent::{rg.parentComponent.name}  rg: {rg.name}')


        if rg.isSuppressed:
            print(f' is supressed: {rg.name}')
        if not rg.isValid:
            print(f' is not valid: {rg.name}')

        occs = rg.occurrences
        print([o.name for o in occs])

 

 

in the knee file it returns:

parent::KNEE v1 rg: RigidGroup8

[]

parent::KNEE v1 rg: RigidGroup9

[]

parent::Knee Small drum rg: RigidGroup2

is supressed: RigidGroup2

['top:2', 'bottom:2']

parent::Knee Small drum rg: RigidGroup3

['top:2', 'bottom:2', '92095A199_Button Head Hex Drive Screw:1', '96887A111_Low-Strength Steel Square Nut:1', '91294A132_Black-Oxide Alloy Steel Hex Drive Flat Head Screw:1']

parent::Big Drum Assembly rg: RigidGroup1

['Knee Big drum:1', 'Intermediate Shaft:1', 'Component8:1', 'Crank:1', '91290A290_Black-Oxide Alloy Steel Socket Head Screw:1', '98689A114_General Purpose 18-8 Stainless Steel Washer:1', '96887A112_Low-Strength Steel Square Nut:1', '4668K147_Permanently Lubricated Stainless Steel Ball Bearing:1', '91294A214_Black-Oxide Alloy Steel Hex Drive Flat Head Screw:1', '91294A214_Black-Oxide Alloy Steel Hex Drive Flat Head Screw (1):1', '91292A126_18-8 Stainless Steel Socket Head Screw:1', '91292A126_18-8 Stainless Steel Socket Head Screw (1):1', '96887A112_Low-Strength Steel Square Nut (1):1', '96887A112_Low-Strength Steel Square Nut (1) (1):1', 'Square Washers:1', 'Square Washers (1):1', '91292A115_18-8 Stainless Steel Socket Head Screw:1', '91294A192_Black-Oxide Alloy Steel Hex Drive Flat Head Screw:1']

kymC6Q8L_0-1659017715610.png

In the browser in my scene, both rigid groups 8&9 are missing, i can find them in the history & the api can see them.

 

when this file is in its main project it sits like:

(main project) > leg > knee

so there is 2 levels of linked files at this point.

 

 

When i run the same short script when the knee is linked inside of  the leg, then the leg linked in side of the main project i hit that runtime error above

 

Cheers

Kym

0 Likes

kandennti
Mentor
Mentor

@kymC6Q8L .

 

I noticed in the image that "Rigid1" and "Rigid2" are Joint rigids, and "RigidGroup9" was created by RigidGroup.

1.png


I am sorry, but I am not able to reproduce the state because I do not understand what you mean.

Is it possible for you to publish a simple f3d file that can reproduce the state using that simple script?

0 Likes

kandennti
Mentor
Mentor

@kymC6Q8L .

 

I noticed in the image that "Rigid1" and "Rigid2" are Joint rigids, and "RigidGroup9" was created by "RigidGroup".

1.png


I am sorry, but I am not able to reproduce the state because I do not understand what you mean.

Is it possible for you to publish a simple f3d file that can reproduce the state using that simple script?

0 Likes