How to add isNewComponent from a Ptr<CombineFeatureInput> to selected component

How to add isNewComponent from a Ptr<CombineFeatureInput> to selected component

Anonymous
Not applicable
1,581 Views
11 Replies
Message 1 of 12

How to add isNewComponent from a Ptr<CombineFeatureInput> to selected component

Anonymous
Not applicable

 

If a new component is added using the Ptr<CombineFeatureInput>->add method, with isNewComponent set

to true, the new component is added to the active component. How can the parent component

be changed?

0 Likes
Accepted solutions (1)
1,582 Views
11 Replies
Replies (11)
Message 2 of 12

erik
Advocate
Advocate

You have to get a reference to the occurrence of the component you want to activate.

With this reference you can use the code:

 

#include <Fusion/Components/Occurrence.h>

returnValue = occurrence_var->activate();

Above code is taken from the documentation of the method Occurrence.activate.

 

To get a reference to an occurrence call the method component.occurrences.itemByName

 

#include <Fusion/Components/Occurrences.h>

returnValue = occurrences_var->itemByName(name);

If this didn't answer you question or you have anymore questions please reply.

 

- Erik

0 Likes
Message 3 of 12

Anonymous
Not applicable

Thanks, that code activates the correct component I want the newly created component to belong to,

but the new component still appears at the top level of the design.

 

So I'm back to square one - how do I choose where the new component created by a

Ptr<CombineFeatures>  add, with isNewComponent = true, is placed in the hierachy

of components?

0 Likes
Message 4 of 12

erik
Advocate
Advocate

When you create you feature isn't it done with something like this:

 

Ptr<Features> propertyValue = component_var->features();

Most features (if not all) are connected to a component eg. rootComponent.

If you instead use a reference to the destination component you should see the new component under that component.

 

Hope this makes sense and work for you, otherwise please reply.

 

- Erik

0 Likes
Message 5 of 12

Anonymous
Not applicable

My code is:-

      static Ptr<BRepBody> FuseComponents
//    ===================================
      (
        Ptr<Component> &         Parent, //!<
        Ptr<BRepBody> &          Head,   //!<
        Ptr<ObjectCollection> &  Tail    //!<       ObjectCollection of BRepBody
      )
      { 
        Ptr<Features>            features             = Parent->features();
        Ptr<CombineFeatures>     combineFeatures      = features->combineFeatures();

        Ptr<CombineFeatureInput> combineFeaturesInput = combineFeatures->createInput ( Head, Tail );
 
        bool Flag = combineFeaturesInput->isKeepToolBodies(false);
             Flag = combineFeaturesInput->isNewComponent(true);
             Flag = combineFeaturesInput->operation(JoinFeatureOperation);

        Ptr<CombineFeature>      combineFeature       = combineFeatures->add ( combineFeaturesInput );

//      Now return the newly created body

        Ptr<BRepBodies>          Bodies               = combineFeature->bodies();
        Ptr<BRepBody>            Body                 = Bodies->item(0);

             Flag = Body->name ( "The new one!" );

        return Body;
      }

The body appears in the grandparent, not the parent as I would like. The grandparent happens to be the

rootComponent. And when I started with this quest was active (by default), which is what lead my down the

"activate the parent" rabbit hole. As you can see, the combineFeature is part of the features of the parent,

but the new component (with its solitary "The new one!" body) is created in the grandparent.

0 Likes
Message 6 of 12

erik
Advocate
Advocate

I am a Python programmer and I am not sure I read you code correctly, but from what I can see in your code you are creating a variable of type Component named Parent.

But where is the reference to the actual component in you design?

 

That is the only thing I can find looking through your code.

 

- Erik

0 Likes
Message 7 of 12

Anonymous
Not applicable

I have a 3 level tree of valid components created by extrude, revolve etc. It all works, except my combine.

 

Tree branches (children) are created by:-

      static Ptr<Component> CreateSubComponent
//    ========================================
      (
        Ptr<Component> &       Parent,
        Ptr<Matrix3D> const &  Transform,
        std::string const &    Name = ""
      )
      {
        Ptr<Occurrences> occurrences  = Parent->occurrences();       
        Ptr<Occurrence>  occurrence   = occurrences->addNewComponent ( Transform );
        Ptr<Component>   subComponent = occurrence->component();
        subComponent->name ( Name );  
        return subComponent;      
      }

How would you solve in Python?

 

 

 

0 Likes
Message 8 of 12

erik
Advocate
Advocate

After testing this thorougly in Fusion with python code I can't the new combined body to end up anywhere but in the RootComponent. This has to be a bug or some functionality hidden to us.

 

Maybe @BrianEkins or @marshaltu knows the answer?

 

The code in my run method would be

 

app = adsk.core.Application.get()
        ui  = app.userInterface
        
        componentSel = ui.selectEntity('Select a body', 'Occurrences')
        occ = componentSel.entity
        
        design = adsk.fusion.Design.cast(app.activeProduct)
        if not design:
            ui.messageBox('No active Fusion 360 design', 'No Design')
            return
        
        comp = design.rootComponent
        
        targetBody = comp.bRepBodies.itemByName("Body1")
        toolBody =  comp.bRepBodies.itemByName("Body2")
        toolBodies = adsk.core.ObjectCollection.create()
        toolBodies.add(toolBody)
        
        combinedBody = fuseComponents(occ.component, targetBody, toolBodies)

And in my fuseComponents method

def fuseComponents (component, targetBody, toolBodies):
    newBody = adsk.fusion.BRepBody.cast(None)
    
    features = adsk.fusion.Features.cast(None)
    features = component.features
    combineFeatures = features.combineFeatures
    combineFeatureInput = combineFeatures.createInput(targetBody, toolBodies)
    
    combineFeatureInput.isKeepToolBodies = False
    combineFeatureInput.isNewComponent = True
    combineFeatureInput.operation = adsk.fusion.FeatureOperations.JoinFeatureOperation
    
    combineFeature = combineFeatures.add(combineFeatureInput)
    
    bodies = combineFeature.bodies
    newBody = bodies.item(0)
    newBody.name = "The new One!"
    
    return newBody

I am sorry I can't help you any further.

 

- Erik

 

0 Likes
Message 9 of 12

Anonymous
Not applicable

Thank you very much for trying this in Python. At least now I know its not a complete "stupid" on

my part. Its either a bug, a feature, or there is some obscure work around hidden deep in the documentation.

 

It will have to wait until the Autodesk people are back.

0 Likes
Message 10 of 12

marshaltu
Autodesk
Autodesk

Hello,

 

I checked the behavior of combine feature in Fusion 360 UI. It looks be same with one in Fusion API. Please refer to the following screencast. I am not sure if it is bug or not. I will check it with our modeling experts. 

 

https://autode.sk/2smsIz8

 

Thanks,

Marshal



Marshal Tu
Fusion Developer
>
0 Likes
Message 11 of 12

erik
Advocate
Advocate

Thank you @marshaltu!

 

The screencast shows the same result, but it is not the desired result.

Even though the other component is active, the new component ends up under the root component.

 

- Erik

0 Likes
Message 12 of 12

marshaltu
Autodesk
Autodesk
Accepted solution

Hello,

 

Yes, I have confirmed with our modeling team. It did not be a desired behaviour. FUS-40520 has been logged to track the issue in our internal system.

 

Thanks,

Marshal



Marshal Tu
Fusion Developer
>