This is the last post in a sequence. In the first post of the sequence I discovered that it isn’t possible to assign names to faces in an assembly. I wanted that function therefore I decided to improve Logic. In this last post I will put it all together. And make it possible to create, view and use named faces of assemblies in a drawing.
Probaly you don't find it as polished as the official iLogic stuff, but remember i'm not working for, or get paid by, a multinational company (like Autodesk). This is just me in my own time, trying to improve my coding skils, and along the way i hope it helps others.
Anyway to make it all work you will need the following rules.
IManagedDrawingViewExtensions
This rule/class was shown in the post “Add function "GetProxyIntent()" to Ilogic”. The rules in that post shows how to make it possible to create dimensions, on a drawing, using named faces in an assembly. The rule/class “IManagedDrawingViewExtensions” is what you need for all the magic. In the post is also an example on how to use it in a drawing.
Label
This rule/class was shown in the post “Create custom 3D Labels with iLogic". The rules in that post shows how to make 3D labels.
ShowLabelsOnNamedFaces and HideLabelsOnNamedFaces
This rules where shown in the post “Adding 3D labels to named faces in assemblies". The rules in that post shows how you can show/hide labels for all named faces.
AssignNameToFace
This is a new rule. When you run it, it will ask you to select a face in a assembly and give a name. when you do that nothing will visibly change. (in the background an attribute is added to the face) if you want to see what any thing you need to run the rule “ShowLabelsOnNamedFaces”. The rule will also let you change/delete an assigned name of a faces by selecting a face that has already been assigned. You can delete names by removing all text when the new name is asked by the rule. The rule looks like this:
AddVbFile "Label.iLogicVb"
Dim doc As AssemblyDocument = ThisDoc.Document
Dim attSetName As String = "iLogicEntityNameSet"
Dim attName As String = "iLogicProxyEntityName"
Dim face As FaceProxy = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select a face that you want to assign a name to.")
Dim attSet As AttributeSet
If (face.AttributeSets.NameIsUsed(attSetName)) Then
attSet = face.AttributeSets.Item(attSetName)
Else
attSet = face.AttributeSets.Add(attSetName)
End If
If attSet.NameIsUsed(attName) Then
Dim att As Attribute = attSet.Item(attName)
Dim name As String = InputBox("Give name for face.", "Assign name (By Jelte de Jong)", att.Value)
Try
Dim l As Label = New Label(doc, att.Value)
l.delete()
Catch ex As Exception
End Try
If (String.IsNullOrWhiteSpace(name)) Then
att.Delete()
Else
att.Value = name
' labels are removed when they are renamed.
' it would be possible automaticaly recreate them but that is not done in this rule.
End If
Else
Dim name As String = InputBox("Give name for face.", "Assign name (By Jelte de Jong)", "")
attSet.Add(attName, ValueTypeEnum.kStringType, name)
End If
I putted all functions in 1 external iLogic rules folder. That makes it easy for me to find them. If you also want to do that then you need to change the code a bit in the rules. Change “AddVbFile "Label.iLogicVb" to “AddVbFile "dimensions\Label.iLogicVb” (where “dimensions” is the folder that you created)
Also, I used my addon “ButtonConstructor” to create buttons for the rules. It all looks like this. I must admit it took some tinkering to get the buttons to work. But its cool that it is possible.