US$0.00
0

Author: Amen Jlili

SOLIDWORKS PDM API: Optimizing Large Scale Operations with Batch Interfaces in SOLIDWORKS PDM

When making numerous calls to the same operation in SOLIDWORKS PDM, the batch interfaces (e.g., IEdmBatchAdd2, IEdmBatchChangeState5) are designed to maximize efficiency and performance. Optimizing large scale operations with batch interfaces in SOLIDWORKS PDM becomes essential when handling high file volumes, helping reduce processing time and system strain while maintaining reliable automation. Here’s a list of all the batch interfaces in PDM and their intended uses. Interface Description IEdmBatchAdd2 Allows adding multiple files or folders to the vault with improved support for additional options. IEdmBatchChangeState5 Enables batch transitioning of files to a different workflow state with the most advanced features. IEdmBatchDelete3 Provides functionality for deleting multiple files from the vault with enhanced validation. IEdmBatchItemGeneration2 Facilitates batch generation of items, ensuring efficient handling of linked item creation. IEdmBatchListing4 Retrieves detailed lists of files, folders, or items in the vault with extended filtering options. IEdmBatchUnlock2 Check-in operation for multiple files in a batch, including support for conditional operations and error handling. IEdmBatchUpdate2 Updates properties or variables for multiple files in the vault with better performance and reliability. You may also read: SolidWorks Macro to Batch Rebuild and Export Drawings to PDF

Read More »

SOLIDWORKS PDM API TIP: Stop Using File Names in PDM Automation – Here’s Why IDs Are Better

When developing automation tools or add-ins for SOLIDWORKS PDM, one of the most common mistakes I see is relying on file paths or names to identify objects. Stop using file names in PDM automation because, at first glance, it seems logical—after all, files have names, right? But here’s the problem: file names and paths are fragile. Users can (and will) rename files, move folders, or reorganize entire directories. The moment that happens, your automation breaks. Enter Immutable IDs SOLIDWORKS PDM assigns a unique, immutable ID to every object—files, folders, data cards, you name it. These IDs never change, no matter what the user does. By using these IDs in your scripts and add-ins: Real-World Example Let’s say your script updates a custom property on all files in a certain folder. If you use the folder path and someone moves it, your script won’t find it. If you use the folder’s ID, it works no matter where it lives. The Takeaway Best practice: Always use IDs to identify objects in SOLIDWORKS PDM. Paths and names are for humans. IDs are for automation.

Read More »

Most Useful API Calls to Optimize SOLIDWORKS Performance

