Inventor General Discussion

Inventor General Discussion

Reply
New Member
tomasmik
Posts: 2
Registered: ‎11-01-2012
Message 1 of 2 (147 Views)

Automatic StartMacro error help

147 Views, 1 Replies
11-01-2012 12:19 PM

Hello, I am beginner in autodesk and VBA and got one little problem.

I already made my model in .ipt and want to change 3 parameters of my model via VBA macro. It works ok but only if I manually start macro in VBA editor/autodesk. But now i need to run this macro on startup when i open my .ipt file (document project).

I got an init error on my start up macro(cant change parameters(dimensions)of my model)

 

This is code in my Form:

 

Public Parameter As Inventor.Parameters

Private Sub UserForm_Initialize()

On Error GoTo ErrorHandler
Set Parameter = ThisApplication.ActiveDocument.ComponentDefinition.Parameters
TextBox1.Value = 10 * Parameter.Item("dlzkadiery").Value
TextBox2.Value = 10 * Parameter.Item("diera1").Value
TextBox3.Value = 10 * Parameter.Item("vysunvystupku1").Value

Exit Sub
ErrorHandler:
MsgBox "Chyba pri inicializácii okna", vbCritical, "Chyba inicializacie"
End Sub

Private Sub ButtonUpdate_Click()
On Error GoTo ErrorHandler
If TextBox1.Value <> "" And TextBox1.Value > 9 And TextBox1.Value < 101 Then
Parameter.Item("dlzkadiery").Expression = TextBox1.Value
Else: MsgBox "Dĺžka diery: Zadajte hodnotu v intervale 10-100mm", vbInformation, "Zmena hodnôt"
End If

If TextBox2.Value <> "" And TextBox2.Value > 4 And TextBox2.Value < 61 Then
Parameter.Item("diera1").Expression = TextBox2.Value
Else: MsgBox "Priemer diery: Zadajte hodnotu v intervale 5-60mm", vbInformation, "Zmena hodnôt"
End If

If TextBox3.Value <> "" And TextBox3.Value > 4 And TextBox3.Value < 101 Then
Parameter.Item("vysunvystupku1").Expression = TextBox3.Value
Else: MsgBox "Vysunutie vystupku: Zadajte hodnotu v intervale 5-100mm", vbInformation, "Zmena hodnôt"
End If

ThisApplication.ActiveDocument.Update
Exit Sub
ErrorHandler:
MsgBox "Chyba pri zmene parametrov", vbCritical, "Chyba parametrov"
End Sub
Private Sub ButtonDefault_Click()
On Error GoTo ErrorHandler
TextBox1.Value = 50
TextBox2.Value = 50
TextBox3.Value = 15

Exit Sub

ErrorHandler:
MsgBox "Chyba pri zápise defaultnych hodnôt", vbCritical, "Chyba hodnot"
End Sub

Private Sub ButtonExit_Click()
End
End Sub

 and this is code in my module

Public Sub EditParamsAutoOpen()
UserForm1.Show vbModeless
End Sub

 Fast help is greatly appreciated

New Member
tomasmik
Posts: 2
Registered: ‎11-01-2012
Message 2 of 2 (122 Views)

Re: Automatic StartMacro error help

11-02-2012 03:36 AM in reply to: tomasmik

bump, still need help, any tips ? 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!