Microsoft .NET Error

Microsoft .NET Error

donaldleigh
Advocate Advocate
1,504 Views
17 Replies
Message 1 of 18

Microsoft .NET Error

donaldleigh
Advocate
Advocate

Hi all

 

Here is a strange one for me anyway

 

I have the code below that works with no errors when its in an Internal Rule but when I made this an external rule I now have the following error.

 

The error is happening on the 1st line of code as I have done the debug as suggested in the past by MechMachineMan

 

Any ideas why??

 

SyntaxEditor Code Snippet

BStruture = InputListBox("Choose BOM Structure", MultiValue.List("BOM_Structure"), BOM_Structure, Title := "Title", ListName := "List")
Select Case BStruture
Case "Normal"
ThisDoc.Document.ComponentDefinition.BOMStructure = BOMStructureEnum.kNormalBOMStructure
Case "Phantom"
ThisDoc.Document.ComponentDefinition.BOMStructure = BOMStructureEnum.kPhantomBOMStructure
Case "Reference"
ThisDoc.Document.ComponentDefinition.BOMStructure = BOMStructureEnum.kReferenceBOMStructure
Case "Purchased"
ThisDoc.Document.ComponentDefinition.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure
Case "Inseparable"
ThisDoc.Document.ComponentDefinition.BOMStructure = BOMStructureEnum.kInseparableBOMStructure
End Select
0 Likes
1,505 Views
17 Replies
Replies (17)
Message 2 of 18

NachoShaw
Advisor
Advisor

Hi

 

If you click the arrow on the details button, it gives you a better indication of what is wrong and on what line. As the error is an Object Reference error and the fact that it works internally but not externally, I would suggest either

 

a reference to Inventor

or

a reference to the active document

 

When its internal, it already has a reference, when its external, it needs to know what document you are processing in what application

 

 

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
Message 3 of 18

matt_jlt
Collaborator
Collaborator

I just made a new document, added the parameters to the same parameter name and ran your rule as an external ilogic rule using Inventor 2018. It ran with no problems.

 

You need to expand the error message "Details" box and paste the error messages so we can see what the issue could be. Also, post the version of Inventor you are running as there could possibly be a bug depending on what you are running.

 

Matt.

 

 

0 Likes
Message 4 of 18

donaldleigh
Advocate
Advocate

Hi Guys

 

Thanks both for your help.

 

I have tried your suggestion NachioShaw but could not get it to work still

 

Matt, Please see attached error details.

 

When I press the Continue button the rule seems to run as normal. I forgot to add that to my original post. 

 

I'm using 2014

 

 

0 Likes
Message 5 of 18

NachoShaw
Advisor
Advisor

Hi

 

Why dont you try posting your code seeing as thats the issue? There is an obvious problem which is you are referencing an object that hasnt been set. for example:

 

Dim oDoc As Inventor.DrawingDocument
Dim oSheet As Inventor.DrawingSheet = odoc.DrawingSheet

in the instance above, you will get a 'Object Reference has not been set' error because i am trying to use oDoc before i have set it.

 

We can help you, things do not need to be so cryptic

 

 

 

Nacho

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
Message 6 of 18

donaldleigh
Advocate
Advocate

the code is posted in my original post here.

 

i'm running this rule in a part or assembly. not a drawing

 

Not sure what else you need???

0 Likes
Message 7 of 18

NachoShaw
Advisor
Advisor

well..... its a code 'snippet'......

 

without checking, when you set up a ComponentDefinition you need the component. Each part (component) has a BOM structure. your code doesnt show you looping though any assembly parts and setting the ComponentDefinition to each part. In order to get information from a componentDefinition, it needs to know what Component to use

 

Imagine taking your car to a mechanic and asking him to fix your engine but not letting him look at the engine first....

 

FYI

the example i provided was only an example. That is why i said "For Example"

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
Message 8 of 18

matt_jlt
Collaborator
Collaborator

What NachoShaw is saying is that the code you provided if run on its own has no issues. If you create a new blank rule and run it there are no issues. While this code runs fine on its own, there is some other part of your ilogic rule that is affecting it.

 

The error is stating that you are trying to assign an object to something that doesn't exist / the reference isn't set. And it looks like it is during the creation of your input box.

You may have accidently duplicated a variable name or maybe you have Ticked run straight VB code or trying to do something more advanced that is affecting it for some reason, or you may have this rule inside of a sub routine that is causing it issues.

