Hi everyone,
First, i thank you in advance for the time spent trying to help me.
So i am trying to enter the world of inventor vba programming and i have been developing a code to change some parameters in an assembly of mine. What i have is a user form where i put some values than in the program calculates some values that i want the program to transmit them to an inventor assembly and change the parameters of a part that is inside the assembly. The code is this one:
Private Sub CommandButton1_Click()
Dim HCI As Integer
Dim HCM As Integer
Dim SFSB As Integer
Dim EBT As Integer
Dim BSF As Integer
Dim SPSB As Integer
Dim DN As Integer
Dim CI As Integer
Dim XSNC As Integer
HCI = TextBox1
HCM = TextBox2
SFSB = TextBox3
EBT = TextBox4
BSF = TextBox5
SPSB = TextBox6
DN = TextBox7
CI = TextBox8
XSNC = TextBox9
Dim C As Integer
C = HCI - (HCM / 2) + SFSB + BSF + 58
Dim D As Integer
D = C - EBT - BSF + 25
Dim G As Integer
G = SPSB
Dim E As Integer
E = 2 * DN + CI - XSNC
Dim F As Integer
F = (E - 20) / 2
Dim AH As Integer
Dim CH As Integer
Dim EH As Integer
Dim GH As Integer
Dim IH As Integer
Dim JH As Integer
AH = D
CH = ((AH - 40) / 150) + 1
EH = (AH - 40) / CH
GH = SPSB
JH = F
IH = JH - 6
' Open The Assembly
Dim invDoc As Document
Set invDoc = ThisApplication.Documents.Open("C:\Users\2251\Desktop\New folder (4)\Shunts Cuba Inferior\Shunts CI E01.iam")
Dim oAsmDoc As AssemblyDocument
Set oAsmDoc = ThisApplication.ActiveDocument
' Get the definition of the assembly.
Dim oAsmDef As AssemblyComponentDefinition
Set oAsmDef = oAsmDoc.ComponentDefinition
'Get the definition of the part
Dim oDoc As Document
Set oDoc = ThisApplication.Documents.ItemByName("C:\Users\2251\Desktop\New folder (4)\Shunts Cuba Inferior\Shunt CI E01.ipt")
Dim ari As PartComponentDefinition
Set ari = oDoc.ComponentDefinition
Dim oParameters As Parameters
Set oParameters = ari.Parameters
Dim oParad0 As Parameter
Set oParad0 = oParameters.Item("d0")
oParad0.Expression = "IH mm"
ThisApplication.ActiveDocument.Update
End Sub
And what happens is that when the program arrives to the oParad0.Expression it gives me an error. when i put the mouse over its equal to the value that i want but the program doesn't transmit it to the inventor. what am i doing wrong?
Thanks for the attention :smileyhappy
Solved! Go to Solution.
Solved by VdVeek. Go to Solution.
arielpipi, with this line : oParad0.Expression = "IH mm" of code you are writing : IH mm : to the parameter "d0". What you want to do is to write the value of IH to the parameter.
Change your line to :
oParad0.Expression = IH that's without the unit
or : oParad0.Expression = IH & " mm" that's with mm units.
Rob.