bug ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I wrote a little add-in to add a workpoint at the center of mass of the part or assembly. It functions perfectly on parts, but on assembly sometimes it fucntions sometimes not : I have an error : "Unspecified error : HRESULT : 0x80004005 (E_FAIL)" when creating the workpoint. Where is the bug ?
Sub
WorkPointAtMassCenter()
'Create a workpoint at the center of mass of the active document
' Set a reference to the active document.
Dim oDoc As Inventor.Document
oDoc = g_inventorApplication.ActiveDocument
Dim oCompDef AsComponentDefinition
oCompDef = oDoc.componentdefinition
' Get the Center of Mass.
Dim oCenterOfMass As Inventor.Point
oCenterOfMass = oCompDef.MassProperties.CenterOfMass
OnErrorResumeNext
Dim oWorkPoint As Inventor.WorkPoint
oWorkPoint = oCompDef.WorkPoints.item("Center Of Mass")
If Err.Number = 0 Then oWorkPoint.Delete() 'If the workpoint already exist, delete it
' Create a new workpoint at the location of the center of mass.
oWorkPoint = oCompDef.WorkPoints.AddFixed(oCenterOfMass) 'the error occurs on this line
' Rename the work point.
oWorkPoint.Name ="Center Of Mass"
' End If
OnErrorGoTo 0
EndSub