I was wondering what is the parameter for file name if it exist?
I did try: =<file name> and it's not working...
thank you
Tuen,
This is amazing, it is exactly what I am looking for.
The only problem I am having is that when I rename the file in windows explorer and then open the part, the VBA isnt running. I am having to go into the Macros and select it and run it that way.
Im using Inventor 2014. Is there a setting I need to enable for it to run the code when the ipt is opened?
Hi dfitting,
I'm not sure Tuen is still present on this forum, but here is the code from his example file, in iLogic format. You can create a rule in your part and paste in this code, and then set the ilogic "After you open a document" event trigger to run the rule when the file is opened.
'this rule expects a part file named something such as 1x2x5.ipt
'define active document
Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument
'look at the parameters
Dim oParameters As Parameters
oParameters = oPartDoc.ComponentDefinition.Parameters
'define the parameters
Dim oParameter(3) As Parameter
oParameter(0) = oParameters.ModelParameters("d0") 'Length
oParameter(1) = oParameters.ModelParameters("d1") 'Width
oParameter(2) = oParameters.ModelParameters("d2") 'Thickness
'look at the full file name of the part
Dim sFullFileName As String
sFullFileName = oPartDoc.FullFileName
'format the file name
Dim sFileName As String
sFileName = Right(sFullFileName, Len(sFullFileName) - InStrRev(sFullFileName, "\"))
sFileName = Left(sFileName, Len(sFileName) - 4)
'split the file name using x as the sperator
'and set it to an array
Dim Values() As String
Values = Split(sFileName, "x")
'parse the array and set the parameters
Dim i As Integer
For i = 0 To 2
oParameter(i).Expression = Values(i)
Next i
'update the model
oPartDoc.Update
'zoom all
ThisApplication.ActiveView.Fit
Creating a Basic iLogic Rule with an Event Trigger
http://inventortrenches.blogspot.com/2012/01/creating-basic-ilogic-rule-with-event.html
Work with event triggers in iLogic
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Thanks a bunch Curtis, I actually go it working with a simple ilogic rule that calls the vba, I am going to use this instead though so that its not using ilogic to call the vba, might get messy down the road.
A quick question, if I wanted to name my file 50x25x2 - Earthen Berm or maybe a client name, how would I get the ilogic to stop reading the file name once it gets to the -
Hi dfitting,
This rule should do it. I added a couple of new things to set the Part Number, Description, and reset the browser, etc.
'this rule expects a part file named something such as 1x2x5.ipt 'define active document Dim oPartDoc As PartDocument oPartDoc = ThisApplication.ActiveDocument 'look at the parameters Dim oParameters As Parameters oParameters = oPartDoc.ComponentDefinition.Parameters 'define the parameters Dim oParameter(3) As Parameter oParameter(0) = oParameters.ModelParameters("d0") 'Length oParameter(1) = oParameters.ModelParameters("d1") 'Width oParameter(2) = oParameters.ModelParameters("d2") 'Thickness 'look at the full file name of the part Dim sFullFileName As String sFullFileName = oPartDoc.FullFileName 'format the file name Dim sFileName As String sFileName = Right(sFullFileName, Len(sFullFileName) - InStrRev(sFullFileName, "\")) sFileName = Left(sFileName, Len(sFileName) - 4) 'define seperators as capital X, lower case x, and dash Dim Separators() As Char = {"X"c,"x"c, "-"c} 'define and set array to hold results of split filename Dim Values() As String Values = sFileName.Split(Separators) 'parse the array and set the parameters Dim i As Integer 'look at first three Values in the array (0 ,1, 2) For i = 0 To 2 'set parameter values to array values oParameter(i).Expression = Values(i) Next i 'set Part Number iProperties.Value("Project", "Part Number") = Values(0) & "x" & Values(1) & "x" & Values(2) 'set Description iProperties.Value("Project", "Description") = Values(0) & "x" & Values(1) & "x" & Values(2) & "-" & Values(3) 'set Description (alternative method) 'iProperties.Value("Project", "Description") = sFileName 'reset browser name (in case someone has overidden it in the past) ThisDoc.Document.DisplayName = "" 'update the model oPartDoc.Update 'zoom all ThisApplication.ActiveView.Fit
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Thank you sir for all your help!
Works perfectly, had to remove the little c's that were in this line:
Dim Separators() As Char = {"X","x", "-"}