Message 1 of 6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Unfortunately, I know enough iLogic to have gotten myself stuck in the weeds... I have this piece of code (copied from a larger code). My issue is in the Private Function CutL_iProp. What I'd like it to do is, if FindParameter_FL returns something (in other words, if User Parameter "FL" exists) then proceed with creating iProperty "Cut Length"=Parameter("FL").
How do I access either ParamFL or function FindParameter_FL from within Public function CutL_iProp? Or why do I get the errors? And maybe there is a better way to create the new iProperty if Parameter("FL") exists...
Thank you for the help!
Sub Main() Dim oPart As PartDocument = ThisDoc.FactoryDocument Dim invdoc As Document = ThisDoc.FactoryDocument Dim oSubType As String = invdoc.SubType oUserParams = GetUserParams(invdoc) 'Function GetUserParams returns UserParameters Collection ParamFL = FindParameter_FL(invdoc, "FL") 'Function FindParameter_FL returns the looked for parameter: FL - "Final Length" If ParamFL Is Nothing Then ParamFL = oUserParams.AddByValue("FL", 0, UnitsTypeEnum.kInchLengthUnits) Else 'It already exists with its own value End If Dim CL As String = CutL_iProp(oPart) Logger.Info(CL) End Sub 'Get user parameters collection *************************************************************************************************** Public Function GetUserParams(invdoc As Inventor.Document) As UserParameters Dim cd As ComponentDefinition = Nothing Select Case invdoc.DocumentType Case Is = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Dim docAssembly As Inventor.AssemblyDocument = invdoc cd = docAssembly.ComponentDefinition Case Is = Inventor.DocumentTypeEnum.kPartDocumentObject Dim docPart As Inventor.PartDocument = invdoc cd = docPart.ComponentDefinition End Select If cd IsNot Nothing Then Dim oParams As Parameters oParams = cd.Parameters Dim oUserParams As UserParameters oUserParams = oParams.UserParameters Return oUserParams End If Return Nothing End Function 'See if parameter "FL" exists ***************************************************************************************************** Function FindParameter_FL(invdoc As Inventor.Document, strParameter As String) As Inventor.Parameter Dim oParams As Parameters If invdoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Or _ invdoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then If invdoc.ComponentDefinition.IsModelStateMember Then invdoc = invdoc.ComponentDefinition.FactoryDocument End If oParams = invdoc.ComponentDefinition.Parameters Else Return Nothing End If For Each oParam As Inventor.Parameter In oParams If oParam.Name = strParameter Then Return oParam End If Next Return Nothing End Function 'Define / Create iProperty: "CUT LENGTH" ****************************************************************************************** Private Function CutL_iProp(part As PartDocument) As String If FindParameter_FL Is Nothing Then 'Do nothing Else Dim oCL As Double = Parameter("FL") Dim PropertyName As String = "CUT LENGTH" Dim PropertyValue As String = RoundToFraction(oCL, 1 / 16, RoundingMethod.Round) & " in" Dim oCProps As PropertySet = part.PropertySets.Item("Inventor User Defined Properties") Dim oCLProp As Inventor.Property Dim oExists As Boolean = False For Each oCProp As Inventor.Property In oCProps If oCProp.Name = PropertyName Then oCLProp = oCProp oCProp.Value=PropertyValue oExists = True End If Next If oExists = False Then oCLProp = oCProps.Add(PropertyValue, PropertyName) End If End If End Function
Solved! Go to Solution.