Saturday, 20 September 2014

Multi-Line iProperties


A colleague asked me the other day if we can have multi-line iProperties. As far as I know there is only one multi-line iPropertie which is "Comments" on the "Summary" tab. I have been using Comments to add long texts like specs and description of an electric motor, or adding revision notes.
He wanted to control the text on the "Project" and force the line return for better visibility in the title block.



The quick solution I've provided was to enter his project text in the comments box where he could control each line with enter and then put a formula in the project box calling the comments like this: =<Comments>.





But then it got me thinking on how else can this be done because it seems the text on all iProperties can be a multi-line one and it's the iProperties window that is's picking up just the last line of text. I didn't wanted to lock Comments and Project with same value so I needed a different solution.

So if you can force the value in a different way it will support multi-line.

First thought was to have 3 parameters for each line of text that he wanted and then have a form called project where he can enter the text on each parameter (each line). Then use iLogic to send all three parameters to Project value like this:


iProperties.Value("Project", "Project") = "line1" & vbLf & "line2" & vbLf & "line2"

Notice the & vblf & that sends a line feed (enter) command after each line.




This seem complicated having all this parameter and iLogic embedded in the template especially since it's very rare that we need this.
Then I've thought that this can be done with just an iLogic rule that can be called and run when needed. Something like this:

---------this was not working, because it didn't retain the ln values ------
ln1 = InputBox("Enter first line", "Project iLogic ln1", ln1)
ln2 = InputBox("Enter second line", "Project iLogic ln2", ln2)
ln3 = InputBox("Enter third line", "Project iLogic ln3", ln3)
iProperties.Value("Project", "Project") = ln1 & vbLf & ln2 & vbLf & ln3
InventorVb.DocumentUpdate()
---------this was not working, because it didn't retain the ln values ------

So we need to add custom properties that can hold the text value of each line like this:

' - - - - - - - - start of iLogic code - - - - - - - -
Dim sTitleLn1 As String = "Enter first line value" 'Set default text for line
Dim sTitleLn2 As String = "Enter second line value" 'Set default text for line
Dim sTitleLn3 As String = "Enter third line value" 'Set default text for line
Dim sText As String

  'define custom property collection
oCustomPropertySet = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties")

Try
            'get current value if exists
                sText = iProperties.Value("Custom", sTitleLn1)
            'set default value text in prompt window
                sText = InputBox("Enter first line:", "iLogic", sText )
            'copy back text to iProperties
                iProperties.Value("Custom", sTitleLn1) = sText
Catch
            ' if current iprop value does not exist
                oCustomPropertySet.Add("", sTitleLn1)
            'set default value text in prompt window
                sText = InputBox("Enter the Destination Code:", "iLogic", sText )
            'copy back text to iPropertiess
                iProperties.Value("Custom", sTitleLn1) = sText
End Try


Try
            'get current value if exists
                sText = iProperties.Value("Custom", sTitleLn2)
            'set default value text in prompt window
                sText = InputBox("Enter first line:", "iLogic", sText )
            'copy back text to iProperties
                iProperties.Value("Custom", sTitleLn2) = sText
Catch
            ' if current iprop value does not exist
                oCustomPropertySet.Add("", sTitleLn2)
            'set default value text in prompt window
                sText = InputBox("Enter the Destination Code:", "iLogic", sText )
            'copy back text to iPropertiess
                iProperties.Value("Custom", sTitleLn2) = sText
End Try

Try
            'get current value if exists
                sText = iProperties.Value("Custom", sTitleLn3)
            'set default value text in prompt window
                sText = InputBox("Enter first line:", "iLogic", sText )
            'copy back text to iProperties
                iProperties.Value("Custom", sTitleLn3) = sText
Catch
            ' if current iprop value does not exist
                oCustomPropertySet.Add("", sTitleLn3)
            'set default value text in prompt window
                sText = InputBox("Enter the Destination Code:", "iLogic", sText )
            'copy back text to iPropertiess
                iProperties.Value("Custom", sTitleLn3) = sText
End Try

iProperties.Value("Project", "Project") = iProperties.Value("Custom", sTitleLn1) & vbLf & iProperties.Value("Custom", sTitleLn2) & vbLf & iProperties.Value("Custom", sTitleLn3)


iLogicVb.UpdateWhenDone = True
' - - - - - - - - end of iLogic code - - - - - - - -


The good thing is that you can have this as an external rule available for everybody instead of embedded in the document.

First time you run the code it will have an empty string, after that it will show the existing value in case you only need to do a small change like typing correction or changing case to upper.




After a couple of searches it seems that Autodesk is aware of this limitation and they are working on fixing it.

Decided to force a video every time, no matter how hard or tiring it might be so here it is:

ADS