Occasional "Object Variable or With block Variable Not Set" Error on ext. iLogic

Occasional "Object Variable or With block Variable Not Set" Error on ext. iLogic

Maxim-CADman77
Advisor Advisor
4,993 Views
24 Replies
Message 1 of 25

Occasional "Object Variable or With block Variable Not Set" Error on ext. iLogic

Maxim-CADman77
Advisor
Advisor

We do have set of external iLogic rules running automatically on Open and Save Inventor Documents with IDC (Inventor Design Checker).

Some (AFAIK only two particular) IPT oriented rules sometimes produce error "Object Variable or With block Variable Not Set".

Here is a bit simplified code of one:

Try

Dim oCompdef As PartComponentDefinition
oCompdef = ThisDoc.Document.ComponentDefinition
Dim oSketch As Sketch

''' Initial argument values
msg = "There were no unused sketches found."
retval = 1

For each oSketch in oCompdef.Sketches	
	If oSketch.HealthStatus <> HealthStatusEnum.kBeyondStopNodeHealth And oSketch.Consumed = False	Then
		msg = "There is at least one unused sketch - " & oSketch.Name	
		retval = 0
Exit For
	End if
Next

RuleArguments.Arguments.Value("ReturnValue") = retval
RuleArguments.Arguments.Value("Description") = msg

Catch
End Try

Trace.WriteLine (retval & "; " & msg)

 

The Error occurs occasionally. I see no relation to particular IPTs. Sometimes it even happens on creating new IPT. Sometimes Inventor reboot helps.

How could I debug such occasional errors?

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Accepted solutions (1)
4,994 Views
24 Replies
Replies (24)
Message 21 of 25

DRoam
Mentor
Mentor

Ok, good to know. I'll post back here if it ever does cause the Member Not Found error.

 

Yeah, if I understand you correctly, that's what I would expect. I think (hope) the GetCompDef function should always return the proper ComponentDefinition type for the type of document being processed (for example, a Part should return a PartComponentDefinition object and an assembly should return an AssemblyComponentDefinition object), so only the ComponentDefinition properties and methods appropriate to the document type should be available. If I tried to do something like this:

 

Dim oPartDoc As PartDocument = ThisDoc.Document
Dim oCompDef = GetCompDef(oPartDoc)
Dim oConstraints = oCompDef.Constraints

... the third line would produce an error, because the PartComponentDefintion object has no Constraints property.

 

The "GetCompDef" function should hopefully return the same result as doing "Document.ComponentDefinition" would return in Inventor 2019.2+. The result could be a PartComponentDefinition, or it could be an AssemblyComponentDefinition, depending on which document type was passed in. It's up to the person writing the code to make sure that only methods and properties shared by both Part and Assembly ComponentDefinitions are used (or else add necessary provisions for handling type-specific operations).

 

Please correct me if I'm understanding anything incorrectly.

0 Likes
Message 22 of 25

MjDeck
Autodesk
Autodesk

That's right, your "GetCompDef" function will return the same result as "Document.ComponentDefinition" would return in Inventor 2019.2+.

Then ideally you could use a single piece of code to access properties (e.g. the Parameters property) that are in common to both PartComponentDefinition and AssemblyComponentDefinition. I don't have any evidence of that failing. But I'm reluctant to recommend it, just because the situation is similar to the one between PartDocument and AssemblyDocument. In that case, the ComponentDefinition property looks like it's in common, but it's not really. That's what caused problems before the 2019.2 fix.

I will do more investigation to find out if PartComponentDefinition and AssemblyComponentDefinition could ever throw a "member not found" error with members that they have in common.


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 23 of 25

drouthierXAHY9
Participant
Participant

Hi Mike!

 

I'm having this issue in Inventor 2017. 

The error will get thrown "randomly" and upon restart it will sometimes work.

I tried the solution provided  here by Xiaodong Liang and it doesn't alleviate the problem.

 

will the fix be implemented in "Inventor" 2017?

 

Below is a snippet of my code.

 

ElseIf oRefDoc.documenttype = 12291		'assemblyDocumemt
Dim oAssyCompDef As assemblyComponentDefinition = oRefDoc.componentdefinition
0 Likes
Message 24 of 25

DRoam
Mentor
Mentor

@drouthierXAHY9, if you're pre-2019 then you'll need to explicitly declare the document as an assembly document before trying to get its AssemblyComponentDefinition. Try this and see if it works better for you:

 

ElseIf oRefDoc.documenttype = 12291		'assemblyDocumemt
Dim oAssyDoc As AssemblyDocument = oRefDoc
Dim oAssyCompDef As assemblyComponentDefinition = oAssyDoc.componentdefinition
0 Likes
Message 25 of 25

drouthierXAHY9
Participant
Participant

Thanks DRoam!

 

I "overlooked" that part of Mike's response. hahaha Man-eyes!

0 Likes