Tuesday, 25 October 2016

iLogic - Set view labels and Add Selection to SelectSet

Had a little spare time today, so I thought I would play around with one of my iLogic rules.

When creating drawings, I more often than not need to rename the view label.

For a while now I have had code which does that, but the one troubling thing was I had to select the view before running the code, not an issue just painfull, because if I forget to select the view, I have to backout of the code, select the view, run the code again.

My code uses the "Selectset" and I was struggling to find the correct method to ADD to the selectset. I eventually found it in the "Programming/API help" So using the CommandManager.Pick method, I can add to the set.

Anyway here is my code to rename the view labels.

--------------------------------------


'Revision 2
'Date: 25.10.2016
'Notes:
'Added the ability to select a view if none are selected.
'It will also allow you to select another view when completed.

'Set view Label
Sub Main oView
Dim oSSet As SelectSet = ThisDoc.Document.SelectSet
If oSSet.count = 0 Then
    MessageBox.Show("Please select a view first", "iLogic")
'Exit Sub ' Removed rev2
oView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a View") 'Added Rev2
'Added rev2
'Add the selected view to the SelectSet
'Doing this will leave the rest of the code unaltered, as "oSSet.count=1"
oSSet.select(oView)
End If
oMenu ()
End Sub

Sub oMenu
Dim resu1t As String="Result"
Dim oLab As New ArrayList
oLab.Add("Single Assy")
oLab.Add("Mirror Assy")
oLab.Add("Extrusion - Item")
oLab.Add("Extrusion - Mirrored")
oLab.Add("")
oLab.Add("Detail Item")
oLab.Add("")
oLab.Add("Section View")
oLab.Add("Detail View")
oLab.Add("Plan View")
oLab.Add("Axonometric View")
oLab.Add("")
oLab.Add("Elevation")
oLab.Add("Flat Pattern")
oLab.Add("Custom Label")

'Display table and get the selection
resu1t=InputListBox("Select View Label", oLab, resu1t, _
Title := "View Label Choice", ListName := "View Label")

'Set iProperties based on the selection.
If resu1t="Single Assy" Then
Call oSingle

ElseIf resu1t="Mirror Assy" Then
Call oMirror

ElseIf resu1t="Extrusion - Item" Then
Call oExtrusion

ElseIf resu1t="Extrusion - Mirrored" Then
Call oExtrusion_M

ElseIf resu1t="Detail Item" Then
Call oDetail

ElseIf resu1t="Section View" Then
Call oViewSect

ElseIf resu1t="Detail View" Then
Call oViewDet

ElseIf resu1t="Plan View" Then
Call oViewPlan

ElseIf resu1t="Axonometric View"
Call oViewAxon

ElseIf resu1t="Elevation" Then
Call oViewelevation

ElseIf resu1t="Flat Pattern" Then
Call oViewFlat

ElseIf resu1t="Custom Label" Then
Call oViewCUST

End If
End Sub

Sub oSingle
'Set view Label
Dim oSSet As SelectSet = ThisDoc.Document.SelectSet
'Reference to the drawing view from the 1st selected object
Dim oView As DrawingView= trycast(oSSet.item(1), DrawingView)
oModel = ThisDoc.ModelDocument
If oView IsNot Nothing Then
oView.ShowLabel = True

Call project
'MessageBox.Show(iProperties.Value("Project", "Project"), "Title")

oProject=iProperties.Value("Project", "Project")       
        oItemValue= oProject & "_QTY"
'MessageBox.Show(oItemValue, "Title")
'Sub Set properties to create the Custom Fields, Without going into too much detail, I can't do this in one step

o_iPropID_QTY = oModel.PropertySets.Item("User Defined Properties").Item(oitemValue).PropId 'Custom QTY Field, defined above
o_iPropID_ENG = oModel.PropertySets.Item("User Defined Properties").Item("ENG").PropId

