Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Region properties in sketch confusion

5 REPLIES 5
Reply
Message 1 of 6
pball
2270 Views, 5 Replies

Region properties in sketch confusion

I was trying to do calculations on an odd shape earlier and I noticed something odd about how the region properties in sketches works. Ix and Iy appear to be calculated at the centroid but at an angle to the sketch axes (whatever the principle axes is). Ixx and Iyy are calculated from the sketch origin following the sketch axes. However the centroid has to be on the sketch origin for those values to be correct.

For a tube or symmetrical part drawn around the origin none of that matters as Ix and Ixx would be the same, but for an odd shape Ixx depends on the centroids relation to the origin and Ix depends on what the principle axes is.

Is there a simple way to get Inventor to calculate Ix/Iy about the centroid without having to move the part so the centroid is on the origin? I would like if the Ix/Iy calculation was in relation to the sketch axes instead of the principle axes, since I can't see the reason you'd want Ix/Iy on the principle axes.

 

angle.PNG

5 REPLIES 5
Message 2 of 6
innovatenate
in reply to: pball

Could you apply the parallel axis theorem to quickly calculate your inertia tensors about an axis of your choosing?

 

There is no automated tool that I'm aware of. This would make a good IdeaStation request for a new feature. However, there are API commands for the Region Properties. You may be able to write an ilogic code that utilizes the API command that would automatically calculate those inertia tensors about the centroid.

 

For clarity, I will go through an example. The below image is the Region Properties when the section has been rotated and centered on the Principal Axis, the axis through which rotational symmetry is obtained. This screenshot is mostly for reference. Note that Ixx and Iyy have the same values as Ix and Iy.

 

Centered and Rotated to Principal Axis.PNG

 

 

Next I have rotated the section to align with the default work axis and origin, but I have centered the section on the Centroid. Note that the "Centroid, with respect to Sketch Origin" values are 0 for X and Y. Also, note that the Ixx/Iyy values no longer match Ix and Iy, since they are being calculated with respect to the Sketch Origin to which they have been aligned.

 

Centered on Centroid.PNG

 

 

 

Next, I will move the section 10 inches above the X axis. Since I know:

Ixx = 5.282 in^2

d = 10 in

Area = 2.089 in^2

 

Inewxx = Ixx + d^2 * A = 214.182 in^4

 

 

Offset for Calculation.PNG

 

Result is that the new Ixx value is 214.198 in^4. The difference (214.198 - 214.182 = .016 or .00746972 % Error ) is due to the difference in precision Inventor and I used to calculate the results.

 

To get a better idea of the API commands, you can Help drop down menu > Community Resources > Programming Help and search for RegionProperties Object. There is a sample for querying a sketch profile to get regions that should be a good start.

 

Let me know if this helps or if you have any questions.

 

Thanks,

 

 

 




Nathan Chandler
Principal Specialist
Message 3 of 6
pball
in reply to: innovatenate

Thanks for the reply. It reinforces everything I thought about this region properties.

I think I will take a look at the API stuff and use the parallel axis theorem to spit out the numbers I want.

I think I'll also make an idea station post. It'd be nice if you choose between the two methods it uses to calculate the moment of inertia by and a third option to calculate the moment of inertia about the centroid which it doesn't do. The first time I used this tool it was on a square tube so Ixx and Ix were the same, so when I used it on an angle and they were different I was confused and had to figure what the difference was. Not to mention my hand calculation was different from Ixx because the angle didn't have it's centroid on the sketch origin.
Message 4 of 6
innovatenate
in reply to: pball

I took a crack at some code that should get you started. This ilogic code will apply the parallel axis theorem about the centroid automatically for you. I must warn you that I haven't tested this code extensively, but it seems to work for the simple example that I demonstrated earlier. 

 

