Thursday, February 16, 2017

iLogic - Dynamic MultiValue Parameter Lists "Filtered" By Current Selected Value

Issue:
You want to "filter" a list (List B) based on the selection from another list (List A), but the lists are long and writing the If/Then or Select Case statements are repetitive, and difficult to maintain. Is there a better way?

Solution:
You can use ArrayLists and For Each Statements to do this, as shown in this example.

Here an illogic form is used, and when a value is selected from List A, then List B and C are reset to include only values less than or equal to the current selected List A value.



Example file:
Dynamic MultiValue Lists iLogic 2015.ipt ‏68 KB    

SyntaxEditor Code Snippet
Example code:

'reset List B list to default
MultiValue.SetList("List_B", 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)

'reset List C list to default
MultiValue.SetList("List_C", 2,4,6,8,10,12,14,16)

Dim B_List As New ArrayList
B_List = MultiValue.List("List_B")

Dim C_List As New ArrayList
C_List = MultiValue.List("List_C")

Dim Temp_List As New ArrayList

Temp_List.Clear
For Each oItem in B_List
    If List_A >= oItem Then
        Temp_List.Add(oItem)
    End If
Next

MultiValue.List("List_B") = Temp_List

Temp_List.Clear
For Each oItem in C_List
    If List_A >= oItem Then
        Temp_List.Add(oItem)
    End If
Next

MultiValue.List("List_C") = Temp_List

Friday, February 10, 2017

Hybrid Wireframe and Shaded Views in Autodesk Inventor




Issue:
You want to create a view on your drawing that has some parts shaded and some that look wire-framed, so you can show some particular detail of your assembly in your detailed drawing.


In the past you could do it as described in tip #1 at this link, but that seems not to work now.
http://inventortrenches.blogspot.com/2011/06/autodesk-inventor-tips-from-around-web.html

Solution:
Here is another way to do this.

  • Create one new Positional Representation ( no need to do anything else with it, other than creating it).
  • Create 2 View Representations
  • In View Representation 1, turn off the visibility of the part you want to show wireframe
  • In View Representation 2, turn off the visibility of everything else
  • Create a drawing Base View and set it to use View Representation 2
  • Create an Overlay View, and set it to use the Positional Representation and View Representation 1
  • In the Overlay View dialog box set the style to be not shaded & hidden lines removed
  • And also in the Overlay View dialog box set the Layer dropdown to be 'As Parts'.



  • Here's a link to a quick video.

    Thursday, October 23, 2014

    iLogic - Suppress Components in all but the Active Level of Detail

    Issue:
    Your assembly has several Level of Detail Representations set up, which works well. The problem is that when you add a new component to the assembly, you have to go to each Level of Detail and suppress the component in order to prevent it from showing up in those existing Level of Detail Representations.



    Solution:
    Here is an iLogic rule that will suppress any selected components in all of the other LOD's, with the exception of the active LOD.

    This allows you to place the component in the assembly with the LOD you want to add the component to set active, then select the component (or components) and run this iLogic rule to remove the component(s) from the other LODs.

    This iLogic rule also doesn't suppress the selected components in the standard LODs, such as the "Master" LOD, the "All Content Center Suppressed" LOD, etc.

    Note too that it saves the file each time one of the other LODs is modified in order to make the changes "stick", so if you have a large assembly with many LODs it might take a bit for this rule to run.






    Dim oDoc As AssemblyDocument
    oDoc = ThisApplication.ActiveDocument

    ' Find all selected components and add them to an ObjectCollection.
    Dim oSelected As ObjectCollection
    oSelected = ThisApplication.TransientObjects. _
    CreateObjectCollection (oDoc.SelectSet)

    'define LOD rep
    Dim oLODRep As LevelOfDetailRepresentation

    'define rep manager
    Rep_Manager =ThisApplication.ActiveDocument. _
    ComponentDefinition.RepresentationsManager

    'define an arraylist to hold the list of  LOD rep names
    Dim NameList As New ArrayList()

    'look at the LOD reps in the assembly
    For Each oLODRep in Rep_Manager.LevelOfDetailRepresentations
    'add the LOD names to the array list
    NameList.add(oLODRep.Name)
    Next

    Dim myLOD as LevelOfDetailRepresentation
    'get the name of the active LOD
    myLOD = Rep_Manager.ActiveLevelOfDetailRepresentation

    'remove active LOD from list
    NameList.remove(myLOD.name)

    'remove standard LODs from list
    NameList.remove("Master")
    NameList.remove("All Components Suppressed")
    NameList.remove("All Parts Suppressed")
    NameList.remove("All Content Center Suppressed")

    'step through the LOD list
    'and suppress the selected components
    Dim sName as String
    For Each sName in NameList
                    'Activate the LOD
                    Rep_Manager.LevelOfDetailRepresentations(sName).Activate
                    For Each oObject in oSelected
                                    Try
                            'suppress component
                                    Component.IsActive(oObject.Name) = False
                                    Catch ' catch any errors
                                    End Try
                            Next
                ThisDoc.Save
    Next    

    'set the original active LOD back to active
    Rep_Manager.LevelOfDetailRepresentations(Trim(myLOD.Name)).Activate

    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