'format the model iproperties
    oStringQTY = "<StyleOverride Underline='True' FontSize='0.5' Bold='True'><Property Document='model' PropertySet='User Defined Properties' Property='customPropertyName' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
     & o_iPropID_QTY & "'>customPropertyName </Property></StyleOverride>"
    
     oStringENG = "<StyleOverride Underline='True' FontSize='0.5' Bold='True'><Property Document='model' PropertySet='User Defined Properties' Property='customPropertyName' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
     & o_iPropID_ENG & "'>customPropertyName </Property></StyleOverride>"

    oStringTXT = "<StyleOverride Underline='True' FontSize='0.5' Bold='False'> OFF - AS SHOWN - MARK AS - </StyleOverride>"
    oStringScale = "<Br/><StyleOverride FontSize='0.25'>SCALE <DrawingViewScale/></StyleOverride>"

'add to the view label
oView.Label.FormattedText =  oStringQTY & oStringTXT & oStringENG & oStringScale
Else
    MessageBox.Show("The selected object is not a drawing view", "iLogic")
End If
'If Not oView.Label.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextLeft Then
'        oView.Label.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextLeft
'    End If
Align ()
End Sub

Sub oMirror
'Set view Label
Dim oSSet As SelectSet = ThisDoc.Document.SelectSet
''If oSSet.count = 0 Then
''    MessageBox.Show("You must select a drawing view first", "iLogic")
''Exit Sub
''End If
'Reference to the drawing view from the 1st selected object
Dim oView As DrawingView= trycast(oSSet.item(1), DrawingView)
oModel = ThisDoc.ModelDocument
If oView IsNot Nothing Then
oView.ShowLabel = True
' set up the the project number for the drawing label
Call project

oProj=iProperties.Value("Project", "Project")
oItemValue= oProj & "_QTY"

o_iPropID_QTY = oModel.PropertySets.Item("User Defined Properties").Item(oitemValue).PropId 'Custom QTY Field, defined above
o_iPropID_ENG = oModel.PropertySets.Item("User Defined Properties").Item("ENG").PropId

'format the model iproperties   
oStringQTY = "<StyleOverride Underline='True' FontSize='0.5' Bold='True'><Property Document='model' PropertySet='User Defined Properties' Property='customPropertyName' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
     & o_iPropID_QTY & "'>customPropertyName </Property></StyleOverride>"

     oStringENG = "<StyleOverride Underline='True' FontSize='0.5' Bold='True'><Property Document='model' PropertySet='User Defined Properties' Property='customPropertyName' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
     & o_iPropID_ENG & "'>customPropertyName </Property></StyleOverride>"

    oStringTXT = "<StyleOverride Underline='True' FontSize='0.5' Bold='False'> OFF - AS SHOWN - MARK AS - </StyleOverride>"
    oStringOPP = "<StyleOverride Underline='True' FontSize='0.5' Bold='False'> OFF - OPPOSITE HAND - MARK AS - </StyleOverride>"
    oStringTXTx = "<StyleOverride Underline='True' FontSize='0.5' Bold='True'>x </StyleOverride>"
    oStringScale = "<Br/><StyleOverride FontSize='0.25'>SCALE <DrawingViewScale/></StyleOverride>"
    oReturn="<Br/>"

'add to the view label
oView.Label.FormattedText =  oStringQTY & oStringTXT & oStringENG & oReturn & oStringQTY & oStringOPP & oStringENG & oStringTXTx & oStringScale
Else
    MessageBox.Show("The selected object is not a drawing view", "iLogic")
    End If
Align ()
End Sub