It could also be an issue with inventor 2014 but I can't check that for you as i am on 2018.

 

If you don't want to post your full code that is understandable but there is no issue with the code you have that I can see.

 

More than happy for you to PM me the code if you want me to have a look.

 

Matt.

0 Likes
Message 9 of 18

donaldleigh
Advocate
Advocate

This is the full code. nothing else

 

I have a form that controls all the data input of a part or assembly. One of them will be to select the type of BOM Structure via this rule.

 

 

0 Likes
Message 10 of 18

matt_jlt
Collaborator
Collaborator

Ok, It may just be a bug in Inventor 2014. Just an idea, may not work but try this.

 

 

 

' Add this to the very top of your ilogic code
Imports System.Windows.Forms

 

another suggestion is change the top line to the following.

 

BStruture = InputListBox("Choose BOM Structure", MultiValue.List("BOM_Structure"), BOM_Structure, "Title", "List")

 

Also, ensure that your multi value list parameter is set to text and that you have the parameter name exactly the same 'BOM_Structure' and that all of the list of values are exactly the same. It is case senstive.

 

Alternatively, post your part, you can strip out anything, just leave the form box that changes the list and the parameter with that one ilogic rule. Run it to check that you still get the error and you can upload it here or PM it.

 

Hope it helps.

 

Matt.

0 Likes
Message 11 of 18

donaldleigh
Advocate
Advocate

Hi Matt

 

Here is a sample.

 

One thing I didn't realize is that i'm getting another error when run on a part file at the end but not an assembly file. Again only when its an external rule.

 

You will also see that I have now added to the end of the rule code so that it shows on the form what the current BOM Structure is.

 

This is something that I was going to add once I have the rule running right but have now included it to show you how I am hoping it works.

 

Also the Form is set up as a global From but I have added a sample to the part and assembly locally.

 

Remember that the rule is set up as An external rule. I have added it to the Assembly so you can see it (BOM Input), Also in the Assembly file is the code to include the BOM Structure to the Parameters. (BOM Para) This one is working well.

 

Thanks heaps for helping with this.

0 Likes
Message 12 of 18

matt_jlt
Collaborator
Collaborator

Hi Donald, it took me ages of testing different methods out and I have come to the conclusion that iLogic cannot change the BOM structure of an assembly document. It works flawlessly in VBA and vb.net but iLogic throws an error everytime.

I tried a ton of different methods and each one worked in everything but iLogic in an assembly.

 

Sorry but there doesn't seem to be a solution for this one. I'll start a new post and see if someone knows a fix.

0 Likes
Message 13 of 18

MechMachineMan
Advisor
Advisor

I've tried the code as both an internal and external rule.

 

It works in both scenarios for me.

 

I fairly certain this means it's an issue with your computer's setup/.dll files/inventor install.

 

You can try things like using inventor reset utility, reinstalling inventor, or reinstalling/repairing the install for your windows framework.

 

 

Again:

As written, the code functions perfectly fine on my workstation with Inventor 2018.

 

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
Message 14 of 18

matt_jlt
Collaborator
Collaborator

Justin is correct, I tried it on a different machine and it works fine. We must have somehow had the same issue occurring on both of our machines. Weird. Sorry for the misleading info. 

 

Loos like i'm resetting the inventor install on my other machine.

 

Matt.

0 Likes
Message 15 of 18

donaldleigh
Advocate
Advocate

No worries Guys

 

Again big thanks for looking into this for me

 

Looks like i might have to try and work this with internal rules

 

One last thing!!!!!

 

I have seen an .exe file that can add an internal rule to existing files. but is there a way to do this via ilogic.

 

If I cant have this rule as an External rule I would love to be able to add the rule to my old projects via ilogic

 

Donald

0 Likes
Message 16 of 18

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @donaldleigh,

 

Try the suggestion provided in the following link.

 

https://inventorlogicblog.wordpress.com/2016/04/20/autodesk-inventor-ilogic-create-a-new-ilogic-rule...

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 17 of 18

NachoShaw
Advisor
Advisor
Hi

Could you write the bom structure function in vb.net as a dll then import that reference into ilogic?

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
Message 18 of 18

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @NachoShaw,

 

The following blog link might help to call vb.net dll in iLogic.

 

http://adndevblog.typepad.com/manufacturing/2013/06/use-vbnet-dialog-in-ilogic.html

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes