How to control the location of a Body in part file

How to control the location of a Body in part file

Anonymous
Not applicable
782 Views
3 Replies
Message 1 of 4

How to control the location of a Body in part file

Anonymous
Not applicable

I know how to create the Body I desire however but I can't figure out how to position the Body.  It comes in at 0,0,0.

Set oDerivedPartDefinition = oPartDocument.ComponentDefinition.ReferenceComponents.DerivedPartComponents. _
        CreateUniformScaleDef(sDerivedFile)
Set oDerivedPartComponent = oPartDocument.ComponentDefinition.ReferenceComponents. _
        DerivedPartComponents.Add(oDerivedPartDefinition)

The only way I can see of moving the Body is to use the "Move Bodies" command (a.k.a. "PartTransformCmd") but this command requires user interaction since it a dialog. CommandManager.PostPrivateEvent won't work here becuase there are multiple parameters and some parameters data types are not supported.

ThisApplication.CommandManager.ControlDefinitions.Item("PartTransformCmd").Execute

 

That said, how can I position the Body?

0 Likes
Accepted solutions (1)
783 Views
3 Replies
Replies (3)
Message 2 of 4

alewer
Advocate
Advocate
Accepted solution

The quick example below should be enough to get you started.  In the example, I derive a part that with an offset and rotation.

 

Public Sub DerivePositionOrientation()
  Dim oPartDoc As Inventor.PartDocument
  Set oPartDoc = ThisApplication.ActiveDocument
  
  Dim oCompDef As Inventor.PartComponentDefinition
  Set oCompDef = oPartDoc.ComponentDefinition
  
  'You need the full file name of the source part
  Dim sFile As String
  sFile = "***.ipt"
  
  Dim oCoordSys As DerivedPartCoordinateSystemDef
  Set oCoordSys = oPartDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.CreateCoordinateSystemDef(sFile)

  'Define position.  Here I offset by (1, 1, 1)
  Dim oPoint As Inventor.Point
  Set oPoint = ThisApplication.TransientGeometry.CreatePoint(1#, 1#, 1#)
  
  'Define X-axis orientation
  Dim oVectorX As Inventor.Vector
  Set oVectorX = ThisApplication.TransientGeometry.CreateVector(0#, 0#, 1#)
  
  'Define Y-axis orientation
  Dim oVectorY As Inventor.Vector
  Set oVectorY = ThisApplication.TransientGeometry.CreateVector(1#, 0#, 0#)
  
  Call oCoordSys.SetCoordinateSystem(oPoint, oVectorX, oVectorY)
  
  'Set scale in x, y, z
  Call oCoordSys.SetScale(1#, 1#, 1#)
  
  'Include only the first body
  oCoordSys.Solids.Item(1).IncludeEntity = True
  
  'Finally create the derived component
  Dim oDerivedComp As Inventor.DerivedPartComponent
  Set oDerivedComp = oCompDef.ReferenceComponents.DerivedPartComponents.Add(oCoordSys)
End Sub

 

I'm curious--can you tell me what you will be using this for?

Message 3 of 4

Anonymous
Not applicable

Thanks alewer, that works.  That will work great for initially bringing the COG Body in but I also need to be able to move the COG Body after model feature changes which affect the COG.  Do you have any thoughts on how I can accomplish this?  In the meanwhile I'll poke around myself.

 

I'm trying to develop a Center Of Gravity (COG) app for part files so we can dimension to the COG in a drawing.  We've been using a macro (off the internet) which works fine for assemblies but now I'd like to see if I can make it work for part files.  It dawned on me that perhaps I could import (in to a part model) the COG part file as separate Body so it can be moved to wherever the COG is (based on feature changes).  We have setup the COG.opt file so that it doesn't have volumme or mass so I'm hoping when it's derived in that its volumme and mass don't affect the physical properties calcs (I'll see very soon). 

 

The macro does have the the user enter the cooredinates for the COG that he/she obtains from iProperties > physical properties tab however I'd like to see the COG calculated by the macro instead of the user entereing it (future upgrade).  Perhaps I'll have my addin automatically move the COG after feature changes to the model so the user doesn't have to run the macro in order to relocate the COG when the model is modified. 

 !temp1.jpg

 

!temp2.jpg

0 Likes
Message 4 of 4

Anonymous
Not applicable

I just found out that what I'm trying to do is not necessary because Inventor since we think 2009 have the ablity to to bring in a tick mark (+) in a drawing view.  Dooooh!

 

This is done by right clicking on a drawing view in the Browser then selecting Center Of Gravity.

0 Likes