Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Missing Reference Parameters

8 REPLIES 8
Reply
Message 1 of 9
Anonymous
1403 Views, 8 Replies

Missing Reference Parameters

I have created some DimensionConstraint objects with the driven set to true.  the dimensions are not showing up in the refence parameters collection both in the Inventor Parameters UI and watch window.  I need these dimensions to show up as reference parameters.  Do I have to add them to the reference table manually, am I missing something, or did I discover a bug?

 

  Dim sdcVert As DimensionConstraint = (ClearanceModelProfileSketch.DimensionConstraints.AddTwoPointDistance(spOrigin, spProfile(i), DimensionOrientationEnum.kHorizontalDim,
                      tg.CreatePoint2d(spDeckRight.Geometry.X / 2, spDeckRight.Geometry.Y - ((1 + i) * dDimensionOffset)), True))
                With sdcVert.Parameter
                    .Name = "ATR" & (i + 1)
                    .Visible = True
                    .Precision = Inventor.LinearPrecisionEnum.kSixteenthsFractionalLinearPrecision
                    .Units = Inventor.UnitsTypeEnum.kFootLengthUnits
                    .ExposedAsProperty = True
                    With .CustomPropertyFormat
                        .PropertyType = CustomPropertyTypeEnum.kTextPropertyType
                        .Units = Inventor.UnitsTypeEnum.kFootLengthUnits
                        .Precision = CustomPropertyPrecisionEnum.kSixteenthsFractionalLengthPrecision
                        '.ShowUnitsString = True
                    End With
                End With

The following check code returns 0 after the sketch creates 6 very visible driven dimensions.

 

 MsgBox(ClearanceModel.ComponentDefinition.Parameters.ReferenceParameters.Count)

After checking the open document, there are visible dimensions, they all have the appropriate names, and are all marked as driven, but the UI does not show them, not even a reference parameters section on the table.  Please help me figure this out.

 

 

Thanks,

8 REPLIES 8
Message 2 of 9
Anonymous
in reply to: Anonymous

The created driven dimension's parameter (reference) is not visible to iLogic either.  It is only visible to iProperties (custom).  This is causing me a problem, because I can't ask for the iProperty its value if it is not numeric, because the parameter exported it as formated text what I get back in "31 in" instead of 31.  As such I can not perform math on the stored value within iLogic, I would have to write elaborate code to get the value from the component reference, its cg and translate it to current space.

Message 3 of 9
Vladimir.Ananyev
in reply to: Anonymous

I don’t see any problem in your code snippet.

I made the simple VBA test to play with the reference parameters in a planar sketch.  It creates new planar sketch in the active part and adds one reference dimension.  Then it changes some properties in the associated parameter.  Here is the result:

RefDim.PNG

 

