VB .net : Workpoint at mass center

VB .net : Workpoint at mass center

TONELLAL
Collaborator Collaborator
792 Views
1 Reply
Message 1 of 2

VB .net : Workpoint at mass center

TONELLAL
Collaborator
Collaborator

 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

 

0 Likes
Accepted solutions (1)
793 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
Accepted solution

try 

Dim oDoc As Inventor.PartDocument -> instead of Dim oDoc as Document
0 Likes