iLogic Rule Object reference not set to an instance of an object

iLogic Rule Object reference not set to an instance of an object

timothy_berg
Advocate Advocate
7,560 Views
10 Replies
Message 1 of 11

iLogic Rule Object reference not set to an instance of an object

timothy_berg
Advocate
Advocate

Hello, I am working on a rule that will rename the sheet name in the browser for easier exporting to DWG. The code below works on some drawings and some drawings it does not work, not sure what i have wrong. The error i get is "Object reference not set to an instance of an object." not sure what this means please help.

 

 

SyntaxEditor Code Snippet

Dim oSheets As Sheets = ThisDrawing.Document.sheets
Dim oSheet As Sheet


For Each oSheet In oSheets
    oSheet.activate
    Dim oDrawingView As DrawingView = oSheet.DrawingViews(1)
    oModel = ActiveSheet.View(oDrawingView.Name).ModelDocument
    EquipName = iProperties.Value(oModel.DisplayName, "Summary", "Comments")
    EquipName1=Left(EquipName,3)
    'MessageBox.Show(EquipName1)
    

    ActiveSheet.Sheet.Name = iProperties.Value("Custom", "EQUIP_CAT") &"-"& iProperties.Value("Custom", "DWG_EQUIP_NAME") & "-" & iProperties.Value("Custom", "DERIVATIVE") & "-" & EquipName1
Next

 

0 Likes
Accepted solutions (2)
7,561 Views
10 Replies
Replies (10)
Message 2 of 11

MechMachineMan
Advisor
Advisor
in the rule environment, you can do a manual debug by coding in the line

MsgBox("Here")

and starting at the top then moving it down to see where/what line your code fails at.

--------------------------------------
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 11

timothy_berg
Advocate
Advocate

did that and this is what popped up    Capture.PNG

 

also this is the text that is on the more info tab of the error message

System.NullReferenceException: Object reference not set to an instance of an object.
at iLogic.CadAssemblyUtil.FindComponentOccurrence(Document rootDoc, Object compoName, Boolean topLevelOnly, Boolean inTopLevelContext)
at iLogic.CadCompoOrDoc..ctor(Document rootDoc, Object oName)
at iLogic.CadPropertiesInRule.FindCompoOrDoc(Object compoOrDocName)
at iLogic.CadPropertiesInRule.InvPropertyInCompoOrDoc(Object compoOrDocName, String setName, String propName, Boolean createCustom)
at iLogic.CadPropertiesInRule.get_Value(Object compoOrDocName, String setName, String propName)
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

 

 

 

 

0 Likes
Message 4 of 11

MechMachineMan
Advisor
Advisor
But at what line? If you put it as the first line in the code does it run
and pop up the window?

--------------------------------------
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 5 of 11

timothy_berg
Advocate
Advocate
Accepted solution

SyntaxEditor Code Snippet

Dim oSheets As Sheets = ThisDrawing.Document.sheets
Dim oSheet As Sheet


For Each oSheet In oSheets
    oSheet.activate
    Dim oDrawingView As DrawingView = oSheet.DrawingViews(1)
    oModel = ActiveSheet.View(oDrawingView.Name).ModelDocument
    
    EquipName = iProperties.Value(oModel.DisplayName, "Summary", "Comments")
    MsgBox("Here")
    EquipName1=Left(EquipName,3)
    'MessageBox.Show(EquipName1)
    
    
    

    ActiveSheet.Sheet.Name = iProperties.Value("Custom", "EQUIP_CAT") &"-"& iProperties.Value("Custom", "DWG_EQUIP_NAME") & "-" & iProperties.Value("Custom", "DERIVATIVE") & "-" & EquipName1
Next

 

 

with the MsgBox in that location i get the error before the message

0 Likes
Message 6 of 11

MechMachineMan
Advisor
Advisor

So it's telling you it doesn't like the line that you access the iproperty on.

 

Other ways to write this line would be like:

 

 

EquipName = oModel.PropertySets("Inventor Summary Information")("Comments").Value

 

and to find out what is the proper descriptors, use:

http://modthemachine.typepad.com/my_weblog/2010/02/accessing-iproperties.html

 

 

Note: the above code is actually a shortened versions due to the default property of the calls being its Item. The shorthand says that you can replace the ".Item" (or other default property/method) with the brackets that outline the default property/method arguements.

 

The line, without the shorthand would be:

EquipName = oModel.PropertySets.Item("Inventor Summary Information").Item("Comments").Value

 


--------------------------------------
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 7 of 11

timothy_berg
Advocate
Advocate

that worked! thanks for the help

 

Do you have time for one more tweek? Is there a way to run the code on certain sheets only, for example 1-6 and ignore the remainder?

0 Likes
Message 8 of 11

MechMachineMan
Advisor
Advisor
Programmatically yes, just need to come up with a criteria to test on for
each sheet to tell it whether to run for that sheet or not

--------------------------------------
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 9 of 11

timothy_berg
Advocate
Advocate
Accepted solution

Got it to work with an If and Then statement thanks for the help

0 Likes
Message 10 of 11

Anonymous
Not applicable

Where did/would one place the ' If ' & ' Then ' words in the code? ? ? 

0 Likes
Message 11 of 11

bradeneuropeArthur
Mentor
Mentor

if sheet.item(1) then

 

end if

 

if sheet.item(2) then

 

end if

'till

if sheet.item(6) then

 

end if

 

I think!

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes