VBA not working randomly with IPT files on my computer only

VBA not working randomly with IPT files on my computer only

Anonymous
Not applicable
501 Views
2 Replies
Message 1 of 3

VBA not working randomly with IPT files on my computer only

Anonymous
Not applicable

Hello,

 

I hope somebody will give ideas to explore on why iLogic rules don't work properly on my computer sometimes only. Following line of code was working properly last friday and doesn't work this morning (my computer only). I restarted Inventor and now it works. See attached image for error message.

 

 

actBomStrucInt = ThisApplication.ActiveDocument.ComponentDefinition.BOMStructure

 

I use the integer to set the value of a custom iproperty. It always works properly within assemblies but not always within parts.

 

This is not the first time I have this problem but today I have time to post for an answer. By the way, I'll be out of my office until next week so it may take some time before I get back here.

 

Thanks,

0 Likes
Accepted solutions (1)
502 Views
2 Replies
Replies (2)
Message 2 of 3

MechMachineMan
Advisor
Advisor
Accepted solution

Please look into the information provided in this blog. I do believe it could be the issue with the documents/files and how you access the component definition.

 

http://adndevblog.typepad.com/manufacturing/2016/11/ilogic-activedocumentcomponentdefinition-throws-...

 

ie; the solution is to call component definition on the explicitly declared document type.

 

Something like this:

Dim doc = ThisApplication.ActiveDocument

Dim oCD As ComponentDefinition
If doc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
  Dim assemDoc As AssemblyDocument = doc
  oCD = assemDoc.ComponentDefinition
ElseIf doc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
  Dim partDoc As PartDocument = doc
  oCD = partDoc.ComponentDefinition
End If

actBomStrucInt = oCD.BOMStructure

 


--------------------------------------
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
Message 3 of 3

Anonymous
Not applicable

 

Link you provided is almost right (in my case at least) since we can reproduce the issue with the sequence indicated but the reversed sequence reproduces the issue randomly.

 

Here is my final code to prevent this issue:

 

...
Dim actBomStrucInt As Integer

Dim doc = ThisApplication.ActiveDocument
Dim BOMStruc As BOMStructureEnum = Nothing

If doc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
	Dim assemDoc As AssemblyDocument = doc
	BOMStruc = assemDoc.ComponentDefinition.BOMStructure
ElseIf doc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
	Dim partDoc As PartDocument = doc
	BOMStruc = partDoc.ComponentDefinition.BOMStructure
End If

actBomStrucInt = BOMStruc
...

 

0 Likes