Writing SOLIDWORKS macros and add-ins is a wonderful thing to do in order to save repetitive work. But nothing spoils the experience more quickly than sluggish performance. A performance-intensive macro can negate any productivity gain and drive users bughouse. So, how do we make our SOLIDWORKS API macros and add-ins soar? This is where understanding useful API calls to optimize SOLIDWORKS performance becomes essential, helping you write faster and more efficient automation. The answer is in some special API calls and best practices that keep SOLIDWORKS from wasting time doing unnecessary work behind our backs. Let’s dive into the most precious SOLIDWORKS API optimization techniques and take your code flying! How to Speed Up and Optimize the SOLIDWORKS API When your attempts at optimizing SOLIDWORKS performance stop in their tracks, it is usually because your code is causing SOLIDWORKS to do things that are not necessarily required in order for the task to be executed. UI updates, feature tree updates, and screen redraws take even the most mundane macro forever to do. The below API calls are your weapon to combat this issue. 1. What is CommandInProgress? Think of CommandInProgress as telling SOLIDWORKS, “Hey, I’m busy doing something important, so don’t bother with UI updates or other background processes until I’m done.” Setting this property to True is one of the most effective ways to significantly improve macro execution speed, especially when performing complex tasks. Use it: Remember to set CommandInProgress to False once your operation is done. If you don’t, part of the SOLIDWORKS UI will be unusable, and you’ll need to manually restart SOLIDWORKS in order to fix it. 2. DoEvents This is an old VBA and VB.NET call that releases control to the operating system so it can respond to other events while your macro is executing. It’s great for making the UI responsive during lengthy operations so the user has a chance to click a cancel button or observe an updating progress bar. Use it with caution, though! Multiple calls to DoEvents will really slow down your macro. For optimum performance, in the majority of situations, don’t call DoEvents at all. Example: 3. AddToDB Manual creation of new sketch entities, SOLIDWORKS will usually try to snap them to nearby geometry or grid points to assist the user. Useful for manual sketching, but wasteful when creating programmatically. AddToDB allows you to avoid this snapping process and add entities directly into the database, which can result in a performance gain. Example: 4. DisplayWhenAdded Similar to AddToDB, this API call is a great way to speed up the generation of sketches. If you call DisplayWhenAdded with False, you prevent SOLIDWORKS from adding new sketch entities to the screen until you’ve specifically requested it to. This is a real time-saver when macros are creating a lot of sketch entities. Example: 5. EnableFeatureTree The FeatureManager Design Tree of SOLIDWORKS is a wonderful piece of work, but constant updating during the middle of a macro is a performance and efficiency killer. You can avoid the tree from being updated until you are done with your activities by using EnableFeatureTree = False. Example: 6. EnableConfigurationTree If the macro is manipulating configurations, you might be able to gain some speed by disabling the config tree updates using EnableConfigurationTree. Example: 7. EnableGraphicsUpdate This is a mandatory use for any macro that performs geometry-intensive actions. Setting EnableGraphicsUpdate to False stops the SOLIDWORKS graphics window from updating while your code makes its changes, resulting in an incredible performance gain. Make sure to set it back to True afterward, however, so the user can see the results! Example: 8. UserControlBackground To obtain the optimum speed boost, you can hide the full SOLIDWORKS application window through UserControlBackground. This is useful when you have a stand-alone application that is doing a very complex, non-visual task. Example: 9. Lock/Unlock Model The Lock API call will exclude the user from seeing the UI while your macro is running. This can be useful to get the user out of your hair so that user activity won’t interrupt your code. Be aware, however, that certain API calls, like InsertNote, will not function if the model is locked. Example: 10. Do not use Excel Interop dll If you’re writing a .NET add-in or desktop application and you’re reading from or writing to Excel, it is recommended that you use the services of a library called EPPlus instead of the Excel interop DLL. You will notice a far better performance outcome when you make the switch. By using these API calls wisely, the performance of SOLIDWORKS macros and add-ins can be significantly optimized. The conclusions in summary are:

Read More »

SOLIDWORKS PDM API TIP: Writing Add-ins with Version-Specific APIs

When writing an add-in for SOLIDWORKS PDM, it is essential to consider compatibility across different versions of the software. Some API calls introduced in newer versions may not be available in older versions, potentially causing runtime errors for clients using older systems, which is why writing add-ins with version-specific APIs becomes so important. Scenario Suppose your add-in uses an API feature introduced in SOLIDWORKS PDM 2022, but some clients are still using SOLIDWORKS PDM 2018. To ensure compatibility, you can programmatically check the PDM version installed on the client’s machine before calling the new API. Solution: Use the GetVersion Method The GetVersion method allows you to retrieve the major and minor version numbers of the installed SOLIDWORKS PDM Professional. Based on the version, your code can decide whether to execute the new API call or fall back to an alternative logic for older versions. Implementation Here is an example in Visual Basic: This approach ensures your add-in remains robust and user-friendly, even in environments with mixed PDM versions, highlighting the importance of writing add-ins with version-specific APIs.

Read More »

SOLIDWORKS PDM API Tip: Ideal Number of Add-ins Per SOLIDWORKS PDM Vault

