Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Workpoint vs point vs array of doubles vs vectors, how can I multiply a point by a scalar?

nbonnett-murphy
Advocate

Workpoint vs point vs array of doubles vs vectors, how can I multiply a point by a scalar?

nbonnett-murphy
Advocate
Advocate

Hello,

I'm trying to place a point to locate the center of gravity, both in assemblies and in parts.

 

I'm using

oCenterOfMass = iProperties.CenterOfGravity

to get the cog, which seems to come in document units (in). 

 

When I go to place a work point though, it seems that it's using database units instead, so the point is in the wrong location:

oWorkpoint = partDoc.ComponentDefinition.WorkPoints.addFixed(oCenterOfMass)

 

The different types are giving me a lot of trouble. It seems like workpoint.Point, and iproperties.CenterOfGravity should have compatible units. It also seems like I should be able to just go "workpoint.point * 2.54" and have all 3 elements of the coordinate set multiplied by the scalar. Or at the very least go workpoint.point.x = workpoint.point.x * 2.54. But none of those seem to work for me. I've also tried pulling each individual coordinate out, converting to various types, trying to multiply, then trying to put them back into a point type variable, but I can't seem to get that to work either. I haven't tried applying a matrix transformation to it yet, because it seemed like there should be a more straightforward way. 

 

I also tried to figure out how to use workpoint.point.getpointdata(), but it requires a double as input and I clearly don't know VBA well enough to see how this would be used. I tried temp = workpoint.point.getpointdata(), hoping to get a 3 element vector inside temp. Then I tried workpoint.point.getpointdata(temp) hoping for the same thing. No luck.

 

Can anyone please help explain:

What is the "normal" way to multiply a point by a scalar?

How does getpointdata() work?

What would be the normal way to break a (work)point down into an array/vector, then individual components, manipulate them arbitrarily, then build them back into an array/vector, then back into a point, and then place a workpoint or move an existing one onto those coordinates?

0 Likes
Reply
Accepted solutions (2)
375 Views
3 Replies
Replies (3)

Michael.Navara
Advisor
Advisor
Accepted solution

It is much easier to obtain COG from API then from iLogic shortcut (iProperties.CenterOfGravity).

Sample requires part or assembly as actual document (intellisense not working)

 

Dim compDef As ComponentDefinition = ThisDoc.Document.ComponentDefinition
Dim massProperties As MassProperties = compDef.MassProperties

Dim centerOfMass As Point = massProperties.CenterOfMass
compDef.WorkPoints.AddFixed(centerOfMass)

 

 

Sample for part with working intellisense (correct types)

Dim part As PartDocument = ThisDoc.Document
Dim massProperties As MassProperties = part.ComponentDefinition.MassProperties

Dim centerOfMass As Point = massProperties.CenterOfMass
part.ComponentDefinition.WorkPoints.AddFixed(centerOfMass)

 

 

 

nbonnett-murphy
Advocate
Advocate

That's very helpful thanks. Much easier to leave everything in database units then convert for display than to mess with whatever I was getting from iProperties.CenterOfGravity

0 Likes

Frederick_Law
Mentor
Mentor
Accepted solution

VBA Macro to add COG point and 3 Planes:

Private Sub COGUpdate()
  Dim oWorkPoint As WorkPoint
  Dim oWorkPlane As Workplane
  Dim vX, vY, vZ As UnitVector
  Dim oFixedDef As FixedWorkPointDef
  Dim oAssPtDef As AssemblyWorkPointDef
  Dim COGXY, COGXZ, COGYZ As Boolean
  
  Dim oDoc As Inventor.Document
  Set oDoc = ThisApplication.ActiveDocument
  
  Dim oCenterOfMass As point
  Set oCenterOfMass = oDoc.ComponentDefinition.MassProperties.CenterOfMass
  
  Dim PointExist As Boolean
  PointExist = False

  For Each oWorkPoint In oDoc.ComponentDefinition.WorkPoints
    If oWorkPoint.Name = "COG" Then
      PointExist = True
      If oDoc.DocumentType = kAssemblyDocumentObject Then
        Set oAssPtDef = oWorkPoint.Definition
        oAssPtDef.point = oCenterOfMass
      ElseIf oDoc.DocumentType = kPartDocumentObject Then
        Set oFixedDef = oWorkPoint.Definition
        oFixedDef.point = oCenterOfMass
      End If
      oDoc.Update
      Exit For
    End If
  Next
  
  If Not PointExist Then
    Set oWorkPoint = oDoc.ComponentDefinition.WorkPoints.AddFixed(oCenterOfMass)
    oWorkPoint.Name = "COG"
  End If
  
  For Each oWorkPlane In oDoc.ComponentDefinition.WorkPlanes
    Select Case oWorkPlane.Name
      Case "COG XY"
        COGXY = True
      Case "COG XZ"
        COGXZ = True
      Case "COG YZ"
        COGYZ = True
    End Select
  Next
  
  Set vX = ThisApplication.TransientGeometry.CreateUnitVector(1, 0, 0)
  Set vY = ThisApplication.TransientGeometry.CreateUnitVector(0, 1, 0)
  Set vZ = ThisApplication.TransientGeometry.CreateUnitVector(0, 0, 1)

  If COGXY Then
    oWorkPlane = oDoc.ComponentDefinition.WorkPlanes.SetFixed(oWorkPoint.point, vX, vY)
  Else
    Set oWorkPlane = oDoc.ComponentDefinition.WorkPlanes.AddFixed(oWorkPoint.point, vX, vY)
  End If
  
  oWorkPlane.Name = "COG XY"
  
  Set oWorkPlane = oDoc.ComponentDefinition.WorkPlanes.AddFixed(oWorkPoint.point, vX, vZ)
  oWorkPlane.Name = "COG XZ"
  
  Set oWorkPlane = oDoc.ComponentDefinition.WorkPlanes.AddFixed(oWorkPoint.point, vY, vZ)
  oWorkPlane.Name = "COG YZ"
End Sub