Message 1 of 6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
When a positional representation is activated, the assembly gets dirty.
But why?
Is it a bug in Inventor 2020.3?
You can use this VBA-code to reproduce the unexpected behaviour:
Public Sub DemonstrateUnexpectedBehaviour()
MsgBox "This function will demonstrate the unexpected behaviour of positional representations dirting asemblies." + vbCrLf + vbCrLf + "ATTENTION: all opened files will be closed now!!!"
' Define paths
Dim pTemp As String
Dim fPart As String
Dim fAssembly As String
pTemp = Environ("TEMP")
fPart = pTemp + "\part.ipt"
fAssembly = pTemp + "\assembly.iam"
' Close all opened documents
ThisApplication.Documents.CloseAll (False)
' Remember the original application setting and ensure that prompt for recomputable changes is enabled
Dim originalSetting As Boolean
originalSetting = ThisApplication.SaveOptions.PromptSaveForRecomputableChanges
ThisApplication.SaveOptions.PromptSaveForRecomputableChanges = True
' Create a new part document, using the default part template.
Dim oPartDoc As PartDocument
Set oPartDoc = ThisApplication.Documents.Add(kPartDocumentObject, _
ThisApplication.FileManager.GetTemplateFile(kPartDocumentObject))
' Set a reference to the component definition.
Dim oCompDef As PartComponentDefinition
Set oCompDef = oPartDoc.ComponentDefinition
' Create a new sketch on the X-Y work plane. Since it's being created on
' one of the base workplanes we know the orientation it will be created in
' and don't need to worry about controlling it. Because of this we also
' know the origin of the sketch plane will be at (0,0,0) in model space.
Dim oSketch As PlanarSketch
Set oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes(3))
' Edit the sketch
oSketch.Edit
' Set a reference to the transient geometry object.
Dim oTransGeom As TransientGeometry
Set oTransGeom = ThisApplication.TransientGeometry
' Project the origin point onto the sketch
Dim oOriginSketchPoint As SketchPoint
Set oOriginSketchPoint = oSketch.AddByProjectingEntity(oCompDef.WorkPoints.Item(1))
' Create new point for the rectangle
Dim oRectangleSketchPoint As SketchPoint
Set oRectangleSketchPoint = oSketch.SketchPoints.Add(oTransGeom.CreatePoint2d(4, 3), False)
' Draw a 4cm x 3cm rectangle with the corner at (0,0)
Dim oRectangleLines As SketchEntitiesEnumerator
Set oRectangleLines = oSketch.SketchLines.AddAsTwoPointRectangle( _
oOriginSketchPoint, _
oRectangleSketchPoint)
' Constraint the sketch
Dim oDim1 As OffsetDimConstraint
Set oDim1 = oSketch.DimensionConstraints.AddOffset(oSketch.SketchLines(1), oSketch.SketchLines(3), oTransGeom.CreatePoint2d(5, 2), False, False)
Dim oDim2 As OffsetDimConstraint
Set oDim2 = oSketch.DimensionConstraints.AddOffset(oSketch.SketchLines(2), oSketch.SketchLines(4), oTransGeom.CreatePoint2d(2, 2), False, False)
' Create a profile.
Dim oProfile As Profile
Set oProfile = oSketch.Profiles.AddForSolid
' Exit sketch
oSketch.ExitEdit
' Create a base extrusion 1cm thick.
Dim oExtrudeDef As ExtrudeDefinition
Set oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, kJoinOperation)
Call oExtrudeDef.SetDistanceExtent(1, kNegativeExtentDirection)
Dim oExtrude As ExtrudeFeature
Set oExtrude = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef)
' Save the part file
Call oPartDoc.SaveAs(fPart, False)
' Create a new assembly document, using the default template.
Dim oAssemblyDoc As AssemblyDocument
Set oAssemblyDoc = ThisApplication.Documents.Add(kAssemblyDocumentObject, _
ThisApplication.FileManager.GetTemplateFile(kAssemblyDocumentObject))
' Set a reference to the component definition.
Dim oACompDef As AssemblyComponentDefinition
Set oACompDef = oAssemblyDoc.ComponentDefinition
Set oMatrix1 = oTransGeom.CreateMatrix
Set oMatrix2 = oTransGeom.CreateMatrix
Call oMatrix2.Translation.AddVector(oTransGeom.CreateVector(0, 0, 15))
' Add the part to the assembly origin
Dim oPart1 As ComponentOccurrence
Set oPart1 = oACompDef.Occurrences.AddByComponentDefinition(oCompDef, oMatrix1)
' Ground the part occurrence 1
oPart1.Grounded = True
' Add the part again to the assembly
Dim oPart2 As ComponentOccurrence
Set oPart2 = oACompDef.Occurrences.AddByComponentDefinition(oCompDef, oMatrix2)
' Constraint the part occurrence 2
Dim oConstraints As AssemblyConstraints
Set oConstraints = oACompDef.constraints
Dim oPartPlaneProxy As WorkPlaneProxy
Call oPart2.CreateGeometryProxy(oPart2.Definition.WorkPlanes.Item(1), oPartPlaneProxy)
Dim oConstraint1 As FlushConstraint
Set oConstraint1 = oConstraints.AddFlushConstraint(oPartPlaneProxy, oACompDef.WorkPlanes.Item(1), 0)
Call oPart2.CreateGeometryProxy(oPart2.Definition.WorkPlanes.Item(2), oPartPlaneProxy)
Dim oConstraint2 As FlushConstraint
Set oConstraint2 = oConstraints.AddFlushConstraint(oPartPlaneProxy, oACompDef.WorkPlanes.Item(2), 0)
Call oPart2.CreateGeometryProxy(oPart2.Definition.WorkPlanes.Item(3), oPartPlaneProxy)
Dim oConstraint3 As FlushConstraint
Set oConstraint3 = oConstraints.AddFlushConstraint(oPartPlaneProxy, oACompDef.WorkPlanes.Item(3), 5)
' Create a positional representation
Dim oPos As PositionalRepresentation
Set oPos = oACompDef.RepresentationsManager.PositionalRepresentations.Add("Demo")
' Activate the new positional representation
oPos.Activate
' Override the 3rd constraint
Call oPos.SetConstraintValueOverride(oConstraint3, 10)
' Activate the master positional representation
oACompDef.RepresentationsManager.PositionalRepresentations.Item(1).Activate
' Save the assembly
Call oAssemblyDoc.SaveAs(fAssembly, False)
' Inform the user that the assembly is not dirty at the moment
MsgBox "Assembly and part are now saved and fully ok." + vbCrLf + vbCrLf + "Assembly is dirty: " + CStr(oAssemblyDoc.Dirty)
' Activate the new positional representation
MsgBox "Step 1/2" + vbCrLf + vbCrLf + "Activating Demo positional representation"
oPos.Activate
' Activate the master positional representation
MsgBox "Step 2/2" + vbCrLf + vbCrLf + "Activating Master positional representation"
oACompDef.RepresentationsManager.PositionalRepresentations.Item(1).Activate
' Inform the user that the assembly is now dirty
MsgBox "As if by a miracle, the assembly is now dirty." + vbCrLf + "And the Dirty Bits property has the value 0X10 instead of the expected value 0X0." + vbCrLf + vbCrLf + "But WHY??????" + vbCrLf + vbCrLf + "Assembly is dirty: " + CStr(oAssemblyDoc.Dirty) + vbCrLf + "Inventor version is: " + ThisApplication.SoftwareVersion.DisplayName
' Restore the original application setting
ThisApplication.SaveOptions.PromptSaveForRecomputableChanges = originalSetting
End Sub
Solved! Go to Solution.