Please review and let me know if you have any questions. Hope this helps. Thanks!

 

 

 

	'Check that sketch is active
	If TypeOf ThisApplication.ActiveEditObject Is Sketch Then
		'Do Nothing
    Else
		MessageBox.Show("A sketch must be active with a closed profile.", "WARNING")
		Return
    End If

    ' a reference to the active sketch.
    ' This assumes a 2D sketch is active.
    Dim oSketch As Sketch
    oSketch = ThisApplication.ActiveEditObject

    Dim oRegionProps As RegionProperties
	oRegionProps = oSketch.Profiles.AddForSolid.RegionProperties
	' the accuracy to Low
	oRegionProps.Accuracy = 69377	
    
	Dim Ixx, Iyy, Izz, Ixy, Iyz, Ixz As Double
    Call oRegionProps.MomentsOfInertia(Ixx, Iyy, Izz, Ixy, Iyz, Ixz)
	'Parallel Axis Theorem Applied About Centroid	
    Dim IxCon As Double
	IxCon=Ixx-oRegionProps.Area * oRegionProps.Centroid.Y^2
	Dim IyCon As Double
	IyCon=Iyy-oRegionProps.Area * oRegionProps.Centroid.X^2

	
	Dim oMessage As String
	Dim oConMessage
	oMessage= "Current Location Properties: " & vbCrLf & _
				"Area: " & oRegionProps.Area & vbCrLf & "Centroid (X,Y): " & _
                oRegionProps.Centroid.X & ", " & oRegionProps.Centroid.Y & vbCrLf & _
				" Ixx: " & Ixx & vbCrLf & " Iyy: " & Iyy & vbCrLf & _
				vbCrLf & "Parallel Axis Theorem" & vbCrLf & _
				"Applied About Centroid:" & vbCrLf & _
				" Ixx (centroid): " & IxCon & vbCrLf & " Iyy (centroid): " & IyCon
					
	Dim oUOM As UnitsOfMeasure ' 11272 is inch, 11268 is cm
	oUOM = ThisApplication.ActiveDocument.UnitsOfMeasure
	Dim oRegionPropsCon As RegionProperties
	Dim ConArea, ConCentroidX,ConCentroidY, ConIxx, ConIyy, ConIxCon, ConIyCon As Double
	ConCentroidX=oUOM.ConvertUnits(oRegionProps.Centroid.X, 11268,11272)
	ConCentroidY=oUOM.ConvertUnits(oRegionProps.Centroid.Y, 11268,11272)
	
	'Conversion factors
	Dim oConversionFactorArea As Double
	Dim oConversionFactorInertia As Double
	oConversionFactorArea=oUOM.ConvertUnits(1, 11268,11272)^2
	oConversionFactorInertia=oUOM.ConvertUnits(1, 11268,11272)^4

	ConArea=oRegionProps.Area*oConversionFactorArea	
	ConIxx=Ixx*oConversionFactorInertia
	ConIyy=Iyy*oConversionFactorInertia
	ConIxCon=IxCon*oConversionFactorInertia
	ConIyCon=IyCon*oConversionFactorInertia
	
	oConMessage= "Current Location Properties: " & vbCrLf & _
					"Area: " & ConArea & vbCrLf & "Centroid (X,Y): " & _
                    ConCentroidX & ", " & ConCentroidY & vbCrLf & _
					" Ixx: " & 	ConIxx & vbCrLf & _
					" Iyy: " & ConIyy & vbCrLf & vbCrLf & "Parallel Axis Theorem "& vbCrLf & _
					"Applied About Centroid:" & vbCrLf & " Ixx (centroid): " & _
					ConIxCon & vbCrLf & " Iyy (centroid): " & ConIyCon
	
'	oRegionPropsCon = oUOM.ConvertUnits(oRegionProps, 11268,11272)
'	Dim oMessageCon As String
'	oMessageCon="Area: " & oRegionPropsCon.Area & vbCrLf & "Centroid: " & _
'                    oRegionPropsCon.Centroid.X & ", " & _
'					oRegionPropsCon.Centroid.Y & vbCrLf & " Ixx: " &_
'					Ixx & vbCrLf & " Iyy: " & Iyy & vbCrLf & " Ixy: " & Ixy
'	
	

	
	MessageBox.Show(oMessage, "Default (cm)")
	MessageBox.Show(oConMessage, "Default (in)")
	
 

 

 

 




Nathan Chandler
Principal Specialist
Message 5 of 6
DeerSpotter
in reply to: innovatenate

Regarding your piece of code.

 

can you get it to find current Centroid (as i think it already does) and automatically move the whole sketch to X=0 & Y=0?

 

That would be super awesome!

 

Please let me know if that is possible?

 

I saw this piece of code that places stuff at origin:

 

Public Sub AlignOccurrencesWithConstraints() 
    Dim assemblydoc As AssemblyDocument 
    Set assemblydoc = ThisApplication.ActiveDocument 

    ' Get the occurrences in the select set. 
    Dim occurrenceList As New Collection 
    Dim entity As Object 
    For Each entity In assemblydoc.SelectSet 
        If TypeOf entity Is ComponentOccurrence Then 
            occurrenceList.Add entity 
        End If 
    Next 

    If occurrenceList.Count < 2 Then 
        MsgBox "At least two occurrences must be selected." 
        Exit Sub 
    End If 

    ' This assumes the first selected occurrence is the "base" 
    ' and will constrain the base workplanes of all the other parts 
    ' to the base workplanes of the first part. If there are 
    ' constraints on the other they end up being over constrained.

    ' Get the planes from the base part and create proxies for them. 
    Dim baseOccurrence As ComponentOccurrence 
    Set baseOccurrence = occurrenceList.Item(1) 

    Dim BaseXY As WorkPlane 
    Dim BaseYZ As WorkPlane 
    Dim BaseXZ As WorkPlane 
    Call GetPlanes(baseOccurrence, BaseXY, BaseYZ, BaseXZ) 

    Dim constraints As AssemblyConstraints 
    Set constraints = assemblydoc.ComponentDefinition.constraints 

    ' Iterate through the other occurrences 
    Dim i As Integer 
    For i = 2 To occurrenceList.Count 
        Dim thisOcc As ComponentOccurrence 
        Set thisOcc = occurrenceList.Item(i) 

        ' Move it to the base occurrence so that if the base is 
        ' not fully constrained it shouldn't move when the flush 
        ' constraints are added. 
        thisOcc.Transformation = baseOccurrence.Transformation 

        ' Get the planes from the occurrence 
        Dim occPlaneXY As WorkPlane 
        Dim occPlaneYZ As WorkPlane 
        Dim occPlaneXZ As WorkPlane 
        Call GetPlanes(thisOcc, occPlaneXY, occPlaneYZ, occPlaneXZ) 

        ' Add the flush constraints. 
        Call constraints.AddFlushConstraint(BaseXY, occPlaneXY, 0) 
        Call constraints.AddFlushConstraint(BaseYZ, occPlaneYZ, 0) 
        Call constraints.AddFlushConstraint(BaseXZ, occPlaneXZ, 0) 
    Next 
