Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Use filename as parameter

16 REPLIES 16
Reply
Message 1 of 17
EmpireBuff
1935 Views, 16 Replies

Use filename as parameter

Is there a way to use the filename to drive the parameters of the file?

Example: I have a cube that is called 4x4x4.ipt its dimensions d0,d1,d2 are 4,4,4 respectively. I want to rename it to 4x4x6.ipt and have the dimensions d0,d1,d2 resize to 4,4,6.

Thanks
16 REPLIES 16
Message 2 of 17
Anonymous
in reply to: EmpireBuff

Option 1: Through VB code read the filename and parse it and then set it to the parameters d0,d1,d2 and update. autodesk.inventor.customization group could provide more help here.

Option 2: You might be knowing this already you can create an iPart with d0,d1,d2 as columns and then create keys for them and then see if that works out. You could add rows for as many variations as possible. This does create files though.

Thanks

shekar
Message 3 of 17
Anonymous
in reply to: EmpireBuff

Free of charge 😉

--
T. Ham
Mechanical Engineer
CDS Engineering BV

HP xw4300 Workstation
Dual Pentium XEON 3.6 Ghz
4 GB SDRAM
NVIDIA QUADRO FX 3450/4000 SDI (Driver = 8.4.2.6)
250 GB SEAGATE SATA Hard Disc
3Com Gigabit NIC

Windows XP Professional SP2
Autodesk Inventor Series 10 SP3a
--
Message 4 of 17
Anonymous
in reply to: EmpireBuff

option 3 get a copy of yippee pro.

use the parameters to drive the filename
Message 5 of 17
Anonymous
in reply to: EmpireBuff

The only problem...he wants it the other-way-around 🙂

--
T. Ham
Mechanical Engineer
CDS Engineering BV

HP xw4300 Workstation
Dual Pentium XEON 3.6 Ghz
4 GB SDRAM
NVIDIA QUADRO FX 3450/4000 SDI (Driver = 8.4.2.6)
250 GB SEAGATE SATA Hard Disc
3Com Gigabit NIC

Windows XP Professional SP2
Autodesk Inventor Series 10 SP3a
--
Message 6 of 17
Anonymous
in reply to: EmpireBuff

some say tomato, some say tomato, wait that doesnt work here...

i really should think about learning some code, nice work
Message 7 of 17
Anonymous
in reply to: EmpireBuff

For those of you who are curious how Teun did it he used Option 1. When you open the IPT file attached by Teun go to Tools, Macro, Visual Basic Editor to see the script that will be run when the file is opened. Nice job Teun. Thanks.

shekar
Message 8 of 17
Anonymous
in reply to: EmpireBuff

One remark: the macro is embedded in the IPT. This can cause problems when
you have a lot of IPTs open at the same time (it's a VBA limitation, so you
can blame Microsoft for it)

An Add-in would solve that problem, but my example is just to show that it
can be done!

Cheers,

--
T. Ham
Mechanical Engineer
CDS Engineering BV

HP xw4300 Workstation
Dual Pentium XEON 3.6 Ghz
4 GB SDRAM
NVIDIA QUADRO FX 3450/4000 SDI (Driver = 8.4.2.6)
250 GB SEAGATE SATA Hard Disc
3Com Gigabit NIC

Windows XP Professional SP2
Autodesk Inventor Series 10 SP3a
--
Message 9 of 17
EmpireBuff
in reply to: EmpireBuff

You have all been very helpful, especially you Teun, I was trying to do this for a while now and only found out about this discussion group yesterday. My first experience has been very good !!!!

Cheers !!!
Message 10 of 17
Anonymous
in reply to: EmpireBuff

No problem!

--
T. Ham
Mechanical Engineer
CDS Engineering BV

HP xw4300 Workstation
Dual Pentium XEON 3.6 Ghz
4 GB SDRAM
NVIDIA QUADRO FX 3450/4000 SDI (Driver = 8.4.2.6)
250 GB SEAGATE SATA Hard Disc
3Com Gigabit NIC

Windows XP Professional SP2
Autodesk Inventor Series 10 SP3a
--
Message 11 of 17
UpRising
in reply to: EmpireBuff

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

Message 12 of 17
UpRising
in reply to: UpRising

so there is no way to do that?

Message 13 of 17
dfitting
in reply to: Anonymous

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?

Message 14 of 17

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

http://help.autodesk.com/cloudhelp/2014/ENU/Inventor/files/GUID-DA0F4988-AE08-4791-83E5-F9D41B82D4F6...

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

Message 15 of 17

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 -

 

 

Message 16 of 17

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

Message 17 of 17

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", "-"} 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums