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: 

How to apply a circular pattern to a component?

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
258 Views, 2 Replies

How to apply a circular pattern to a component?

Hi guys! 
I have an assembly which I download from web-server. But the problem is that I don't know how to get sketch or components to change number of holes, nuts and bolts using circular pattern. 
Here's the code: 

import adsk.core, adsk.fusion, traceback

import urllib.request
import urllib.error
import urllib.parse
import pathlib

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface

        url = "http://195.133.144.86:4200//FlangeAssemblyGOST.f3d"
        occ = importComponentFromURL(url)

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

# F3D File Only
def importComponentFromURL(url) -> adsk.fusion.Occurrence:
    app = adsk.core.Application.get()
    ui = app.userInterface

    # doc check
    doc :adsk.fusion.FusionDocument = app.activeDocument
    if not doc.dataFile:
        ui.messageBox('Please save the document once.')
        return adsk.fusion.Occurrence.cast(None)

    # get path
    # folder = pathlib.Path(__file__).resolve().parent
    # parsed = urllib.parse.urlparse(url)
    # filename = parsed.path.split('//')[-1]
    # dlFile = folder / filename

    folder = pathlib.Path(r'C:\Temp')
    if not folder.exists():
        folder.mkdir()

    parsed = urllib.parse.urlparse(url)
    filename = parsed.path.split('//')[-1]
    dlFile = folder / filename

    # suffix check
    if dlFile.suffix != '.f3d':
        ui.messageBox('F3D File Only')
        return adsk.fusion.Occurrence.cast(None)

    # delete download file
    if dlFile.is_file():
        dlFile.unlink()

    # file download
    try:
        data = urllib.request.urlopen(url).read()
        with open(str(dlFile), mode="wb") as f:
            f.write(data)
    except:
        ui.messageBox(f'File not found in URL\n{url}')
        return adsk.fusion.Occurrence.cast(None)


    app.executeTextCommand(u'Fusion.ImportComponent {}'.format(dlFile))
    app.executeTextCommand(u'NuCommands.CommitCmd')

    # delete download file
    if dlFile.is_file():
        dlFile.unlink()

    des = adsk.fusion.Design.cast(app.activeProduct)
    comp = des.activeComponent
    return comp.occurrences[-1]

 

Labels (2)
2 REPLIES 2
Message 2 of 3
BrianEkins
in reply to: Anonymous

There isn't an easy way because the model wasn't designed with the intent that the number of holes or parts can be edited that way.  For example, in the main part called Полумуфта, the two holes are defined by two circles on either side of the part and they are extruded.  Instead, it could be designed by defining one of the holes and then using the circular pattern feature to define the location of the second hole.  Because the pattern is parametric, you will be able to easily modify the number of holes.  The same is true for the bolts.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 3 of 3
Anonymous
in reply to: BrianEkins

Hello @BrianEkins! The problem is that half-coupling uncludes 2 different holes with different diameters (I cannot make a circular pattern with number of selectd objects which is equal to 1). In 1st execution of half-coupling I had to design it in that way. But the number of holes, nuts and bolts has to change in next execution. That's why I try to get sketch and faces of components and apply circular pattern to them. 

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

Post to forums