Showing posts with label Autodesk Inventor iProperties. Show all posts
Showing posts with label Autodesk Inventor iProperties. Show all posts

Monday, February 28, 2011

iLogic Audio Alerts: Set up Autodesk Inventor to give you a scolding!

Issue:
You're not satisfied with polite message boxes to remind you (and/or your fellow Inventor users) to complete common tasks such as filling out iProperties. Instead you'd like to use an iLogic rule to play an audio alert.

Solution:
You can create a rule in your Inventor file, and then use CreateObject to call the Windows media player, and specify a sound file to play. Then you can use a conditional If, Then statement to check to see if the iProperty is empty. And finally you can set up an Event Trigger to run the rule to fire after the file is saved.

Below is a screen shot of the message box and a video of the rule in action, using a wave file of a popular cartoon character exclaiming "ah crap!", which is usually the thought I have when I realize I forgot to fill out the iProperties... again!


Here's a small video of this in action with sound (turn down your speakers if needed).


Here is the sample code.


'start of iLogic Code-----------------------------
‘declare variables
‘get the user name from the Inventor Options
myName= ThisApplication.GeneralOptions.UserName

‘get the iProperty Description Field
Description = iProperties.Value("Project", "Description")

‘create a message for the user
mymessage = (myname & ",  you forgot to fill out the description again.")

‘set the path of the sound file to use
sound_alert = "C:\Users\Curtis\Music\ah_crap.wav"

‘check the iProperty Description Field to see if it is empty
If Description = "" Then
'play a sound
player = CreateObject("MediaPlayer.MediaPlayer.1")
player.FileName = sound_alert

'display a message box
MessageBox.Show(mymessage, "iLogic Reminder")
End If
'end of iLogic Code-----------------------------







Ok, so that was fun!
But why stop there? Here is a variation on this theme using the Windows text to speech utility.  This utility, will read aloud the message from your iLogic code, using a computer generated voice. It's fun to mess around with, but can also be useful. And it is typically installed on most standard versions of Windows.
http://en.wikipedia.org/wiki/Microsoft_text-to-speech_voices

I saw an example of this posted by Rob Cohee, but in his example his computer was a bit more civil than mine!




Here is the sample code.

'start of iLogic Code-----------------------------
‘declare variables
‘get the iProperty Revision Number Field
Revision_Number = iProperties.Value("Project", "Revision Number")

‘create a message for the user
mymessage = ("Really? You're just going to leave the Revision Number blank? You Looser.")

If Revision_Number = "" Then
      '___Use windows voice command____________
      Dim objSPVoice,colVoices
      objSPVoice = CreateObject("SAPI.SpVoice")
      objSPVoice.Speak (mymessage)
      'display a message box
      MessageBox.Show(mymessage, "iLogic Reminder")
End If
'end of iLogic Code-----------------------------



Look for more iLogic examples on this blog or in the chapter dedicated to iLogic Basics in the next edition of Mastering Autodesk Inventor book (due out in June of 2011 if all goes well).

Tuesday, January 4, 2011

iLogic Code To Set The Part Number Per Length Range

Issue:
You purchase stock lengths of material, and then cut them to length. You want to assign a part number based upon the part length so that if the part falls into a given range it receives one part number, and if it falls into another range it receives a different part number, and so on. Thus assigning part numbers based on the stock material lengths.

Solution:
    Click to Enlarge
  • First a multi-value parameter is created and the stock sizes are added to the list, in this case the list is a user parameter called Size. 
  • Next an iLogic rule is created, and an input box is set to read the multi-value list, so the user can select one of the stock sizes.
  • Then a model parameter called Length is set to equal the user parameter called Size.
  • The part is updated to reflect the parameter change
  • A conditional if/then evaluates the length parameter and sets the part number iProperty based on the Length of the part.
  • And finally a message box displays the assigned part number for confirmation.
 
'get size from list
Size= InputListBox("Choose Size", MultiValue.List("Size"), _
Size, Title := "Select Size", ListName := "Available Sizes")

'set length to be Size
Length = Size

'update the part to reflect the parameter change
iLogicVb.UpdateWhenDone = True

If Length <= 250 Then
iProperties.Value("Project", "Part Number") = "000-10"
Else If Length <= 500 Then
iProperties.Value("Project", "Part Number") = "000-20"
Else
iProperties.Value("Project", "Part Number") = "000-30"
End If

'evaluates the length parameter and sets the part number iProperty
PN =iProperties.Value("Project", "Part Number")

'displays the Partn number in a message box.
MessageBox.Show("Part Number: " & PN, "Part Number Confirm",MessageBoxButtons.OK)

 This shows the rule in action, with the part number range scale sketched for illustration purposes. If the length is 250 or less then the part number is 000-10, if its over 250 and less than or equal to 500, then it is 000-20, for anything over 500 the part number is 000-30.

Click to Enlarge
Click here to download the example file (Inventor 2011)
The file is called PN Range From List.ipt

Look for more iLogic examples on this blog or in the chapter dedicated to iLogic Basics in the next edition of Mastering Autodesk Inventor book (due out in June of 2011 if all goes well).