Inventor General Discussion

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

Automatic StartMacro error help

139 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 (114 Views)

Re: Automatic StartMacro error help

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

bump, still need help, any tips ? 

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube