iLogic Rule for Text Manipulation

This iLogic Rule will save a great deal of time in the creation of changeable text features such as the embossed head markings on the FastenMaster BIM objects on this site.

On with the iLogic Rule. If you open the Inventor iLogic version of the OlyLog part, you can see that in the original file I created nine separate sketches, each with their own emboss feature —then manipulated the suppression of these features to create the head markings required.

It was quite easy to write the original code for these parts, but suppression/unsupression of features is probably the thing that causes Inventor to bog down the most. At any rate, all the extra features creates a lot of bloat in the code as can be seen in the codeblocks below.

This is the original code as you will find it over in the BIM section. There is one iLogic Rule called Resolution (as in high or low resolution for the BIM objects) note that there is a Boolean (True/False) statement for each Head Mark feature available:

If Part_Number = “LOG212” And Part_Quality = “High” Then
Part_Length = 2.5
Thread_Length = 1.25
Feature.IsActive(“Thread Normal”) = False
Feature.IsActive(“Head Fillets”) = True
Feature.IsActive(“Head Mark 2.5”) = True
Feature.IsActive(“Head Mark 4.0”) = False
Feature.IsActive(“Head Mark 6.0”) = False
Feature.IsActive(“Head Mark 8.0”) = False
Feature.IsActive(“Head Mark 9.0”) = False
Feature.IsActive(“Head Mark 10.0”) = False
Feature.IsActive(“Head Mark 12.0”) = False
Feature.IsActive(Head Mark 14.0″) = False
Feature.IsActive(“Head Mark 16.0”) = False
Feature.IsActive(Point threads”) = True
Feature.IsActive(“Shank Threads”) = True
Feature.IsActive(“Shank Chamfer”) = True

And this is the new code. Notice that all of the Feature.IsActive statements related to Head Marks are gone. This is now handled by a new string parameter called SketchText.

If Part_Number = “LOG212” And Part_Quality = “High” Then
Parameter(“Part_Length”) = 2.5
Parameter(“Thread_Length”) = 1.25
Parameter(“Text_Width”) = .132
Feature.IsActive(“Thread Normal”) = False
Feature.IsActive(“Head Fillets”) = True
Feature.IsActive(“Point threads”) = True
Feature.IsActive(“Shank Threads”) = True
Feature.IsActive(“Shank Chamfer”) = True

It would be easier to use a string parameter directly to control the text, but in this case it was not possible. The choices needed to be the part number –which is not the same as the text that needs to appear on the head of the fastener. What I did was map the values of the new SketchText string parameter to the existing Part_Number parameter values in a new rule called “Equality” which looks like this…

If Part_Number = “LOG212” Then
SketchText = “2.5”

…note that the value of the SketchText parameter is contained within quotation marks. If this were not so, the value returned would be a number, and every number besides the 2.5 value would truncate to the whole number –which is not how the markings need to appear. The quotation marks will force the return of a string (text) value.

There is also another rule called TextChanger that does the majority of the work in the background. In that rule, as can be seen in the code below, you need to specify the string parameter, which is named SketchText in this instance. This is the multi-value parameter that holds the values that will appear in the text feature. The “HeadMarks” value is the name of the actual sketch in the browser, and would need to match the name of your particular sketch (when you create your own).

AddReference “System.Web”
Imports System.Web

Sub Main()
doc = ThisDoc.Document
Dim strings as New Generic.List(Of String)
strings.Add(SketchText) ‘string parameter holding text I want to push to the sketch
‘strings.Add( EmbossTextLine2)

SetSketchText(“HeadMarks”, strings)

End Sub

The video and text tutorial below describes how to create a quick version yourself. You may want to uncomment the gray text and try multiple lines of text…looks pretty easy.

Now for a very quick tutorial to show how this all works generically. Start a new part, and create a rectangle on the XY plane 1″ tall by 2½” wide and extrude to ¼” thick. On the XY face of this, create a new sketch, and activate the text tool. Change the size of the text to .240 and type Text into the text box. Center the text by Center and Middle  justifying the text, then constraining the text bounding box to the perimeter of the face you are working on, then exit the sketch. Rename the sketch Text (if you watch the video, you will see that you will get an error if you forget this part).

Open the iLogic Parameter Editor and create a rule called SketchText, and make it a string (text) parameter, then make it multi-value. In the Value List Editor, add “Number One”, “Number Two, Number Three, and “Number Four” hitting enter after each one.

Now download this snippet of code (text format), open the file and copy the rule to the clipboard. Start a new iLogic rule named Text Changer, and paste the text you just copied into the Rule Editor.

You should now be able to use the iLogic parameter SketchText to change the text on your part.

Now click on the Emboss tool and select the text. Set the Depth at .05, and either Emboss or Engrave –whichever trips your trigger. When you finish, go back to the SketchText parameter and give it a whirl.

That will wrap up the tutorial for this iLogic Rule. The file: contains the modified FastenMaster part as well as the little tutorial file called Numbers. If you get a material missing warning on the BIM file, skip the material and continue. I need to fix that….


Inventor Tutorials

Subscribe to Blog via Email