iLogic - error when running code (Exception from HRESULT: 0x80004005 (E_FAIL))

iLogic - error when running code (Exception from HRESULT: 0x80004005 (E_FAIL))

mikko.m
Advocate Advocate
7,838 Views
7 Replies
Message 1 of 8

iLogic - error when running code (Exception from HRESULT: 0x80004005 (E_FAIL))

mikko.m
Advocate
Advocate

I get this error when i try to run my code:

 

System.Runtime.InteropServices.COMException (0x80004005): Määrittämätön virhe. (Exception from HRESULT: 0x80004005 (E_FAIL))
   at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   at Inventor.CustomPropertyFormat.set_ShowTrailingZeros(Boolean )
   at LmiRuleScript.Main()
   at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
   at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

It doesn't happen on all parts. I've attached part with this problem.

 

I found this but it didn't help.

https://www.cadlinecommunity.co.uk/hc/en-us/articles/201769272-Trouble-Shooting-Inventor-iLogic-Erro...

 

 

 

SyntaxEditor Code Snippet

'Set a reference to the active part document
    Dim oDoc As PartDocument
    oDoc = ThisApplication.ActiveDocument
    
    Dim oDef As PartComponentDefinition
    oDef = oDoc.ComponentDefinition
	
	oDoc.Update
	

Dim oparams As Parameters
    Dim oparam As Parameter
    oparams = oDoc.ComponentDefinition.Parameters
    Dim exists As Boolean
    exists = False


    'Find out if parameter exists, if not it will create this parameter in the table
    For Each oparam In oparams
    If oparam.Name = "MAX_Y" Then exists = True
	If oparam.Name = "MAX_Z" Then exists = True
	If oparam.Name = "MAX_X" Then exists = True

	Next

    'Change the value if the parameter exists otherwise add the parameter
	
	 If exists Then
		 oparams.Item("MAX_Y").Value = Measure.ExtentsWidth/10
        
    Else
         oparams.UserParameters.AddByValue("MAX_Y",  Measure.ExtentsWidth/10,  11266)
    End If
	
	
	
	 If exists Then
		 oparams.Item("MAX_X").Value = Measure.ExtentsLength/10
        
    Else
         oparams.UserParameters.AddByValue("MAX_X", Measure.ExtentsLength/10,  11266)
    End If
	
	
	
	 If exists Then
		 oparams.Item("MAX_Z").Value = Measure.ExtentsHeight/10
        
    Else
        oparams.UserParameters.AddByValue("MAX_Z", Measure.ExtentsHeight/10,  11266)
    End If
	


'Dim param As Parameter
'param = Parameter.Param("MAX_Y") 
Parameter.Param("MAX_Y").ExposedAsProperty = True 

Parameter.Param("MAX_Y").CustomPropertyFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision 
Parameter.Param("MAX_Y").CustomPropertyFormat.ShowTrailingZeros = True 
Parameter.Param("MAX_Y").CustomPropertyFormat.ShowLeadingZeros = False 
Parameter.Param("MAX_Y").CustomPropertyFormat.ShowUnitsString = False 
'Parameter.Param("MAX_Y").CustomPropertyFormat.Units = "mm" 

'param =Parameter.Param("MAX_Z") 
Parameter.Param("MAX_Z").ExposedAsProperty = True 

Parameter.Param("MAX_Z").CustomPropertyFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision  
Parameter.Param("MAX_Z").CustomPropertyFormat.ShowTrailingZeros = True 
Parameter.Param("MAX_Z").CustomPropertyFormat.ShowLeadingZeros = False 
Parameter.Param("MAX_Z").CustomPropertyFormat.ShowUnitsString = False 
'Parameter.Param("MAX_Z").CustomPropertyFormat.Units = "mm" 

'param =Parameter.Param("MAX_X") 
Parameter.Param("MAX_X").ExposedAsProperty = True 

Parameter.Param("MAX_X").CustomPropertyFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision   
Parameter.Param("MAX_X").CustomPropertyFormat.ShowTrailingZeros = True 
Parameter.Param("MAX_X").CustomPropertyFormat.ShowLeadingZeros = False 
Parameter.Param("MAX_X").CustomPropertyFormat.ShowUnitsString = False 
'Parameter.Param("MAX_X").CustomPropertyFormat.Units = "mm" 

	oDoc.Update

 

_____________________________________________________________________________________
Inventor Professional 2019.3
Vault Workgroup 2019.1.1
0 Likes
Accepted solutions (1)
7,839 Views
7 Replies
Replies (7)
Message 2 of 8

MechMachineMan
Advisor
Advisor

See if you get the proper results and no errors if you just exclude the ShowTrailingZeroes statements

 

Parameter.Param("MAX_Y").CustomPropertyFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision 
'Parameter.Param("MAX_Y").CustomPropertyFormat.ShowTrailingZeros = True 

I mean, aren't the 2 redundant - if you don't have a decimal (as set by your Zero Decimal precision), any trailing zeroes would just be adding to increasing the value by a factor of 10, instead of just acting as placeholders


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

bradeneuropeArthur
Mentor
Mentor

