How to add curves from a ProfilesCurves collection to an ObjectCollection? C++

How to add curves from a ProfilesCurves collection to an ObjectCollection? C++

Anonymous
Not applicable
823 Views
2 Replies
Message 1 of 3

How to add curves from a ProfilesCurves collection to an ObjectCollection? C++

Anonymous
Not applicable

Hi All,

 

I'm trying to add curves from an outer ProfileLoop to an ObjectCollection for later offset. The following code is crashing however. Any pointers (no pun intended) as to what's going on?

 

Thx,

 

Rod.

 

        Ptr<Profiles> profiles = sketchIn->profiles();

        Ptr<ObjectCollection> curvesForOffset = ObjectCollection::create();

 

 

        for (Ptr<Profile> profile : profiles)

        {

            

            Ptr<ProfileLoops> loops = profile->profileLoops();

            

            for (Ptr<ProfileLoop> loop : loops)

            {

                Ptr<ProfileCurves> loopCurves = loop->profileCurves();

                if (loop->isOuter())

                {

                    curvesForOffsetOut = sketchIn->findConnectedCurves(loopCurves->item(0));

                }

            }

        }

0 Likes
Accepted solutions (1)
824 Views
2 Replies
Replies (2)
Message 2 of 3

ekinsb
Alumni
Alumni
Accepted solution

You're mixing two different things here that can't be mixed.  Although it's completely understandable how you would make that mistake.  In the picture below I've drawn three lines in a sketch.  Only in one of the corners do the line lines geometrically connect at their ends.  At one of the other two corners they overlap and at the other one butts up to the other.  The triangular profile is also shown.  If I was to get the Profile loop for this profile it would consist of three ProfileCurve objects and they are represented in the picture below by the black lines.  These curves don't really exist in the sketch but are just the results of the profile being calculated and are only part of the profile.  I can't offset profile curves.  You can only offset sketch curves.

 

Profile.png

 

If you know you have clean sketches where the sketch curves connect end-to-end then they will match the profile curves.  In the Python code below, (it was quicker to write and test than C++), I do what you described by getting the outer profile loop and iterating over its curves, but for each ProfileCurve I get the associated sketch entity and add that to the collection and then that's what is offset.  Hopefully that makes some sense.

 

def run(context):
    try:
        des = adsk.fusion.Design.cast(app.activeProduct)
        sketchIn = adsk.fusion.Sketch.cast(des.activeEditObject)
        profiles = sketchIn.profiles
        
        curvesForOffset = adsk.core.ObjectCollection.create()

        profile = adsk.fusion.Profile.cast(None)
        for profile in profiles:
            loops = profile.profileLoops            
            
            if loops.count > 1:            
                loop = adsk.fusion.ProfileLoop.cast(None)
                for loop in loops:
                    if loop.isOuter:
                        curve = adsk.fusion.ProfileCurve.cast(None)
                        for curve in loop.profileCurves:
                            curvesForOffset.add(curve.sketchEntity)

        if curvesForOffset.count > 0:
            sketchIn.offset(curvesForOffset, adsk.core.Point3D.create(0,0,0), 1)                        
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 3

Anonymous
Not applicable

Hi Brian,

 

Awesome explanation, don't think I would have figured that out alone:-) My code is back in action.

 

Many thanks,


Rod.

0 Likes