- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I try to use the code sample "Work point at mass center" as an addin in VB .net, but I have e problem with ComponentDefinition : I can't use ActiveDocument.ComponentDefinition. I think I missed something...
Sub
WorkPointAtMassCenter()
' Set a reference to the active document.
Dim oDoc AsDocument
oDoc = g_inventorApplication.ActiveDocument ' g_inventorApplication is a global inventor.application
Try
Dim oCompDef AsComponentDefinition
oCompDef = oDoc.componentdefinition ' <<<<---- The problem is here !!
' Get the Center of Mass.
Dim oCenterOfMass AsPoint
oCenterOfMass = oCompDef.MassProperties.CenterOfMass
' Check to see if a work point for center of mass already exists.
' This uses the name of the work feature to identify it.
Dim oWorkPoint AsWorkPoint
oWorkPoint = oCompDef.WorkPoints.Item(
"Center Of Mass")
If Err.Number = 0 Then
Dim oFixedDef AsFixedWorkPointDef
oFixedDef = oWorkPoint.Definition
oFixedDef.Point = oCenterOfMass
oDoc.Update()
Else
' Create a new workpoint at the location of the center of mass.
oWorkPoint = oCompDef.WorkPoints.AddFixed(oCenterOfMass)
' Rename the work point.
oWorkPoint.Name =
"Center Of Mass"
EndIf
Catch
MsgBox(Err.Description)
EndTry
EndSub
Solved! Go to Solution.