Help with VBA code that is crashing

Help with VBA code that is crashing

Anonymous
Not applicable
688 Views
3 Replies
Message 1 of 4

Help with VBA code that is crashing

Anonymous
Not applicable

I have a fully automated model of a machine that the company I work for makes. I have 8 different rules running in the main model assembly file to change everything about the machine, such as components for different styles and overall machine material. There is one rule that has lines of VBA in it--this code changes the material of the nuts, bolts, and washers in the machine. I'm at the point where I'm creating drawing sets for this machine now. However, every time I finish creating one set, I have to go back to the main model and run component switching codes so I can make a new drawing set. But when I go to do this, I find that an error appears and the machine cannot run its component change codes. I've pinpointed the rule and the exact spot in it where the problem happens.

 

The first image I've attached is the rule with the VBA code in it, the second image is the error message.

 

The problem occurs in the code where I have a "MesageBox.Show" line tabbed out. There is only one other person in this company that knows anything about advanced Inventor use; I don't know as much as him, but he says that my problem is that the VBA in this rule is crashing and not allowing the model to complete its changes. The only solution he and I have so far is to restart the computer. It works, but I can't keep doing this every time I make a set of drawings. But until we can figure something out, it's all I can do.

 

This is a company computer, here are its specs: HP z210 Workstation, Intel Xeon CPU E31240 @ 3.30 GHz, 8 GB RAM, 64-bit operating system, running on Windows 7 Professional. I'm using Inventor 2016. All my Inventor files and its templates are stored on the company's server. I'm getting ready to request a better computer, because this model is only the smallest machine this company makes. The next machines I work on are going to generate much bigger and more complex models. I'm hoping someone can examine my problem and help me figure out what the problem is, where it's code or computer hardware related. But if anyone could maybe help me out here, I would greatly appreciate it. Thank you

0 Likes
689 Views
3 Replies
Replies (3)
Message 2 of 4

MechMachineMan
Advisor
Advisor

If it fails at the "ThisDoc" line, it's likely issues with what file type it is trying to call .Document on. Or it could be that the file is not open.

 

If it fails at the .ComponentDefinition line, it's because it can't grab the component definition of the doc you are trying to call it on. This could be if it somehow is trying to call THAT specific rule in a drawing.

 

Good luck.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 4

Anonymous
Not applicable

But I have never had this problem occur until I started creating drawings for the components of the machine. This code has been running and working for months. What would make it start to crash after each time I make a drawing?

0 Likes
Message 4 of 4

richard.joseph.pollak
Advocate
Advocate

If you didn't have problems until after you started making drawings, is it possible that you're setting oDoc to be the drawing document by mistake rather than the model document?

0 Likes