take a look at this similar code:

 

https://forums.autodesk.com/t5/inventor-customization/ilogic-to-set-max-dimensions-as-parameters-wit...

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

mikko.m
Advocate
Advocate

@MechMachineMan

 

Excluding the ShowTrailingZeroes didn't help. The code itself seems to be working and changing values. Error message appears after the code has run.

 

@bradeneuropeArthur

 

Same problem with that code. Code runs but the error occurs.

_____________________________________________________________________________________
Inventor Professional 2019.3
Vault Workgroup 2019.1.1
0 Likes
Message 5 of 8

t_hascj
Autodesk
Autodesk
Accepted solution

Hi mikko,

Try this code:

 

SyntaxEditor Code Snippet

'Set a reference to the active part document
Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument
    
Dim oDef As PartComponentDefinition
oDef = oDoc.ComponentDefinition
	
oDoc.Update
	

Dim oparams As Parameters
Dim oparam As Parameter
oparams = oDoc.ComponentDefinition.Parameters
Dim exists As Boolean
exists = False

'Find out if parameter exists, if not it will create this parameter in the table
For Each oparam In oparams
	If oparam.Name = "MAX_Y" Then exists = True
	If oparam.Name = "MAX_Z" Then exists = True
	If oparam.Name = "MAX_X" Then exists = True
Next

'Change the value if the parameter exists otherwise add the parameter	
If exists Then
	oparams.Item("MAX_Y").Value = Measure.ExtentsWidth
Else
	oparams.UserParameters.AddByValue("MAX_Y",  Measure.ExtentsWidth,  11266)
End If
	
If exists Then
	oparams.Item("MAX_X").Value = Measure.ExtentsLength        
Else
	oparams.UserParameters.AddByValue("MAX_X", Measure.ExtentsLength,  11266)
End If
	
If exists Then
	oparams.Item("MAX_Z").Value = Measure.ExtentsHeight        
Else
	oparams.UserParameters.AddByValue("MAX_Z", Measure.ExtentsHeight,  11266)
End If	


'Dim param As Parameter
'param = Parameter.Param("MAX_Y") 
Parameter.Param("MAX_Y").ExposedAsProperty = True
Parameter.Param("MAX_Y").CustomPropertyFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision
If (Parameter.Param("MAX_Y").CustomPropertyFormat.PropertyType <> Inventor.CustomPropertyTypeEnum.kNumberPropertyType)
	Parameter.Param("MAX_Y").CustomPropertyFormat.ShowTrailingZeros = True 
	Parameter.Param("MAX_Y").CustomPropertyFormat.ShowLeadingZeros = False 
	Parameter.Param("MAX_Y").CustomPropertyFormat.ShowUnitsString = False 
End If

'param =Parameter.Param("MAX_Z") 
Parameter.Param("MAX_Z").ExposedAsProperty = True
Parameter.Param("MAX_Z").CustomPropertyFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision  
If (Parameter.Param("MAX_Y").CustomPropertyFormat.PropertyType <> Inventor.CustomPropertyTypeEnum.kNumberPropertyType)
	Parameter.Param("MAX_Z").CustomPropertyFormat.ShowTrailingZeros = True
	Parameter.Param("MAX_Z").CustomPropertyFormat.ShowLeadingZeros = False 
	Parameter.Param("MAX_Z").CustomPropertyFormat.ShowUnitsString = False 
End If

'param =Parameter.Param("MAX_X") 
Parameter.Param("MAX_X").ExposedAsProperty = True
Parameter.Param("MAX_X").CustomPropertyFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision  
If (Parameter.Param("MAX_Y").CustomPropertyFormat.PropertyType <> Inventor.CustomPropertyTypeEnum.kNumberPropertyType)
	Parameter.Param("MAX_X").CustomPropertyFormat.ShowTrailingZeros = True
	Parameter.Param("MAX_X").CustomPropertyFormat.ShowLeadingZeros = False 
	Parameter.Param("MAX_X").CustomPropertyFormat.ShowUnitsString = False 
End If

oDoc.Update

 

Thanks,
Jaroslav

0 Likes
Message 6 of 8

mikko.m
Advocate
Advocate

Thank you! That works, no errors. I think I have to divide parameter value by 10 because otherwise parameter value shows 10 times higher.

 

Like this:

 

oparams.Item("MAX_Y").Value = Measure.ExtentsWidth/10
_____________________________________________________________________________________
Inventor Professional 2019.3
Vault Workgroup 2019.1.1
0 Likes
Message 7 of 8

MechMachineMan
Advisor
Advisor

@mikko.m that sounds like it's because of database units not being and measurements automatically being converted to the database lengths ("cm") instead of your working units ("mm").

 

Its definitely something to look up and be aware of if you are using params in iLogic!


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

t_hascj
Autodesk
Autodesk

Yes, you are right.

The nominal value is multiplied by 10, therefore Measure.ExtentXXX return value in mm. And AddByValue function get value in database units(cm) and then convert it to specified units(11266 = mm)

More info http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-DB91F7F6-842C-4849-A856-1003F8B7C576