Your add-ins consist of DLL files. Each time an application like explorer.exe logs into PDM, it loads those files into the application’s sessions, increasing startup time and memory usage. While memory use is not a major issue these days, startup time can be noticeably affected. This is why it’s essential to ideal number of add-ins per SOLIDWORKS PDM vault, as having too many add-ins can significantly impact user performance and responsiveness. The ideal number of add-ins is five, but PDM already includes three default ones: This means you only have 2 slots left for custom add-ins before performance starts to degrade. Each add-in adds overhead, increasing vault load times. Instead of multiple separate add-ins, merge functionalities into one to keep performance smooth. ✅ PDM already has 3 built-in add-ins, leaving space for just 2 custom add-ins.✅ Too many add-ins slow down vault operations.✅ Merging multiple add-ins into one improves performance & simplifies maintenance.

Read More »

A Tetris Game in SolidWorks VBA Macro

TLDR: You can download a tetris game in SOLIDWORKS VBA macro by providing your email address. Here are the instructions to play: In this article, we’re diving into how you can create the iconic Tetris game in SOLIDWORKS using a custom VBA macro. I’m calling this project SOLIDWORKS Tetris, and it’s a fun way to combine gaming with CAD modeling. Using SOLIDWORKS’ API, I’ve managed to recreate the classic Tetris mechanics: falling blocks, collision detection, rotating pieces, clearing lines, and even an online high-score system. Here’s a breakdown of how I built SOLIDWORKS Tetris and how you can make your own version too! Getting Started The first thing you’ll want to do is set up the board. Using SOLIDWORKS, we create a grid of cubes, each one representing a block in the game. The grid is 10 columns wide and 20 rows high, just like the original Tetris game. We use SOLIDWORKS to generate small cubes and position them in the grid, creating the visual representation of the game space. Creating the Tetris Shapes Next, we define the seven standard Tetris shapes. Each shape has different rotations, and we store these rotations in an array. You’ve got the classic shapes like the I, O, and T blocks, and these are represented by four blocks each, rotating in different ways. I’ve set up a few of these shapes, but you can add the rest (S, Z, J, L) as well! Collision Detection Collision detection is a big part of Tetris, and we need to make sure the pieces don’t overlap or move outside the grid. I check for collisions whenever a piece moves or rotates. The game will stop the piece from moving if it’s out of bounds or collides with another piece already on the board. Rendering and Moving the Pieces Once the pieces are defined, it’s time to make them move! Each piece starts at the top of the board, and you control it using the arrow keys on your keyboard. I use the GetAsyncKeyState function to capture the input and move or rotate the piece accordingly. As the pieces fall, I check for collisions each time the piece moves. If the piece hits the bottom or another block, it locks into place, and a new piece appears at the top. Clearing Lines and Scoring When a line is completely filled, it gets cleared, and all the blocks above it drop down. I keep track of the score, giving you points every time you clear a line. The more lines you clear, the higher your score! Game Loop The game runs in a loop where: As you play, the game speeds up, making it more challenging over time! User Input To control the pieces, you simply use the arrow keys: High Score System I added a high-score system to make the game more competitive. After each game, your score is saved online, and you can check out the top scores. You’ll even get a global leaderboard to see how you rank! You can also see the top scores within your company by sharing a unique company ID, making it a fun challenge among coworkers. Get the Source Code If you want to dive deeper into SOLIDWORKS Tetris and access the source code, it’s available when you purchase the SOLIDWORKS API course bundle from Blue Byte Systems Inc. This course bundle will teach you how to harness the power of the SOLIDWORKS API for projects like this and many more! Wrapping Up Building SOLIDWORKS Tetris was a fun and creative project. It combines the logic of game development with the power of SOLIDWORKS’ API to create something completely unique. Whether you’re a SOLIDWORKS user, a game enthusiast, or just someone looking for a cool project, this is a great way to get hands-on with SOLIDWORKS and the API. Get Tetris Below

Read More »
0
    0
    Your Cart
    Your cart is emptyReturn to Shop
    0
      0
      Your Cart
      Your cart is emptyReturn to Shop