US$0.00
0

Category: macros

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 »

Merging PDFs with PDMPublisher: Enhancing Document Navigation with Bookmarks

When utilizing PDMPublisher to merge PDFs from your PDM system, one standout feature of merging PDFs with PDMPublisher is the automatic addition of bookmarks to the merged document. These bookmarks act as quick links to each component inside the merged PDF, making navigation and overall usability far better for the end user. Unlike the default PDM Convert Task, which does not provide this bookmarking capability, PDMPublisher enhances your workflow by ensuring that users can easily access specific sections of the document without having to scroll through numerous pages. This functionality not only streamlines document management but also boosts efficiency, making PDM Publisher an invaluable tool for anyone working with large assemblies or detailed drawings.

Read More »

SOLIDWORKS PDM Professional: You have chosen to load a .Net Add-in? Well, what do you do next ?

SOLIDWORKS PDM Professional employs a server-client architecture. Your files and metadata is stored on the server (Archive server is where your files and stored and everything else go in the SQL db). You push all of your changes to the server from your local PDM client and you also pull any updates from the server. This applies to PDM add-ins. When you update an existing version with a new version, that version is not automatically updated on each connected client machine. All users who want to use the latest version have to log out of PDM and log back in. PDM will actually warn you of this effect when you update an add-in from the administration tool. To ensure a proper restart of your PDM session, you can use this nice little script that will kill both Explorer.exe and EdmServer.exe and restart them again. taskkill /f /im edmserver.exetaskkill /f /im explorer.exestart explorer.exestart “Path_To_Vault” You can save these lines as a bas script by opening Notepad.exe, copy pasting the code above (make sure to replace the last line with the vault) and then saving it as a bas file. The bas file works very well for a single user environment. If your add-in has a large audience, a good idea for a PDM admin is to do the following: Having issues with your SOLIDWORKS PDM add-ins? Blue Byte Systems, Inc is here to help with your PDM customization needs. Reach out to us via contact page for a free 30-min consultation.

Read More »

Traverse Assembly Tree Recursively – SOLIDWORKS API

This topic is most definitely a recurring one. I often find myself revisiting old pieces of code I wrote a while ago and having to copy-paste. So I thought it would be a good idea to congregate all that in one useful post for future reference. In this article, we are going to explain traverse assembly tree recursively. Unfortunately, the code samples we have from the SOLIDWORKS Corp fall behind in terms of proper recursion, which is essential for navigating complex assembly structures. Below in this documentation, you will find an example that uses VBA recursion to drill down into an assembly tree effectively. The code examples provided here go beyond the basics often found in the standard SOLIDWORKS API SDK documentation, offering a more robust and reusable solution. I’ve prepared the code in C#, VB.NET, and VBA, demonstrating the easy yet effective technique to traverse assembly completely. Note: While the logic respects the assembly order, it will not traverse the FeatureManager display tree as it appears in SOLIDWORKS (i.e., it ignores components organized into folders). To traverse the FeatureManager design tree exactly as it appears, use this object. Note: The highlighted green line in the C# and VB.NET samples needs to be updated by the user with a proper assembly path. The VBA code sample assumes that an assembly document is open and active in SOLIDWORKS. VBA C# VB.NET Using these recursive functions, you have at your fingertips a powerful and effective tool for working with your SOLIDWORKS assembly data. If all you wish to do is examine the structure or SOLIDWORKS sort assembly tree alphabetically, the code presented here is a good place to begin. If you are still finding that you’re stuck or have specific questions about tailoring this code, don’t hesitate to reach out!

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