Skip to main content

Tutorial - AutoCAD

info

Level: Intermediate
Time: 30–45 min

Prerequisites:

  • You have a VIKTOR account and completed the installation process. No account? Get one here
  • You have AutoCAD installed and licensed on a Windows computer.
  • You can install VIKTOR Desktop on that computer and open a drawing in AutoCAD.
  • Introduction​

    Welcome to this tutorial on how to create VIKTOR apps that draw directly in AutoCAD.

    If you create structural drawings, many details follow the same rules but change from one project to another. Beam dimensions, reinforcement, bay spacing, storey heights, and member sizes may all change. Here you can choose between three App Builder prompts and a step-by-step local development example. Both paths draw in the AutoCAD file already open on your computer.

    Start with VIKTOR Desktop and the AutoCAD worker, then choose a tab in Choose your approach. The Prompt guide offers three workflows:

    1. Draw a reinforced-concrete beam detail.
    2. Draw a structural-steel stair detail.
    3. Create a parametric 3D structural frame.
    Prefer writing Python?

    If you're comfortable with Python and want to build the app yourself, select the Local development tab under Choose your approach. You'll build a simple beam-detail app step by step. Complete the AutoCAD and VIKTOR Desktop setup below first, as it applies to both approaches.

    1. Set up AutoCAD and VIKTOR Desktop​

    Both approaches use a personal worker to connect a VIKTOR app to AutoCAD on your Windows computer. First, check the VIKTOR Desktop requirements, then download and install VIKTOR Desktop and log in with your VIKTOR account.

    In VIKTOR Desktop, click Add, choose AutoCAD, and start the worker. The worker and AutoCAD must run on the same computer and under the same Windows user. Follow the AutoCAD worker installation steps if you need more detail. You do not need to install Python on the worker computer.

    Select AutoCAD in the Add worker window:

    AutoCAD highlighted in the VIKTOR Desktop Add worker window

    After starting the worker, check that its status is Running:

    AutoCAD personal worker with Running status in VIKTOR Desktop

    Before running either app:

    1. Open AutoCAD on the computer where the personal worker is running.
    2. Open the drawing you want the app to update.
    3. Check that the AutoCAD worker is running in VIKTOR Desktop.
    4. Keep AutoCAD free of open dialogs, then trigger the drawing action from the VIKTOR app.
    note

    AutoCAD needs a logged-in Windows desktop session. The worker cannot attach to AutoCAD if the application is closed or waiting on a dialog.

    2. Understand the key concepts​

    Although you can get quite far with a clear prompt, it helps to understand how the app reaches AutoCAD:

    • Personal worker: a small program managed through VIKTOR Desktop. It passes drawing operations from the VIKTOR app to AutoCAD on your own computer.
    • vkt.autocad.attach(): connects the app to the AutoCAD instance that is already open. It does not start AutoCAD or create a separate drawing. Read more in Attaching to a running instance.
    • Active drawing: the drawing currently open in AutoCAD. The generated app adds geometry to this drawing, so start with the correct file and save it yourself when the result is ready.
    • AutoCAD ActiveX API: the set of drawing operations used by the app. It can create lines, polylines, dimensions, blocks, layers, and 3D solids without sending commands to the AutoCAD command line.
    • Layers: named groups that keep concrete, reinforcement, dimensions, annotations, or 3D objects separate. A clear layer prefix makes generated content easier to review, hide, or remove.
    • Regeneration: refreshing the drawing after the app finishes. Regenerating once at the end is faster than refreshing after every object is added.
    note

    You can also use vkt.autocad.connect() to start a new AutoCAD instance, do the work, and close it when the session ends. This tutorial uses attach() to keep the drawing open so you can review and save it yourself. Both methods are BETA and require viktor >= 14.35.0.

    3. Choose your approach​

    Use the Prompt guide to generate an app with the VIKTOR App Builder, or Local development to build a small beam-detail app yourself. The Desktop and worker setup above applies to both tabs.

    Explore AutoCAD workflows with prompts​

    The following prompts help you turn common AutoCAD drawing tasks into interactive VIKTOR apps. Use the arrow on each prompt to open it in the App Builder, then adapt it to your needs. Once the app is generated, review its inputs and code before running it against your open drawing.

    Prompt 1: Draw a reinforced-concrete beam detail​

    Let's start with a reinforced-concrete beam detail. It is useful when the same drawing standard must be applied to beams with different spans, sections, reinforcement, and clear cover. The app creates an elevation and cross-section from your inputs.

    Reinforced-concrete beam detail

    Once the App Builder finishes creating the app, check the default beam dimensions and reinforcement values. Open a copy of your AutoCAD drawing, run the action, and confirm that the elevation, cross-section, dimensions, and annotations use the expected scale and layers. Here is the generated app and its beam detail:

    Reinforced-concrete beam detail in AutoCAD beside its VIKTOR App Builder preview

    tip

    Ask the App Builder to add your office layer names, colors, text style, dimension style, and bar-mark format. This turns the general example into a detail that follows your drawing standard.

    Prompt 2: Draw a structural-steel stair detail​

    The second workflow draws a steel stair in several coordinated views. It is useful when a stair's floor height, width, or riser count changes, but you still need consistent geometry and connection details.

    Structural-steel stair detail

    Once the app is ready, enter the stair dimensions and create the drawing in a test file. Check that the elevation, plan, tread section, and landing connection agree with the inputs. This example shows the generated VIKTOR app beside the AutoCAD drawing:

    Structural-steel stair views in AutoCAD beside the generated VIKTOR app

    tip

    You can extend the prompt with your standard steel sections, connection preferences, and drawing scale. Review the generated plate, bolt, and weld details against your project requirements before using them in a design.

    Prompt 3: Create a parametric 3D structural frame​

    The third workflow creates a 3D structural frame. This is useful for early design studies, when you want to compare bay layouts or member sizes and see the result in AutoCAD without rebuilding every part by hand.

    Parametric 3D structural frame

    After the app is generated, choose a layer prefix that does not conflict with the existing drawing. Change the frame inputs, run the drawing action, and inspect the columns, beams, and slab in a 3D AutoCAD view. Here is the generated app beside the frame it drew in AutoCAD:

    Parametric structural frame in AutoCAD beside the generated VIKTOR app

    tip

    Extend the prompt with grid labels, base plates, foundations, or a choice between replacing the previous result and drawing a new option. A replace option is especially useful when you want to compare several frame configurations without leaving old solids behind.

    4. Important limitations​

    The app edits the live drawing through AutoCAD's ActiveX API. Keep these points in mind:

    • The app cannot attach when AutoCAD is closed. Open AutoCAD and the correct drawing before running the action.
    • The drawing changes are real and are not rolled back automatically. Test the app on a copy of the drawing and use recognizable layer prefixes.
    • AutoCAD must remain available. A modal dialog or an active command can prevent the worker from attaching to the running instance.
    • The app cannot use interactive command-line prompts. Ask for dimensions and choices in the VIKTOR interface instead of relying on AutoCAD selections or prompts.
    • Each AutoCAD operation travels through the worker. Group repeated geometry with polylines, blocks, copies, and arrays, then regenerate once at the end.

    For the full list of supported behavior and worker errors, continue with the AutoCAD integration guide.

    To infinity and beyond!​

    Well done! You now have three starting points for creating VIKTOR apps that draw structural details and models in the AutoCAD file open on your computer.

    Continue by adapting the prompts to your drawing standards, layer conventions, and engineering checks. You can also explore the Autodesk Forma / ACC tutorial to work with Revit models stored in Autodesk Construction Cloud, or return to the tutorial overview for more examples.