It is currently Wed Jun 19, 2013 9:31 am

All times are UTC





Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Fri May 11, 2007 8:41 pm 
Offline
MCAD Expert
User avatar

Joined: 26 Apr 2007
Posts: 1439
Country: United States
State: Florida
CAD System: Inventor
So, I am slowly learning basic...I can get input boxes to pop up, use the data in formulas-and spit answers back out on the screen...but what I am now having trouble doing is taking my input paramter into a sketch dimension or parameter:
i.e.
Sub BalcLeng()
Length = InputBox("Please Enter Balcony Length.")
End Sub
where in my model sketch I have a model paramter called "Length".


Share on FacebookShare on TwitterShare on DiggShare on DeliciousShare on TumblrShare on Google+
Top
 Profile  
 
 Post subject:
PostPosted: Fri May 18, 2007 11:44 am 
Offline
MCAD Contributer

Joined: 27 Jul 2004
Posts: 85
Hello,
To get things interacting properly, the data type you get from an input box is a string, however you need a data type of Double for Parameters. I personally would use the Convert to double (CDbl(expression)) function to change the string value received from the input box to a double for use in your parameter.

Try this
Sub BalcLeng()
Dim strInputLength As String ' input box variable assigned here
Dim dblParameterInput As Double ' variable to hold the numeric value once converted

strInputLength = InputBox("Please Enter Balcony Length.") ' get user input
dblParameterInput = CDbl(strInputLength) ' change the uset input string to a double

' This below is a short cut to demonstrate, it assumes you have a part document open, if not it will all go pete tong(... wrong) if not
' may still go wrong anyway actually
Dim varParameter As Inventor.Parameter
' don't which release enabled us to be able to specify what we wanted via names, however you may have to select which item you require
' via an integer e.g. Parameters.Item(1)
Set varParameter = ThisApplication.ActiveDocument.ComponentDefinition.Parameters.Item("Length")
' move the input value to the value
varParameter.Value = dblParameterInput
End Sub

Watch word wrap

Scott


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 18, 2007 2:50 pm 
Offline
MCAD Addict
User avatar

Joined: 22 Mar 2004
Posts: 530
Country: United States
State: Pennsylvania
CAD System: Inventor
One other tip to offer when using Text Boxes for numeric input. If you are trying to get numeric input, you want to restrict entered keystrokes to 0-9 and ".". If a user inadvertantly types in "12A3.06" and isn't paying attention, the CDbl function will throw an error (Type Mismatch). You can use the following code in your Text Box Change event to restrict the input to numeric. Be sure to change the instances of "TextBox1" in your code to match the name of the Text Box you are using.

Code:
Private Sub TextBox1_Change()

Dim workStr As String
Dim buffStr As String
Dim chrIndex As Integer
Dim currChar As Integer
Dim curPos As Integer
Dim badChar As Boolean

'remove any character except 0-9 and "."
    badChar = False
    curPos = TextBox1.SelStart
    buffStr = TextBox1.Text
    For chrIndex = 1 To Len(buffStr)
        currChar = Asc(Mid(buffStr, chrIndex, 1))
        Select Case currChar
        Case 46, 48 To 57
            workStr = workStr & Chr(currChar)
        Case Else
            badChar = True
        End Select
    Next chrIndex
   
    TextBox1.Text = workStr
    If badChar Then
        TextBox1.SelStart = curPos - 1
    End If
   
End Sub

_________________
Robert A. Williams
http://www.leacar.com
"Gentlemen...you can't fight here. This is the War Room!"


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 21, 2007 12:05 pm 
Offline
MCAD Expert
User avatar

Joined: 26 Apr 2007
Posts: 1439
Country: United States
State: Florida
CAD System: Inventor
Thanks,
that helps a ton...now I need the time to play with the code a bit....;-P and then I'll ask a few more questions. Also, just so I am not barking up the wrong tree (or any tree for that matter)...is it possible to write a code that will call/create a new part file (assume it already exists with a complete sketch, just no extrusion or tweaking done to it) and and instert it?

_________________
Swim - Bike - Run ...Repeat
@BreakingChad
The Company Website


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 23, 2007 4:35 pm 
Offline
MCAD Addict
User avatar

Joined: 22 Mar 2004
Posts: 530
Country: United States
State: Pennsylvania
CAD System: Inventor
Yes, it is possible. There are examples in the help file (Look for Samples...) that should put you on the right path.

_________________
Robert A. Williams
http://www.leacar.com
"Gentlemen...you can't fight here. This is the War Room!"


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
POWERED_BY