End Sub 

' Utility function used by the AlignOccurrencesWithConstraints macro.
' Given an occurrence it returns the base work planes that are in 
' the part or assembly the occurrence references.  It gets the 
' proxies for the planes since it needs the work planes in the 
' context of the assembly and not in the part or assembly document 
' where they actually exist. 
Private Sub GetPlanes(ByVal Occurrence As ComponentOccurrence, _  
                      ByRef BaseXY As WorkPlane, _  
                      ByRef BaseYZ As WorkPlane, _  
                      ByRef BaseXZ As WorkPlane) 
    ' Get the work planes from the definition of the occurrence. 
    ' These will be in the context of the part or subassembly, not  
    ' the top-level assembly, which is what we need to return. 
    Set BaseXY = Occurrence.Definition.WorkPlanes.Item(3) 
    Set BaseYZ = Occurrence.Definition.WorkPlanes.Item(1) 
    Set BaseXZ = Occurrence.Definition.WorkPlanes.Item(2) 

    ' Create proxies for these planes.  This will act as the work 
    ' plane in the context of the top-level assembly. 
    Call Occurrence.CreateGeometryProxy(BaseXY, BaseXY) 
    Call Occurrence.CreateGeometryProxy(BaseYZ, BaseYZ) 
    Call Occurrence.CreateGeometryProxy(BaseXZ, BaseXZ) 
End Sub

 

Image and video hosting by TinyPic
..........................................................................................................................
Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
..........................................................................................................................


See My LinkedIn Profile
Message 6 of 6
innovatenate
in reply to: DeerSpotter

This one is not as straight forward as the last request.

 

Fully constrainted or projected sketch geometry can be difficult to deal with. One rule may not best fit every situation. For example, in the Sketch Tab of Application Options, the  "Auto-project sketch origin on sketch creation" creates a sketch point that cannot be moved with the below MoveSketchObjects function. How should that project sketch point be treated?

 

Rather than deal with that, I kept it simple. In the below example, I only include sketch geometry that is underconstrained. In general, it is not a good idea to have underconstrained sketches. However, once the sketch is moved, you may be able to add fixed constaints or dimension to fully constrain the sketch.

 

Please note that I only tested this in the attached file. There are many more scenarios that this would need to be tested in.

 

'Check that sketch is active


If TypeOf ThisApplication.ActiveEditObject Is Sketch Then 'Do NothingElse MessageBox.Show("A sketch must be active with a singular closed profile.", "WARNING") Return End If ' Requires reference to the active sketch with single profile to obtain Region PropertiesDim oSketch As Sketch oSketch = ThisApplication.ActiveEditObject Dim oRegionProps As RegionProperties oRegionProps = oSketch.Profiles.AddForSolid.RegionProperties oRegionProps.Accuracy = 69377 ' the accuracy to Low 'Create Vector to moveDim oVec As Vector2d oVec = ThisApplication.TransientGeometry.CreateVector2d(-oRegionProps.Centroid.X, -oRegionProps.Centroid.Y) 'Create a collection of all underconstrained Entities in the sketch '***Note 'kFullyConstrainedConstraintStatus 51713 Object Is fully constrained. 'kOverConstrainedConstraintStatus 51715 Object Is over-constrained. 'kUnderConstrainedConstraintStatus 51714 Object Is under-constrained. 'kUnknownConstraintStatus 51716 Constraint status Is unknown. Dim oSketchObjects As ObjectCollection oSketchObjects = ThisApplication.TransientObjects.CreateObjectCollection Dim oSketchEntity As SketchEntity For Each oSketchEntity In oSketch.SketchEntities If oSketchEntity.ConstraintStatus() = 51714 oSketchObjects.Add(oSketchEntity) Else End If Next ' Move all sketch object in collectionoSketch.MoveSketchObjects(oSketchObjects, oVec, False, True) oSketch.Solve




Nathan Chandler
Principal Specialist

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report