Sub AddReferenceDimension()
    'create new part document and run this vba code
    
    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument
    Dim oDef As PartComponentDefinition
    Set oDef = oDoc.ComponentDefinition
    Dim oTG As TransientGeometry
    Set oTG = ThisApplication.TransientGeometry
    
    'create 2D sketch on the X-Y plane
    Dim oSketch As PlanarSketch
    Set oSketch = oDef.Sketches.Add(oDef.WorkPlanes.Item(3))
    
    'draw 2d geometry
    Dim oSkPnts As SketchPoints
    Set oSkPnts = oSketch.SketchPoints
    Call oSkPnts.Add(oTG.CreatePoint2d(0, 0), False)
    Call oSkPnts.Add(oTG.CreatePoint2d(1#, 0), False)
    Call oSkPnts.Add(oTG.CreatePoint2d(1#, 0.5), False)
    Call oSkPnts.Add(oTG.CreatePoint2d(2.2, 0.5), False)
    Call oSkPnts.Add(oTG.CreatePoint2d(0.5, 1.5), False)
    Call oSkPnts.Add(oTG.CreatePoint2d(0, 1#), False)
    Call oSkPnts.Add(oTG.CreatePoint2d(2.7, 1.5), False)
    Call oSkPnts.Add(oTG.CreatePoint2d(0.5, 1#), False)
     
    Dim oLines As SketchLines
    Set oLines = oSketch.SketchLines
    Dim oLine(1 To 6) As SketchLine
    Set oLine(1) = oLines.AddByTwoPoints(oSkPnts(1), oSkPnts(2))
    Set oLine(2) = oLines.AddByTwoPoints(oSkPnts(2), oSkPnts(3))
    Set oLine(3) = oLines.AddByTwoPoints(oSkPnts(3), oSkPnts(4))
    Set oLine(4) = oLines.AddByTwoPoints(oSkPnts(4), oSkPnts(7))
    Set oLine(5) = oLines.AddByTwoPoints(oSkPnts(7), oSkPnts(5))
    Set oLine(6) = oLines.AddByTwoPoints(oSkPnts(6), oSkPnts(1))
    Dim oArc As SketchArc
    Dim oArcs As SketchArcs
    Set oArcs = oSketch.SketchArcs
    Set oArc = oArcs.AddByCenterStartEndPoint(oSkPnts(8), oSkPnts(5), oSkPnts(6))
    
    'add driven dimension
    Dim oDims As DimensionConstraints
    Set oDims = oSketch.DimensionConstraints
    
    Dim oPoint As Point2d
    Set oPoint = oTG.CreatePoint2d( _
        (oLine(1).StartSketchPoint.Geometry.x + oLine(1).EndSketchPoint.Geometry.x) / 2, _
         oLine(1).StartSketchPoint.Geometry.y - 1)
    
    Dim oDim As TwoPointDistanceDimConstraint
    Set oDim = oDims.AddTwoPointDistance( _
        oLine(1).StartSketchPoint, _
        oLine(1).EndSketchPoint, _
        DimensionOrientationEnum.kHorizontalDim, _
        oPoint, _
        True)
    
    'parameter properties
    With oDim.Parameter
        .name = "ATR" & (77)
        .Visible = True
        .Precision = Inventor.LinearPrecisionEnum.kSixteenthsFractionalLinearPrecision
        .units = Inventor.UnitsTypeEnum.kFootLengthUnits
        .ExposedAsProperty = True
        With .CustomPropertyFormat
            .PropertyType = CustomPropertyTypeEnum.kTextPropertyType
            .units = Inventor.UnitsTypeEnum.kFootLengthUnits
            .Precision = CustomPropertyPrecisionEnum.kSixteenthsFractionalLengthPrecision
        End With
    End With

End Sub

If you still have a problem please upload the model and the minimal buildable code that could help to reproduce the problem on our side.

thanks


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 4 of 9
Anonymous
in reply to: Vladimir.Ananyev

Strange... The only fundamental difference I have is my sketch in an assembly model sketch, but that shouldn't really matter. 

I am attempting two auto senarios that both have the same problem, dimension is created, but reference is not.

  • I'm adding a line and an origin center point, and constraining the centerpoint to the first point in the line vertically.
  • I'm adding 2 points into the sketch (one assembly origin, and one is a part's center of gravity), then i'm adding a constrained dimension between the two.

I can send you the full code, and it will run to that section.  The files are created by the code, and the only thing that is supplied is the template, and a psuedo railcar part file.

Message 5 of 9
Vladimir.Ananyev
in reply to: Anonymous

I also see strange behavior when create dimensions in the assembly context.

Let me some time to investigate it. 


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 6 of 9
Vladimir.Ananyev
in reply to: Anonymous

Hi Jamie,

It looks like you've uncovered some problems with the Sketch portion of the Assembly API.  My colleague from engineer team confirmed it. Unfortunately we do not see any workaround at the moment. Sorry for that. 

We have logged Change Request number TFS 121060 “Missing parameters when create dimensions in 2D sketch in assembly document” with our development team as this issue requires a modification to our software. Please make a note of this number for future reference. You are welcome to request an update on the status of this issue, or to provide us with additional information.

Thank you very much for this case and discussion!


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 7 of 9

FYI I am getting this same problem whenthe dimension created is normal, not reference - aka driven.  Its becomming a real buzz kill because accessing Inventor's parameters in this state, because when the sket ch containing these dimensions is deleted it causes the program to crash (fatally). 

 

If you delete the dimension, or sketch containing these autocreated dimensions that have incorrect parameter data, then access the parameters window, Inventor will crash.  If you search the parameters using code, Inventor will not find them, and crash.  If you save the file with the sketch deleted, then close it, then open it, then open the parameters window Inventor does not crash, it shows parameters (the ones that have formulas attempting to use the missing parameters) as unreferenced parameters, and allows you to delete the user parameters so that I can recreate the whole lot of them.

jvj
Message 8 of 9

Hi Jamie,
Thank for for the further test. I appended this behavior to that change request:
TFS 121060 for our engineer team to investigate.
Message 9 of 9

Well something changed between Inventor 2019 and 2020 (currently using version 2020.0.1), this problem as resurfaced.  Inventor is unstable after deleting assembly sketch dimensions that were created by code and deleted by hand.  A detailed process list is below:

1. Code creates dimensional constraints in an assembly sketch, and modifies parameter export features.

2. Code creates custom parameters that use the dimensional parameters in their expressions (for rounding tricks).

3. User saves file and forgets all about this having happily completed their task.

4. User revisits same file many moons later, and wants to modify by hand the assembly sketch.  During this time, they delete one or more of the dimensions being used in step 1 above.

5. User attempts to 'rebuild all' or runs same code command to 'update2', Inventor reads an incomplete parameter's table and crashes.

5a.  User runs custom code to delete custom parameters with expressions that used orphaned dimensional parameters.

5b.  User manually deletes custom parameters with expressions that used orphaned dimensional parameters.

5c.  User or code run an update command (or rebuild all command), Inventor crashes.

 

Alternate step 5: User saves and closes file, or code saves and closes file.  Then reopens it, Inventor reads the table data and populates in-memory data from the cleaned table, and does not crash upon update. 

 

I have sent in several crash updates on this.  Currently my Autodesk account can not access its 'View Support Cases' page as it once again redirects back to the home page.  

 

Current version of Code that attempts to clean custom parameters before recreating them:

 Public Sub ATRWideRound()
        Try
            GetInventorApplication()
            If invApp IsNot Nothing Then
                If invApp.ActiveDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
                    Dim invdoc As Inventor.Document = invApp.ActiveDocument
                    Dim trans As Transaction = invApp.TransactionManager.StartTransaction(invdoc, "ATRWide")
                    ATRWideRoundReset(invdoc, trans)
                    trans.End()
                End If
            End If
        Catch ex As Exception
            Dim eh As New ErrorHandler(ex)
            eh.HandleIt()
        End Try
    End Sub

    Public Function RemoveParameterAndIProperty(param As Parameter, dcs As List(Of DimensionConstraint), invDoc As Inventor.Document) As Boolean
        Dim booSuccess As Boolean = False
        Try
            Dim booFound As Boolean = False
            Dim strName As String = String.Empty
            If param.HealthStatus <> HealthStatusEnum.kDeletedHealth Then
                For Each dc As DimensionConstraint In dcs
                    If dc.Parameter.Name = param.Name Then
                        dc.Parameter.ExposedAsProperty = False
                        Dim iProp As [Property] = FindiProperty(Tools.UserDefinedPropertySetID, dc.Parameter.Name, invDoc)
                        If iProp IsNot Nothing Then iProp.Delete()
                        ' ExportParameterAsFeetInches(dc.Parameter)
                        booFound = True
                        Exit For
                    End If
                Next
                strName = param.Name
                param.Delete()
            Else
                'don't remove - its has already been deleted by Inventor during the processing of our current code thread, such as when a user parameter that kept this one around as a formula value was deleted first.
            End If
            'still check for iproperties that need to be removed after parameter was deleted.
            If booFound = False AndAlso String.IsNullOrWhiteSpace(strName) = False Then
                Dim iProp As [Property] = FindiProperty(Tools.UserDefinedPropertySetID, strName, invDoc)
                If iProp IsNot Nothing Then iProp.Delete()
            End If
            booSuccess = True
        Catch ex As Exception
            'Dim strname As String = String.Empty
            'Try
            '    If param IsNot Nothing Then
            '        If param.Name IsNot Nothing Then
            '            strname = param.Name
            '        End If
            '    End If
            '    'MsgBox("Can not delete parameter and iProperty: " & strname & vbCrLf & ex.InnerException.ToString)
            'Catch ex2 As Exception
            '    'MsgBox("Can not delete parameter and iProperty, Inventor has a catastrophic error on this parameter.  You will need to reload the file to clean.")
            'End Try
        End Try
        Return booSuccess
    End Function

    Public Sub ATRWideRoundReset(ByRef docAsm As Inventor.AssemblyDocument, Optional ByRef trans As Transaction = Nothing)
        'find "Clearance Profile" sketch
        Dim skClearanceProfile As PlanarSketch = Nothing
        For Each psk As PlanarSketch In docAsm.ComponentDefinition.Sketches
            If psk.Name = "Clearance Profile" Then
                skClearanceProfile = psk
                Exit For
            End If
        Next
        Dim dcATRs As New List(Of DimensionConstraint)
        Dim dcWides As New List(Of DimensionConstraint)
        Dim dcAllATRs As New List(Of DimensionConstraint)
        Dim dcAllWides As New List(Of DimensionConstraint)
        If skClearanceProfile IsNot Nothing Then
            For Each dc As Inventor.DimensionConstraint In skClearanceProfile.DimensionConstraints
                If dc.Parameter.Name.Contains("ATR") Then
                    dcAllATRs.Add(dc)
                    If Not dc.Parameter.Name = "ATRD" Then dcATRs.Add(dc)
                ElseIf dc.Parameter.Name.Contains("WIDE") Then
                    dcAllWides.Add(dc)
                    If Not dc.Parameter.Name = "WIDED" Then dcWides.Add(dc)
                End If
            Next
        Else
            MsgBox("Can not find sketch named 'Clearance Profile'")
        End If
        'look for existing atr-wide rounded parameters'clear them out
        Dim booReLoadFile As Boolean = False
        Dim exATRs As List(Of Parameter) = GetParameterValues(docAsm, "ATR", True)
        If exATRs.Count > 0 Then
            Dim exATRRs As New List(Of Parameter)
            For Each param As Parameter In exATRs
                If param.Name.Substring(param.Name.Length - 1, 1) = "R" Then exATRRs.Add(param)
            Next
            For Each param As Parameter In exATRRs
                exATRs.Remove(param)
            Next
            For Each param As Parameter In exATRRs
                If RemoveParameterAndIProperty(param, dcAllATRs, docAsm) = False Then
                    booReLoadFile = True
                End If
            Next
            For Each param As Parameter In exATRs
                If RemoveParameterAndIProperty(param, dcAllATRs, docAsm) = False Then
                    booReLoadFile = True
                End If
            Next
        End If
        Dim exWides As List(Of Parameter) = GetParameterValues(docAsm, "WIDE", True)
        If exWides.Count > 0 Then
            Dim exWideRs As New List(Of Parameter)
            For Each param As Parameter In exWides
                If param.Name.Substring(param.Name.Length - 1, 1) = "R" Then exWideRs.Add(param)
            Next
            For Each param As Parameter In exWideRs
                exWides.Remove(param)
            Next
            For Each param As Parameter In exWideRs
                If RemoveParameterAndIProperty(param, dcAllWides, docAsm) = False Then
                    booReLoadFile = True
                End If
            Next
            For Each param As Parameter In exWides
                If RemoveParameterAndIProperty(param, dcAllWides, docAsm) = False Then
                    booReLoadFile = True
                End If
            Next
        End If
        If booReLoadFile Then
            MsgBox("File has errors and needs to be reloaded.")
            Dim strFileName As String = docAsm.FullFileName
            docAsm.Save()
            docAsm.Close()
            docAsm = OpenInventorFile(New IO.FileInfo(strFileName))
        End If
        'once old parameters are cleared out, create new ones based soley on the existence of the parameters found from the dimensions
        Dim dcATRWIDES As New List(Of DimensionConstraint)
        dcATRWIDES.AddRange(dcATRs)
        dcATRWIDES.AddRange(dcWides)
        For Each dc As DimensionConstraint In dcATRWIDES
            dc.Parameter.ExposedAsProperty = False
            Dim iProp As [Property] = FindiProperty(Tools.UserDefinedPropertySetID, dc.Parameter.Name, docAsm)
            If iProp IsNot Nothing Then iProp.Delete()
            ExportParameterAsFeetInches(dc.Parameter)
            Dim paraRound As Inventor.Parameter = Nothing
            Dim paramName As String = dc.Parameter.Name
            If paramName.ToUpper.Contains("ATR") Or paramName.ToUpper.Contains("WIDE") Then
                'round(( ATR1 - 0.49 in ) / 1 in) * 1 in
                Dim sign As String = "+"
                Dim strExpression As String = "round(( " & paramName & " " & sign & " 0.49 in ) / 1 in) * 1 in"
                Dim dRemainderInches As Double = (CDbl(dc.Parameter.Value) * 2.54) Mod 1
                If 0.09 < dRemainderInches AndAlso dRemainderInches < 1 / 32 Then
                    strExpression = "round(( " & dc.Parameter.Name & " ) / 1 in) * 1 in"
                End If
                Dim strName As String = dc.Parameter.Name & "R"
                Try
                    Dim uParams As UserParameters = docAsm.ComponentDefinition.Parameters.UserParameters
                    paraRound = uParams.AddByExpression(strName, strExpression, Inventor.UnitsTypeEnum.kInchLengthUnits)
                Catch ex As Exception
                    Dim eh As New ErrorHandler(ex)
                    eh.HandleIt()
                End Try
            End If
            ExportParameterAsFeetInches(paraRound)
        Next
        If dcWides.Count > 0 Then
            Dim intRoundDown As Integer
            dcWides.Sort(Function(x, y) CInt(x.Parameter.Name.Replace("WIDE", "")).CompareTo(CInt(y.Parameter.Name.Replace("WIDE", ""))))
            For i As Integer = 0 To dcWides.Count - 1
                dcWides(i).Parameter.ExposedAsProperty = False
                Dim iProp As [Property] = FindiProperty(Tools.UserDefinedPropertySetID, dcWides(i).Parameter.Name, docAsm)
                If iProp IsNot Nothing Then iProp.Delete()
                ExportParameterAsFeetInches(dcWides(i).Parameter)
                'if next value is smaller than current value then this is the last integer we want to round down
                If i > 0 Then 'must always be 1 below the max count
                    Dim dblValue As Double = dcWides(i - 1).Parameter.Value
                    Dim dblValue2 As Double = dcWides(i).Parameter.Value
                    If Math.Round(dblValue, 8) < Math.Round(dblValue2, 8) Then
                        'get integer value from name
                        Dim strNumber As String = dcWides(i).Parameter.Name
                        strNumber = strNumber.ToUpper.Replace("WIDE", "")
                        intRoundDown = CInt(strNumber)
                        'Exit For
                    End If
                End If
            Next
            For i As Integer = 1 To intRoundDown - 1
                'get ATR rounded value by name = ATR1R
                Dim uParam As UserParameter = docAsm.ComponentDefinition.Parameters.UserParameters.Item("ATR" & i & "R")
                If uParam IsNot Nothing Then
                    uParam.Expression = "round(( " & "ATR" & i & " - 0.49 in ) / 1 in) * 1 in"
                    Dim dRemainderInches As Double = (CDbl(uParam.Value) * 2.54) Mod 1
                    If 0.09 < dRemainderInches AndAlso dRemainderInches < 1 / 32 Then
                        uParam.Expression = "round(( " & "ATR" & i & " ) / 1 in) * 1 in"
                    End If
                End If
            Next
        End If
        If docAsm.RequiresUpdate = True Then
            Dim strFileName As String = docAsm.FullFileName
            Dim transName As String = String.Empty
            Dim booRestartTransaction As Boolean = False
            If trans IsNot Nothing Then
                booRestartTransaction = True
                transName = trans.DisplayName
                trans.End()
            End If
            docAsm.Save()
            docAsm.Close()
            docAsm = OpenInventorFile(New IO.FileInfo(strFileName))
            docAsm.Update2(True)
            If booRestartTransaction Then
                trans = invApp.TransactionManager.StartTransaction(docAsm, "transName")
            End If
        End If
    End Sub

Example of code used to create dimension:

 'add vertical dimension constraint
            Dim sdcVert As DimensionConstraint = skProfile.DimensionConstraints.AddTwoPointDistance(slMirror.StartSketchPoint, OffsetProfile(i).StartProfilePoint.SketchPoint, DimensionOrientationEnum.kHorizontalDim,
                  tg.CreatePoint2d(OffsetProfile(0).StartProfilePoint.SketchPoint.Geometry.X / 2, OffsetProfile(0).StartProfilePoint.SketchPoint.Geometry.Y + ((1 + i) * dDimensionOffset)), False)
            With sdcVert.Parameter
                .Name = OffsetProfile(i).StartProfilePoint.PointID
                '.DisplayFormat = ParameterDisplayFormatEnum.kArchitecturalDisplayFormat
                .Visible = True
                .Precision = Inventor.LinearPrecisionEnum.kSixteenthsFractionalLinearPrecision
                .ExposedAsProperty = True
                ' MsgBox(.InUse)
                With .CustomPropertyFormat
                    .PropertyType = CustomPropertyTypeEnum.kTextPropertyType
                    .Units = Inventor.UnitsTypeEnum.kFootLengthUnits
                    .Precision = CustomPropertyPrecisionEnum.kSixteenthsFractionalLengthPrecision
                    '.ShowUnitsString = True
                End With
            End With
            sdcProfileVert.Add(sdcVert)
            'add horizontal dimension constraints
            Dim intOppositeID As Integer = ((OffsetProfile.Count - 1) / 2) + i
            Dim sdcHorz As DimensionConstraint = skProfile.DimensionConstraints.AddTwoPointDistance(OffsetProfile(i).StartProfilePoint.SketchPoint, OffsetProfile(intOppositeID).StartProfilePoint.SketchPoint, DimensionOrientationEnum.kVerticalDim,
                  tg.CreatePoint2d(lastPoint1.SketchPoint.Geometry.X + ((1 + i) * dDimensionOffset), 0), False)
            With sdcHorz.Parameter
                .Name = sdcVert.Parameter.Name.Replace("ATR", "WIDE")
                .Visible = True
                .Precision = Inventor.LinearPrecisionEnum.kSixteenthsFractionalLinearPrecision
                .ExposedAsProperty = True
                With .CustomPropertyFormat
                    .PropertyType = CustomPropertyTypeEnum.kTextPropertyType
                    .Units = Inventor.UnitsTypeEnum.kFootLengthUnits
                    .Precision = CustomPropertyPrecisionEnum.kSixteenthsFractionalLengthPrecision
                    '.ShowUnitsString = True
                End With
            End With
            sdcProfileHorz.Add(sdcHorz)

I would really like to have a stable Inventor on this issue.  I'm having to write a lot of workaround code (its not ideal to close and reopen the file in mid processing) just to keep the user working.

 

Thanks,

 

jvj

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

Post to forums  

Autodesk Design & Make Report