Error message: Object variable or With block variable not set

Error message: Object variable or With block variable not set

RoyWickrama_RWEI
Advisor Advisor
3,091 Views
7 Replies
Message 1 of 8

Error message: Object variable or With block variable not set

RoyWickrama_RWEI
Advisor
Advisor

When I run my rule in the drawing document, I get the above error message. Request help.

 

Message.pngInventor Professional 2019

Vault Professional 2019

0 Likes
Accepted solutions (1)
3,092 Views
7 Replies
Replies (7)
Message 2 of 8

bradeneuropeArthur
Mentor
Mentor

Could you upload the code by text?

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

JamieVJohnson2
Collaborator
Collaborator

His code is in the .idw file.

The code attempts to USE a property, then catches the error then creates the property.  The Catch then creates the property, but you then used the variable prop in the message box.  However you forgot to add "prop = "on the previous add line. (hi2 runs, hi2.1 runs, then error) .

Catch
	MsgBox("hi2")
		customPropertySet.Add("TEST", oCustiProperties_Array.Item(i))
			MsgBox("hi2.1")
		MessageBox.Show(prop.Name & ": ADDED" & vbLf & prop.Name & " (VALUE): " & prop.Value, "CUST PROP")
			MsgBox("hi2.2")
		oPrompt = "ASSIGN DATA"
			MsgBox("hi2.3")
	End Try
Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
Message 4 of 8

RoyWickrama_RWEI
Advisor
Advisor

 

Thanks for the reply. My badness: after struggling few hours, I rushed to post for help.

Files are attached here to and code is shown below;

Sub main()
oCust_Prop_Sub()
End Sub

Sub oCust_Prop_Sub()
'Define the open document
Dim openDoc As Document
openDoc = ThisDoc.Document

'Look at the model file referenced in the open document
Dim docFile As Document
If ThisDoc.ModelDocument IsNot Nothing Then
docFile = ThisDoc.ModelDocument
Else
MessageBox.Show("NOT OK, This drawing has no model reference", "iLogic")
Return
End If

'oModelDoc = IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName)
'format model file name                   
Dim FNamePos As Long
FNamePos = InStrRev(docFile.FullFileName, "\", -1)                        
Dim docFName As String 
docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos) 

'define the property set
customPropertySet = docFile.PropertySets.Item("Inventor User Defined Properties")

oName_Prop1 = "TOTAL QTY"
oName_Prop2 = "ROLLING_ALLOWANCE"

Dim oCustiProperties_Array As New ArrayList	
oCustiProperties_Array.Add(oName_Prop1)	
oCustiProperties_Array.Add(oName_Prop2)

For i = 0 To oCustiProperties_Array.Count-1
	'look for the custom propety and add it if not found 
	Try
		prop = customPropertySet.Item(oCustiProperties_Array.Item(i))
		MessageBox.Show(prop.Name & ": EXISTS" _
		& vbLf & prop.Name & " (VALUE): " & prop.Value, "CUST PROP")
		oPrompt = "EDIT/ASSIGN DATA"
	Catch
		customPropertySet.Add("TEST", oCustiProperties_Array.Item(i))
		MessageBox.Show(prop.Name & ": ADDED" _
		& vbLf & prop.Name & " (VALUE): " & prop.Value, "CUST PROP")
		oPrompt = "ASSIGN DATA"
	End Try
	prop.Value = InputBox(oPrompt, prop.Name, prop.Value)
Next i
iLogicVb.UpdateWhenDone = True
InventorVb.DocumentUpdate()
End Sub

Roy Wickrama

 

0 Likes
Message 5 of 8

bradeneuropeArthur
Mentor
Mentor
Accepted solution
Sub main()
oCust_Prop_Sub()
End Sub

Sub oCust_Prop_Sub()
'Define the open document
Dim openDoc As Document
openDoc = ThisDoc.Document

'Look at the model file referenced in the open document
Dim docFile As Document
If ThisDoc.ModelDocument IsNot Nothing Then
docFile = ThisDoc.ModelDocument
Else
MessageBox.Show("NOT OK, This drawing has no model reference", "iLogic")
Return
End If

'oModelDoc = IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName)
'format model file name                   
Dim FNamePos As Long
FNamePos = InStrRev(docFile.FullFileName, "\", -1)                        
Dim docFName As String 
docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos) 

'define the property set
customPropertySet = docFile.PropertySets.Item("Inventor User Defined Properties")

oName_Prop1 = "TOTAL QTY"
oName_Prop2 = "ROLLING_ALLOWANCE"

Dim oCustiProperties_Array As New ArrayList	
oCustiProperties_Array.Add(oName_Prop1)	
oCustiProperties_Array.Add(oName_Prop2)

For i = 0 To oCustiProperties_Array.Count-1
	'look for the custom propety and add it if not found 
	Try
		prop = customPropertySet.Item(oCustiProperties_Array.Item(i))
		MessageBox.Show(prop.Name & ": EXISTS" _
		& vbLf & prop.Name & " (VALUE): " & prop.Value, "CUST PROP")
		oPrompt = "EDIT/ASSIGN DATA"
	Catch
		customPropertySet.Add("TEST", oCustiProperties_Array.Item(i))
prop = customPropertySet.Item(oCustiProperties_Array.Item(i)) MessageBox.Show(prop.Name & ": ADDED" _ & vbLf & prop.Name & " (VALUE): " & prop.Value, "CUST PROP") oPrompt = "ASSIGN DATA" End Try prop.Value = InputBox(oPrompt, prop.Name, prop.Value) Next i iLogicVb.UpdateWhenDone = True InventorVb.DocumentUpdate() End Sub

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
Message 6 of 8

JamieVJohnson2
Collaborator
Collaborator

@bradeneuropeArthur, the .Add command returns the object.  So his modification works fine as a one liner, and doesn't require the second line to get the item.

 

prop = customPropertySet.Add("TEST", oCustiProperties_Array.Item(i))

 

 

Thanks,

 

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
Message 7 of 8

bradeneuropeArthur
Mentor
Mentor

That is correct!

Regards,

Autodesk Software: Inventor Professional 2018 | Vault Professional 2018 | Autocad Mechanical 2018
Programming Skills: Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
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 !

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

RoyWickrama_RWEI
Advisor
Advisor

Dear Bradedeurope;

Thanks a lot.

It runs too smooth.

I will build up the rest of my rule.Your code is a great help.

 

Roy Wickrama

0 Likes