Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Internal Validation error when Moving Components within components

5 REPLIES 5
Reply
Message 1 of 6
nnamfoh
651 Views, 5 Replies

Internal Validation error when Moving Components within components

I have code that aligns a set of components that are contained within a greater component to a different components origin. I get a InternalValidation error: XL::Utils::getObjectPath(pBody,objPath,nullPtr,compPath). Error.

Its not clear to me why this happens, as the same moving code works for a component with no sub components. Does someone know what causes this error and how to fix/avoid it?

Here is a sample program that creates the error. Start it in a design with some other component ("Component1") that does not have the default origin.

#Author-
#Description-

import adsk.core, adsk.fusion, adsk.cam, traceback
def createNewComponent(rootComp):
    allOccs = rootComp.occurrences
    newOcc = allOccs.addNewComponent(adsk.core.Matrix3D.create())
    return newOcc.component
def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)
        
        
        rootComp = design.rootComponent
        comp1 = design.allComponents.itemByName("Component1")
        comp2 = createNewComponent(rootComp)
        comp3= createNewComponent(comp2)
        sketches = comp3.sketches
        sketch = sketches.add(comp3.xZConstructionPlane)
        center = comp3.originConstructionPoint.geometry
        sketch.sketchCurves.sketchCircles.addByCenterRadius(center,4)
        extrudes = comp3.features.extrudeFeatures
        prof = sketch.profiles[0]
        extInput = extrudes.createInput(prof, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        distance = adsk.core.ValueInput.createByReal(3)
        extInput.setDistanceExtent(False, distance)
        extrudes.add(extInput)    
        
        features = comp2.features
        entities = adsk.core.ObjectCollection.create()
        for body in comp3.bRepBodies:
            entities.add(body)
         # Create a transform to do move
        occs = design.rootComponent.allOccurrencesByComponent(comp1)
        occ = occs.item(0)
        origin = comp1.originConstructionPoint.createForAssemblyContext(occ)
        occs = design.rootComponent.allOccurrencesByComponent(comp2)
        occ = occs.item(0)
        partnerOrigin = comp2.originConstructionPoint.createForAssemblyContext(occ)
        ui.messageBox("My origin: "+str(origin.geometry.asArray())+"\nPartner Origin: "+str(partnerOrigin.geometry.asArray()))
        try:
            vector = partnerOrigin.geometry.vectorTo(origin.geometry)
            ui.messageBox("Translation vector: "+str(vector.asArray()))
            transform = adsk.core.Matrix3D.create()
            transform.translation = vector
            moveFeats = features.moveFeatures
            moveFeatureInput = moveFeats.createInput(entities, transform)
            moveFeats.add(moveFeatureInput)
        except: 
            ui.messageBox('Move Failed: {}'.format(traceback.format_exc()))
            pass#Check if there is unexpected, but should handle case where there is no needed movement
        if design.snapshots.hasPendingSnapshot:
            design.snapshots.add()
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
5 REPLIES 5
Message 2 of 6
ekinsb
in reply to: nnamfoh

I'm seeing a different error than you.  Probably because there's something different in how my test assembly is constructed.  It's also not apparent to me what you're actually trying to do.  Can you post an assembly and some pictures of what you're trying to accomplish?


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 6
nnamfoh
in reply to: ekinsb

My larger goal is to align two components to one another based on their origins (which I do not expect to be the default origin of the root component). In the picture attached there are 3 components. Component1 has a box. Component2 contains component3 which contains a sphere. Componen1 is not positioned on the root origin, and component2 and 3 share a different origin. The goal of the movement code in my last snippet would be to find the vector between the two non-root origins and move the bodies of component2 (and thus component3), along this vector.


If component2 contained the sphere and component3 didn't exist, there would be no problem in the code, but when component3 is internal to component2, the movement causes the error I described.

Capture.PNG

Message 4 of 6
lauren.booher
in reply to: nnamfoh

did you ever get an answer on this or figure it out?

Message 5 of 6
nnamfoh
in reply to: lauren.booher

No, the best I could ever do was move everything to true zero and then move everything back out to the new position. However it can produce weird results and I've mostly scrapped this part of my code base. 

Message 6 of 6
lauren.booher
in reply to: nnamfoh

strange. the object model is odd. They don't have common constructors. The errors are hard to follow and the developers don't seem to be active on the forums.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report