Community
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
Can't find what you're looking for? Ask the community or share your knowledge.