Showing posts with label multi-line. Show all posts
Showing posts with label multi-line. Show all posts

Thursday, 30 April 2015

Edit iProperties with global forms

I’m fed up with this problem so I’ve decided to solve it and since the result came out pretty nice I will share it with you and will try and cover but fusion fittings next time.
PROBLEM1:
                 - You have a drawing with multiple LOD’s (Level of Detail) and you want to change iproperties of the model like for example if you need to change the description of the model. So you right click on a view it could even be the main view, main LOD and select open. You try and change some iproperties and Inventor throws a window telling you that you that a different LOD is being edited and before you close that you can’t save the assembly!
WHAT…. I am just trying to change iproperties, what’s that got to do with LOD? See my post on Inventor forum here : http://forums.autodesk.com/t5/inventor-general-discussion/quot-the-assembly-must-be-saved-before-performing-the-bill-of/m-p/5601004#M543896
PROBLEM 2:
- You need to have multi-line iPropertie texts in the title block and you need to control what goes on each line, control the end of line.
PROBLEM 3:
                 - You got bored opening models just to can alter properties, especially on large assemblies.
PROBLEM 4:
                - You don’t want to hunt for different ipropeties on different tabs, rather lazy want them all in one place for fast editing
SOLUTION:
                Create a form that will edit the properties without opening the assembly, where you add all your needed info in one page with multi-line iProperties on it.




                First you need to setup the folder for your iLogic codes so go to Tools / Options / iLogic Configuration and add a folder in your “External Rule Directories”. This way you can use external rules and keep your drawing template clean and small.
                If you’re working in a shared environment you might want to copy all your design data on a shared network drive because any external forms you add will be available to all your colleagues this way. The files will be located in ..Design Data / iLogic / UI.
                Open a drawing (could be your template.idw) and click on Manage/iLogic/iLogic Browser and head over to global forms tab. Right click create a new form, give it a proper name (Label field) and make sure Modal is set to false (so you can do other stuff in Inventor while this is open on top).

                 Click ok for now and let’s add a couple of empty iLogic rules that will appear as buttons on our form.
                Head over to the “External Rules” tab on the iLogic browser pane and create new external rules by right clicking. This is what I’ve added:
·         “iPropsFromModel” – to copy existing properties from the model.
·         “iPropsToModel” – in case you want to update the model with the drawing iproperties.
·         “DrawingCheckIn” – if you use vault you can check the drawing and model back to vault.
·         “Drw_Create_Parameters” – this will create the multi-line properties if they don’t exist in the drawing
·         “Drw_Update_iProps” – to force update the iproperties with our multi-line parameters
·         “Save_PDF_DWF” – to automate creation of PDF’s and DWF’s

                In order to add things to your form you need to drag them from the left pane, “Parameters”, “Rules”, “iProperties” or “Tollbox” into the top right pane in the order you want them to show up. Here’s the sequence from my form:


                Resizing the form while editing it is not persistent, so you need to run the form and choose "resize Controlls" while right cliking on the form, check my previous blog here:

                All iProperties are multi-line texts but the iproperties window will only show you the last line of text and will allow you to control the end of line just for the “Comments” field. To test it out type your custom text inside “Comments” and call it in “Description” by adding this formula =<Comments> and you will see the title block showing your line-by-line formatted text.
                You can add Description to your form but it doesn’t display as multi-line and for that you need to create custom parameters, in my case called the same for simplicity: Description and Project.
                Now you can add the above parameters to your form and change “Edit Control Type” to “Multi-line Text Box”. Make sure you resize your form so you can better see all the lines, I keep mine to 3 visible lines but as soon as you pass that the scrollable arrows become active on the right.
               

                I could have included some of these codes inside the drawing template but I want to keep it as clean as possible, minimizing crashes and problems when upgrading to new releases of Inventor.
                The other reason I have separate button (code) for creating Description and Project parameters is so that you can edit old drawings for which you would have to recreate the ilogic rule. Remember that those drawings don’t have Description and Project as parameters so you either add them manually or run this code. You can easily copy an external rule into the document or you could have used code injector to push this code into a batch of drawings. Here’s the link for codeinjector.
                I think it’s not worth the hassle; it’s just one click away to create the parameters in the form so I suggest you add this button to your form even though you might not use it all the times.
                Because I want this form to show up automatically with each new drawing I need to add a small ilogic code inside the drawing template and trigger it before save. The code has a nice trick to only pop-up the form at first time you save the drawing. I don’t want to see it every time I save a drawing especially on large assemblies.



                The trick was to check if the drawing was saved before, having a path on disk and for that we’ll use “IsNullOrWhiteSpace” to verify it. If it doesn’t have a path then just before saving the drawing fire up the form. The drawing still saves but the form shows up as well.
                  Here isthe drawing (AIP 2015), the rules and the form included (you need to copy it over to global forms).
                This way I can edit the model iProperties without needing to open the model which throws out that ugly error about different LOD being edited.


Later,
ADS

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