Sub oExtrusion ' Added by Reg 27.01.2016
'''Set view Label
Dim oView As DrawingView
Dim oSSet As SelectSet = ThisDoc.Document.SelectSet 'Added rev 2.0 - Selection

oModel = ThisDoc.ModelDocument
    For Each oView In oSSet

Call project
'MessageBox.Show(iProperties.Value("Project", "Project"), "Title")

oProject=iProperties.Value("Project", "Project")       
        oItemValue= oProject & "_QTY"
'MessageBox.Show(oItemValue, "Title")
'Sub Set properties to create the Custom Fields, Without going into too much detail, I can't do this in one step

o_iPropID_QTY = oModel.PropertySets.Item("User Defined Properties").Item(oitemValue).PropId 'Custom QTY Field, defined above
o_iPropID_ENG = oModel.PropertySets.Item("User Defined Properties").Item("ENG").PropId

'format the model iproperties
    oStringQTY = "<StyleOverride Underline='True' FontSize='0.5' Bold='True'><Property Document='model' PropertySet='User Defined Properties' Property='customPropertyName' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
     & o_iPropID_QTY & "'>customPropertyName </Property></StyleOverride>"
    
     oStringENG = "<StyleOverride Underline='True' FontSize='0.5' Bold='True'><Property Document='model' PropertySet='User Defined Properties' Property='customPropertyName' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
     & o_iPropID_ENG & "'>customPropertyName </Property></StyleOverride>"

    oStringStock = "<Br/><StyleOverride FontSize='0.25'><Property Document='model' PropertySet='Design Tracking Properties' Property='Stock Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='55'>STOCK NUMBER</Property></StyleOverride>"
    oStringTXT = "<StyleOverride Underline='True' FontSize='0.5' Bold='False'> OFF - AS SHOWN - MARK AS - </StyleOverride>"
    oStringScale = "<Br/><StyleOverride FontSize='0.25'>SCALE <DrawingViewScale/></StyleOverride>"

'add to the view label
oView.Label.FormattedText =  oStringQTY & oStringTXT & oStringENG & oStringStock & oStringScale
Next
Align ()
End Sub

Sub oExtrusion_M ' Added by Reg 27.01.2016
'Set view Label
Dim oSSet As SelectSet = ThisDoc.Document.SelectSet
'Reference to the drawing view from the 1st selected object
Dim oView As DrawingView= trycast(oSSet.item(1), DrawingView)
oModel = ThisDoc.ModelDocument
If oView IsNot Nothing Then
oView.ShowLabel = True

Call project
'MessageBox.Show(iProperties.Value("Project", "Project"), "Title")

oProject=iProperties.Value("Project", "Project")       
        oItemValue= oProject & "_QTY"
'MessageBox.Show(oItemValue, "Title")
'Sub Set properties to create the Custom Fields, Without going into too much detail, I can't do this in one step

o_iPropID_QTY = oModel.PropertySets.Item("User Defined Properties").Item(oitemValue).PropId 'Custom QTY Field, defined above
o_iPropID_ENG = oModel.PropertySets.Item("User Defined Properties").Item("ENG").PropId

'format the model iproperties
    oStringQTY = "<StyleOverride Underline='True' FontSize='0.5' Bold='True'><Property Document='model' PropertySet='User Defined Properties' Property='customPropertyName' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
     & o_iPropID_QTY & "'>customPropertyName </Property></StyleOverride>"
    
     oStringENG = "<StyleOverride Underline='True' FontSize='0.5' Bold='True'><Property Document='model' PropertySet='User Defined Properties' Property='customPropertyName' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
     & o_iPropID_ENG & "'>customPropertyName </Property></StyleOverride>"

    oStringStock = "<Br/><StyleOverride FontSize='0.25'><Property Document='model' PropertySet='Design Tracking Properties' Property='Stock Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='55'>STOCK NUMBER</Property></StyleOverride>"
    oStringOPP = "<StyleOverride Underline='True' FontSize='0.5' Bold='False'> OFF - OPPOSITE HAND - MARK AS - </StyleOverride>"
    oStringTXTx = "<StyleOverride Underline='True' FontSize='0.5' Bold='True'>x </StyleOverride>"

    oStringTXT = "<StyleOverride Underline='True' FontSize='0.5' Bold='False'> OFF - AS SHOWN - MARK AS - </StyleOverride>"
    oStringScale = "<Br/><StyleOverride FontSize='0.25'>SCALE <DrawingViewScale/></StyleOverride>"
    oReturn="<Br/>"

'add to the view label
oView.Label.FormattedText =  oStringQTY & oStringTXT & oStringENG & oReturn & oStringQTY & oStringOPP & oStringENG & oStringTXTx & oStringStock & oStringScale
Else
    MessageBox.Show("The selected object is not a drawing view", "iLogic")
End If
Align ()
End Sub

Sub oDetail
Dim oView As DrawingView
Dim oSSet As SelectSet = ThisDoc.Document.SelectSet 'Added rev 2.0 - Selection

oModel = ThisDoc.ModelDocument
    For Each oView In oSSet

'format the model iproperties   
    oStringTXT = "<StyleOverride Underline='True' FontSize='0.5' Bold='False'>ITEM <DrawingViewName/> DETAIL </StyleOverride>"
    oStringStock = "<Br/><StyleOverride FontSize='0.25'><Property Document='model' PropertySet='Design Tracking Properties' Property='Stock Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='55'>STOCK NUMBER</Property></StyleOverride>"
    oStringScale = "<Br/><StyleOverride FontSize='0.25'>SCALE <DrawingViewScale/></StyleOverride>"

'add to the view label
oView.Label.FormattedText =  oStringTXT & oStringStock & oStringScale
    Next
    Align ()
End Sub

Sub oViewSect
Dim oView As DrawingView
Dim oSSet As SelectSet = ThisDoc.Document.SelectSet 'Added rev 2.0 - Selection

oModel = ThisDoc.ModelDocument
    For Each oView In oSSet

'format the model iproperties   
    oStringTXT = "<StyleOverride Underline='True' FontSize='0.5' Bold='False'>SECTION  </StyleOverride>"
    oStringScale = "<Br/><StyleOverride FontSize='0.25'>SCALE <DrawingViewScale/></StyleOverride>"

'add to the view label
oView.Label.FormattedText =  oStringTXT & oStringScale
Next
Align ()
'Next
End Sub

Sub oViewDet
'Detail view Label Reset
Dim oView As DrawingView
Dim oSSet As SelectSet = ThisDoc.Document.SelectSet 'Added rev 2.0 - Selection

oModel = ThisDoc.ModelDocument
    For Each oView In oSSet

'format the model iproperties   
    oStringTXT = "<StyleOverride Underline='True' FontSize='0.5' Bold='False'>DETAIL  </StyleOverride>"
    oStringScale = "<Br/><StyleOverride FontSize='0.25'>SCALE <DrawingViewScale/></StyleOverride>"

'add to the view label
oView.Label.FormattedText =  oStringTXT & oStringScale
Next
Align ()
'Next
End Sub

Sub oViewPlan
'Detail view Label Reset
'Set view Label
Dim oSSet As SelectSet = ThisDoc.Document.SelectSet
'Reference to the drawing view from the 1st selected object
Dim oView As DrawingView= trycast(oSSet.item(1), DrawingView)
oModel = ThisDoc.ModelDocument
If oView IsNot Nothing Then
oView.ShowLabel = True

'format the model iproperties   
    oStringTXT = "<StyleOverride Underline='True' FontSize='0.5' Bold='False'>PLAN VIEW  </StyleOverride>"
    oStringScale = "<Br/><StyleOverride FontSize='0.25'>SCALE <DrawingViewScale/></StyleOverride>"

'add to the view label
oView.Label.FormattedText =  oStringTXT & oStringScale

Else
    MessageBox.Show("The selected object is not a drawing view", "iLogic")
End If
Align ()
End Sub

Sub oViewAxon
'Detail view Label Reset
'Set view Label
Dim oSSet As SelectSet = ThisDoc.Document.SelectSet
'Reference to the drawing view from the 1st selected object
Dim oView As DrawingView= trycast(oSSet.item(1), DrawingView)
oModel = ThisDoc.ModelDocument
If oView IsNot Nothing Then
oView.ShowLabel = True

'format the model iproperties   
    oStringTXT = "<StyleOverride Underline='True' FontSize='0.5'
    oStringScale = "<Br/><StyleOverride FontSize='0.25'>SCALE N.T.S</StyleOverride>"

'add to the view label
oView.Label.FormattedText =  oStringTXT & oStringScale

Else
    MessageBox.Show("The selected object is not a drawing view", "iLogic")
End If
Align ()
End Sub

Sub oViewelevation
'Detail view Label Reset
'Set view Label
Dim oSSet As SelectSet = ThisDoc.Document.SelectSet
'Reference to the drawing view from the 1st selected object
Dim oView As DrawingView= trycast(oSSet.item(1), DrawingView)
oModel = ThisDoc.ModelDocument
If oView IsNot Nothing Then
oView.ShowLabel = True

'format the model iproperties   
    oStringTXT = "<StyleOverride Underline='True' FontSize='0.5' Bold='False'>ELEVATION  </StyleOverride>"
    oStringScale = "<Br/><StyleOverride FontSize='0.25'>SCALE <DrawingViewScale/></StyleOverride>"

'add to the view label
oView.Label.FormattedText =  oStringTXT & oStringScale

Else
    MessageBox.Show("The selected object is not a drawing view", "iLogic")
End If
Align ()
End Sub

Sub oViewFlat
'Detail view Label Reset
'Set view Label
Dim oSSet As SelectSet = ThisDoc.Document.SelectSet
'Reference to the drawing view from the 1st selected object
Dim oView As DrawingView= trycast(oSSet.item(1), DrawingView)
oModel = ThisDoc.ModelDocument
If oView IsNot Nothing Then
oView.ShowLabel = True

'format the model iproperties   
    oStringTXT = "<StyleOverride Underline='True' FontSize='0.5' Bold='False'>ITEM FLAT PATTERN  </StyleOverride>"
    oStringScale = "<Br/><StyleOverride FontSize='0.25'>SCALE <DrawingViewScale/></StyleOverride>"

'add to the view label
oView.Label.FormattedText =  oStringTXT & oStringScale

Else
    MessageBox.Show("The selected object is not a drawing view", "iLogic")
End If
Align ()
End Sub

Sub oViewCUST
'Detail view Label Reset
'Set view Label
Dim oSSet As SelectSet = ThisDoc.Document.SelectSet
'Reference to the drawing view from the 1st selected object
Dim oView As DrawingView= trycast(oSSet.item(1), DrawingView)
oModel = ThisDoc.ModelDocument
If oView IsNot Nothing Then
oView.ShowLabel = True

oLabel = InputBox("Enter Custom Label", "Title", "FRONT ELEVATION")
    oStringCUST = "<StyleOverride Underline='True' FontSize='0.5' Bold='False'>"& oLabel &"</StyleOverride>"
    oStringScale = "<Br/><StyleOverride FontSize='0.25'>SCALE <DrawingViewScale/></StyleOverride>"

'add to the view label
oView.Label.FormattedText =  oStringCUST & oStringScale

Else
    MessageBox.Show("The selected object is not a drawing view", "iLogic")
End If
Align ()
End Sub


Sub Align
Dim oDoc As DrawingDocument = ThisDoc.Document
Dim oSheet As Sheet = oDoc.ActiveSheet
Dim oView As DrawingView
For Each oView In oSheet.DrawingViews
    If Not oView.Label.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextLeft Then
        oView.Label.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextLeft
    End If
Next
oAgain=MessageBox.Show("Do you wish to select another view?", "Rinse and Repeat",MessageBoxButtons.YesNo, MessageBoxIcon.Question) 'Added rev2
If oAgain=vbYes
AGAIN ()
End If
End Sub

Sub Project
oProject = InputBox("Change Project Name", "Project Name", iProperties.Value("Project", "Project"))
        iProperties.Value("Project", "Project")=oProject
Return
End Sub

Sub AGAIN ' added rev2
Main
End Sub

Wednesday, 6 January 2016

iLogic to sort Parts List

A few years ago I posted some iLogic code to update and sort the BOM.

This proved rather troublesome, and never really worked for me, so I decided to do it via the detail drawing.  This works MUCH better.

The following is for my environment only, but I am sure you can adapt this for your own needs.

I have a few extra fields in my parts and assemblies, one of which is a custom parameter named "TYPE"

Notes on the iProperty fields: 

"STOCK NUMBER" = Area and/or size of component, E.G "100 x 50 x 5 x 6000 RHS"
"COST CENTER" = Broad based item type E.G. 'TUBE' or 'PLATE'
"TYPE" = More precise item type E.G. 'SHS' or 'RHS' or 'Cleat' etc

Prerequisites: 

1: In order for the code to function correctly, the Parts list must contain the fields in question.



Note how the column width has been set to "1" this "hides" the column from view.



2: There is a Radiobox, true false check. This is applicable for the times you have more than one parts list present on your drawing. Once again this is due to my environment, where my marking plan will have a Structured parts list for item making via balloons as well as the itemised parts list. I will sometimes have a third parts list containing fasteners only.

This section can be removed. Comment out the fist section of the sort. (From the "If True" up to and including the "else" statement, don't forget to comment out the "End if" as well )

TIPS and Caveats

1: I have found the best way to maintain the GA partslist/BOM is to have a separate drawing containing the GA and UNFILTERED Partslist. This one becomes god, and any other GA drawings containing the partlist get sorted via item number only.

2: Sub Assemblies work well with this code, and you don't need to have a separate drawing for management. you will find that the drawings become more consistent and predictable.

3: I have labeled my Fasteners with a 'z'. this forces them to the bottom of my parts list.


This process also forces you to manage and maintain a healthy BOM.
Don't forget, this writes back and updates the Assembly.

The Code:


'start of iLogic code----------------------------------------------------------------------------------
'sort parts list
oBOM = InputRadioBox("Parts List QTY", "2", "1", oBOM, Title := "PartsList Value")

If oBOM=True Then
On Error Resume Next
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

Dim oPartsList1 As PartsList
oPartsList1 = oDrawDoc.ActiveSheet.PartsLists.Item(2)
oPartsList1.Sort("COST CENTER",1,"TYPE", 1, "STOCK NUMBER", 1)
oPartsList1.Renumber
oPartsList1.SaveItemOverridesToBOM

Else

On Error Resume Next
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

Dim oPartsList1 As PartsList
oPartsList1 = oDrawDoc.ActiveSheet.PartsLists.Item(1)
oPartsList1.Sort("COST CENTER",1,"TYPE", 1, "STOCK NUMBER", 1)
oPartsList1.Renumber
oPartsList1.SaveItemOverridesToBOM
End If

'End  of iLogic code.

The result: 




Wednesday, 6 May 2015

I have just installed my new home computer and discovered that the SDK did not want to work anymore.  You know the "Drawing Tools" addin with the revcloud feature. (Why this is not a standard feature no-one knows)

I tried everything that I have previously posed, only to find that it does not work.  Guess what ? The answer was right there all along, hidden in the text file:


Solution to get it working:
1) Open a command prompt (I used admin mode)
2) cd\C:\Users\Public\Documents\Autodesk\Inventor 2015\SDK\UserTools\DrawingTools\bin
3) Type regsvr32 "DrawingTools.dll"

That's it, open inventor and the addin will be available.


I found a typo, and thought I would correct it quickly, just in case someone actually reads this stuff.
Step 2 correction.
cd\Users\Public\Documents\Autodesk\Inventor 2015\SDK\UserTools\DrawingTools\bin

Thursday, 17 July 2014

Happiness is...

I received the call yesterday to say that we have been granted a permanent residency Visa for Australia.

I am still in shock, as we have been waiting so long now, finally the axe over our heads has been removed and we can now start our lives again.

☺ ☺ ☺ ☺

Wednesday, 9 July 2014

iLogic Code to create Cusom Parameters

This little piece of code was created to bulk create custom parameters.

When I start with a new project, I sometimes need to create a lot of parameters in the skeleton part/s. This can sometimes be rather time consuming, so I wrote this snippet.

'GDI iLogic to create a new User Parameter
Sub Main()
Dim oNewParam as String
Dim oPartDoc as PartDocument = ThisDoc.Document

'Get the new Parameter Name
    tNewParam = InputBox("Input Name for New Parameter" & vbNewLine & "" & vbNewLine & "add '-DEG' for Angle" & vbNewLine & "E.G: xxx-DEG", "GDI - iLogic", "") ' prompt the user for a parameter name

If tNewParam <>"" Then 'Error Check if user presses the Cancel key
'Split the name If Needed
    oNewParam = Split(tNewParam, "-") (0)

 'Check for the new parameter name
 'If found then Exit to the question of create something else.
    Try
        oParam = oPartDoc.ComponentDefinition.Parameters(oNewParam)
        i1 = MessageBox.Show(oNewParam & vbNewLine & "Parameter already exists", "GDI - iLogic", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
        Call AsktoCreateAnother ' Subroutine to create another
      
        Catch     'If the parameter was not found, then create a new one.
            If tNewParam.contains ("deg") Or tNewParam.contains ("DEG")Then 'Checks the Temp name, inputted by user
                Call DegreeSUB (oNewParam) 'Pass the Variable name to the sub
            Else
                Call mmSUB (oNewParam) 'Pass the Variable name to the sub
            'Return
            End If
        End Try
    Else 'this one comes from the cancel key press
    MessageBox.Show("Cancel key pressed", "GDI - iLogic")
    Return 'exit the code if Cancel is pressed.
    End If
End Sub

Sub DegreeSUB (ByRef oNewParam as String)
Dim oPartDoc as PartDocument = ThisDoc.Document
Dim userParams As UserParameters = oPartDoc.ComponentDefinition.Parameters.UserParameters

oValue=InputBox("Add a Value?", "GDI - iLogic", 0) ' Get a Value if desired
oComment=InputBox("Add a description if desired?", "GDI - iLogic", "") ' Get a description if desired
    Dim newParam As UserParameter ' Placeholder
    Dim oFormat As CustomPropertyFormat
    newParam = userParams.AddByExpression(oNewParam, oValue, "deg") ' Create the Parameter as per above
    newParam.ExposedAsProperty=True 'Flag for Export
    oFormat=newParam.CustomPropertyFormat 'For some reason or other this line is needed to enable the following formatting
    oFormat.PropertyType=Inventor.CustomPropertyTypeEnum.kTextPropertyType
            oFormat.Precision=Inventor.CustomPropertyPrecisionEnum.koneDecimalPlacePrecision 'Set one decimal place
            'oFormat.Units="mm" 'Units
            oFormat.ShowUnitsString=False
            oFormat.ShowLeadingZeros=False
            oFormat.ShowTrailingZeros=False
    newParam.comment=oComment 'Set the Description
    Call AsktoCreateAnother (oNewParam, oComment) ' Subroutine to add another
End Sub

Sub mmSUB (ByRef oNewParam as String)
Dim oPartDoc as PartDocument = ThisDoc.Document
Dim userParams As UserParameters = oPartDoc.ComponentDefinition.Parameters.UserParameters

oValue=InputBox("Add a Value?", "GDI - iLogic", 0) ' Get a Value if desired
oComment=InputBox("Add a description if desired?", "GDI - iLogic", "") ' Get a description if desired
    Dim newParam As UserParameter ' Placeholder
    Dim oFormat As CustomPropertyFormat
    newParam = userParams.AddByExpression(oNewParam, oValue, "mm") ' Create the Parameter as per above
    newParam.ExposedAsProperty=True 'Flag for Export
    oFormat=newParam.CustomPropertyFormat 'For some reason or other this line is needed to enable the following formatting
    oFormat.PropertyType=Inventor.CustomPropertyTypeEnum.kTextPropertyType
            oFormat.Precision=Inventor.CustomPropertyPrecisionEnum.koneDecimalPlacePrecision 'Set one decimal place
            'oFormat.Units="mm" 'Units
            oFormat.ShowUnitsString=False
            oFormat.ShowLeadingZeros=False
            oFormat.ShowTrailingZeros=False
    newParam.comment=oComment 'Set the Description
    Call AsktoCreateAnother (oNewParam, oComment) ' Subroutine to add another
End Sub

Sub AsktoCreateAnother (ByRef oNewParam as String, ByRef oComment As String)
    i2 = MessageBox.Show(oNewparam & " (" & oComment & ")" & " - Created" & vbNewLine & "Add Another", "GDI - iLogic", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
    If i2 = "6" Then
    Main 'Got to the begining
    ElseIf i2 = "7" Then
    'Return
    End If
    Return
End Sub

Sub DONEAsktoCreateAnother
    i3 = MessageBox.Show("Add Another", "GDI - iLogic", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
    If i3 = "6" Then
    Main 'Got to the beginning
    ElseIf i3 = "7" Then
    'Return
    End If
    Return
End Sub

Wednesday, 2 July 2014

iLogic - Transfer a variable to a Sub routine

I discovered this one today, as I wanted a nice clean script, but I just could not pass a variable between my Sub Routines within iLogic.

I am pretty pleased with this, and will now try and make use of in other scripts.

Sub Main()
Dim oNewParam as String
Blah blah ... stuff in the script
Call NextSubRoutine (oNewParam)  'This is the important stuff - The bit in the brackets.
End Sub

Sub NextSubRoutine (ByRef oNewParam as String'NOTE: The bit in the brackets.
MessageBox.Show(oNewParam, "Variable transferred from the Main Sub")
blah blah ... stuff in the script
End Sub