Friday, September 5, 2014

iLogic - Dimension Text Scale

Issue:
You have some iLogic code to help you setup your drawing sheets and title block size (see this link from Jonathan Landeros for a great example of using iLogic to configure title block and borders). But when you change sheet to a larger size the dimension text is hard to read. You'd like to be able to adjust the dimension style text size as well.



Solution:
Here is a quick iLogic rule that prompts the user to set the text size. You could remove the user input lines, and just have the value set depending on the sheet size as well.



'set active document as drawing document
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument

'get the active dim style
Dim oDStyle As DimensionStyle
oDStyle = oDoc.StylesManager.ActiveStandardStyle. _
ActiveObjectDefaults.LinearDimensionStyle

'get current font size
Dim sFontSize as String
sFontSize = oDStyle.TextStyle.FontSize

'get user input
oInput = InputBox("Active Dimesnion Style = " &  oDStyle.Name _
& vblf & vblf &  "Enter a new font size in inches." , "iLogic", _
Round(sFontSize / 2.54,3))

'set font size for dim style
oDStyle.TextStyle.FontSize = oInput * 2.54





Here is a related topic also:
http://inventortrenches.blogspot.com/2011/05/use-ilogic-to-change-sheet-orientation.html

Tuesday, June 24, 2014

iLogic: Working with the Active Sketch


Issue:
You're working with sketches in some iLogic code and want to be able to find the active sketch name, or active sketch number. 



Solution:
Here are a couple of quick rules that will do this. And also as a bonus there is a quick rule to delete all sketches in the part.

Rule1: Find the active sketch name



Dim oSketch As PlanarSketch
If Typeof ThisApplication.ActiveEditObject Is Sketch Then
oSketch = ThisApplication.ActiveEditObject
MessageBox.Show(oSketch.Name & " is the active Sketch", "iLogic")
Else
MessageBox.Show("Active Edit Object is not a Sketch", "iLogic")
End If




Rule2: Find the active sketch number



Dim oSketches As PlanarSketches
oSketches = ThisApplication.ActiveDocument.ComponentDefinition.Sketches

i=1
For Each oSketch in oSketches
            oSketch = oSketches.Item(i)
                   If oSketch Is ThisApplication.ActiveEditObject Then
                   MessageBox.Show("The active sketch is number: " & i, "iLogic")
                   Else
                   End If
          i=i+1  
Next
 



Rule3: Delete all sketches.



Dim oSketches As PlanarSketches
oSketches = ThisApplication.ActiveDocument.ComponentDefinition.Sketches

If Typeof ThisApplication.ActiveEditObject Is Sketch Then
ThisApplication.ActiveEditObject.ExitEdit
Else
End If

For Each oSketch in oSketches
            oSketch = oSketches.Item(oSketch.Name)
          oSketch.Delete
Next