> ## Documentation Index
> Fetch the complete documentation index at: https://docs.alforse.com/llms.txt
> Use this file to discover all available pages before exploring further.

# CAD

> Sync CAD data from Onshape and Onshape Government into Alforse.

## Two Onshape connections

Alforse offers two ways to connect Onshape. Both pull data from Onshape into Alforse
and both use the same sync: they differ only in how the connection is authorized.

| Integration | Id | How it connects |
| - | - | - |
| **Onshape** | `onshape` | Alforse's own OAuth application. You press **Connect** and approve access in a popup. |
| **Onshape Government** | `onshape-government` | A private OAuth app your Enterprise owns, for the ITAR and FedRAMP edition; see [Onshape Government](#onshape-government). |

A company holds one Onshape connection at a time. Connecting the second while the
first is installed is refused with *Onshape is already connected* (or *Onshape
Government is already connected*); uninstall the current one first.

Two things come from the connection:

* **Bill of materials import.** On an item's bill of materials you pick an Onshape
  document, version and assembly and save its BOM onto a Draft make method; see
  [Import a bill of materials](#import-a-bill-of-materials).
* **Released-asset sync.** With **Sync released assets** on, released Onshape
  drawings and CAD models attach to Alforse items that already exist, matched by
  part number. It never creates items; see [Sync released assets](#sync-released-assets).

## Connect a company

In Alforse, open **Settings → Integrations**. The Onshape cards are in the CAD
category.

### Connect Onshape

Press **Connect** on **Onshape**. A popup opens on Onshape; approve access. The
popup closes on its own and the page reloads with the card installed.

### Optionally turn on released-asset sync

Open the card and switch on **Sync released assets**. **Backfill released assets**
appears once it is on.

If the connection fails, Alforse shows a message on the Integrations page:

| Message | Cause | Fix |
| - | - | - |
| *Onshape denied the connection* (write permission) | Onshape returned `invalid_scope`: the OAuth application lacks "Application can write to your documents". | Grant that permission on the OAuth application and connect again. |
| *Onshape denied the connection* | The authorization was refused in Onshape. | Connect again. |
| *The Onshape connection expired* | The sign-in state timed out. | Return to Integrations and connect again. |
| *Onshape rejected the authorization* | Exchanging the authorization code for a token failed. | Connect again; for Government, check the Onshape URL and client secret. |
| *Couldn't save the Onshape connection* | Onshape authorized but saving the connection failed. | Retry. |
| *Onshape is already connected* / *Onshape Government is already connected* | The company already has the other Onshape connection. | Uninstall it, then connect. |
| Nothing happens on Connect | The browser blocked the popup (Alforse then navigates the page to Onshape instead). | Allow popups for Alforse and retry. |

## Onshape Government

**Onshape Government** is Onshape's ITAR and FedRAMP edition. Because it has no public App Store, your Enterprise must create a **private OAuth app** for Alforse. After connection, it supports document browsing, bill-of-materials imports, and released-asset synchronization.

### Create the private app in Onshape

An Enterprise admin opens **Enterprise settings → Developer → OAuth applications** and creates a new OAuth
application. Name it Alforse, give it a unique primary format, and choose **Connected Cloud App** as the type.
Set the redirect URL to `https://app.alforse.com/api/integrations/onshape-government/oauth`; the Onshape
Government drawer in Alforse shows the exact redirect URL and OAuth URL to paste. Grant **Application can read
your profile information**, **Application can read your documents** and **Application can write to your
documents**. Onshape shows the client secret only once, so copy it immediately. Alforse support can help create
the app if given a seat in your Enterprise.

### Enter it in Alforse

Open **Onshape Government** under **Settings → Integrations**. Enter your Onshape URL (it must be an
`https://` address) and the app's client ID and client secret.

### Approve the connection

Save the settings. Alforse sends you to Onshape to approve the connection; return to Alforse afterwards.

| Setting | What it controls |
| - | - |
| Onshape URL | The address your team signs in to Onshape Government at. Each Enterprise has its own. |
| Client ID / Client secret | The private OAuth app from your Enterprise. The secret is stored encrypted. Leave it empty to keep the saved one, or enter it again to reconnect. |
| Sync released assets | Same as on Onshape: pulls released drawings and models onto matching items. |

HEADS UP

A private app's API calls count toward your Enterprise's **yearly Onshape API limit**. Browsing and importing
a bill of materials take a few calls each. Released-asset sync takes several calls per released revision, so
leave it off if your allowance is tight.

## Import a bill of materials

With an Onshape connection installed, an item's **Bill of Materials** shows an Onshape
card. Open it with the arrow and choose the **Document**, **Version** and **Assembly**
(the BOM comes from a saved version of the document). **Fetch** reads the Onshape BOM
and lists its rows in a **Bill of Materials** box; rows whose part has no part ID are
marked *No part ID*. **Save** writes the rows to the make method. The card shows
*Last synced* once a BOM has been saved, and **Refresh** reloads the list.

The card is only usable while the make method is a **Draft**; on an Active method it
is disabled. Saving needs the **parts: update** permission. Saving makes the method's lines equal to the Onshape BOM, sub-assemblies included. A
sub-assembly whose released method differs from Onshape is refused: create a new
version of it (a Draft) and save again.

## Sync released assets

**Sync released assets** is off by default. When on, Onshape notifies Alforse of
releases and Alforse attaches the released assets to existing items:

* the CAD model of a released part or assembly, as the item's 3D model;
* the released drawing, as a PDF named after the part number and revision.

Items are matched by part number and revision against the item ID. A drawing numbered
`DRW-<number>` is attached to `PRT-<number>` or `ASM-<number>`. When no item or more
than one item matches, nothing is attached: the sync links only and never creates
items. Repeating a release attaches nothing twice.

**Backfill released assets** (on the card, shown when sync is on) pulls the already
released assets for all matching items now instead of waiting for new releases. It
needs the **settings: update** permission.

Asset sync needs the write permission on the OAuth application; without it the card
asks you to reconnect to grant write access.

## Related

**Items**

The part records CAD data attaches to.

[Open](/docs/reference/items.md)

**Methods & sourcing**

How a part's bill of materials is built up.

[Open](/docs/reference/methods.md)

**Revisions**

Why each revision of a part is its own item record.

[Open](/docs/reference/items.md#revisions)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.