Save part and use selected case and length as extension

Save part and use selected case and length as extension

J.VandeMerckt
Advocate Advocate
767 Views
16 Replies
Message 1 of 17

Save part and use selected case and length as extension

J.VandeMerckt
Advocate
Advocate

Hi Forum

 

I have a part file where I can change the length of a part.
The part also has a simple iLogic code with different cases. The cases select what extrusions should be active or suppressed.

I want to make a Form where I choose the length and Case.
Then be able to press save (save as), The length and selected case should be used as a extensions behind the original file name.

 

 

I don't think this should be a complicated code but I'm very new to Ilogic.

 

This is the code I use to Select the case:

	        Feature.IsActive("Ø200 CONT") = False
			Feature.IsActive("Ø200 DOWN") = False
			Feature.IsActive("Ø200 UP") = False
			Feature.IsActive("Ø250 CONT") = False
			Feature.IsActive("Ø250 DOWN") = False
			Feature.IsActive("Ø250 UP") = False
			
			
			Select Case FixedUnit_Curve
	
        Case "Ø200 CONT"
            Feature.IsActive("Ø200 CONT") = True

        Case "Ø200 DOWN"
			Feature.IsActive("Ø200 DOWN") = True
			
        Case "Ø200 UP"
			Feature.IsActive("Ø200 UP") = True
			
        Case "Ø250 CONT"
			Feature.IsActive("Ø250 CONT") = True
			
        Case "Ø250 DOWN"
			Feature.IsActive("Ø250 DOWN") = True
			
        Case "Ø250 UP"
			Feature.IsActive("Ø250 UP") = True
			
		End Select
		iLogicVb.UpdateWhenDone = True

I use this code to open the form when opening the file.

iLogicForm.Show("Fixed Unit Curve and Length")

Let me know if you guys need anymore info!

Thanks 🙂

 

0 Likes
Accepted solutions (1)
768 Views
16 Replies
Replies (16)
Message 2 of 17

richterBKSAC
Advocate
Advocate
Accepted solution

Hi there,

 

I would try the following:

Dim currentfilename As String
Dim choice As String
Dim length As String


currentfilename = ThisDoc.FileName(False)

choice = Parameter("FixedUnit_Curve")
length = Parameter("length")

'custom filepath
'SetTheFilePathHere = "C:\ ... your filepath ..."

'filepath same as the current ipt
SetTheFilePathHere = ThisDoc.Path

SetTheFilenameHere = currentfilename & " " & choice & " " & length


ThisApplication.CommandManager.PostPrivateEvent(kFileNameEvent, SetTheFilePathHere &"\" & SetTheFilenameHere & ".ipt")

Dim oCtrlDef
oCtrlDef = ThisApplication.CommandManager.ControlDefinitions.Item("AppFileSaveCopyAsCmd")
oCtrlDef.Execute

I assume that you are using a custom Parameter for the length as well? If that's the case you have to edit the parameter name in Line 9 to the one you are using.

Let me know if it worked 🙂

 

Message 3 of 17

J.VandeMerckt
Advocate
Advocate
Hi Richter

Thank you very much, due to holiday and a busy schedule I will be able to try it next week.
But I'll definitely let you know if the code works.
0 Likes
Message 4 of 17

J.VandeMerckt
Advocate
Advocate

Hi Richter

 

It works as intended! Beautiful!
Now I would like that the new file is checked into Vault.
Do you know any code to make this happen?

This way we can use the files without having to open them and checking them in manually.

 

BR

Justin

 

here is the coded which I changed very little to make it work.

 

Dim currentfilename As String
Dim choice As String
Dim length As String


currentfilename = ThisDoc.FileName(False)

choice = Parameter("FixedUnit_Curve")
length = Parameter("FixedUnit_Length")

'custom filepath
'SetTheFilePathHere = "C:\ ... your filepath ..."

'filepath same as the current ipt
SetTheFilePathHere = ThisDoc.Path

SetTheFilenameHere = currentfilename & " - " & choice & " - L" & length & "mm"


ThisApplication.CommandManager.PostPrivateEvent(kFileNameEvent, SetTheFilePathHere &"\" & SetTheFilenameHere & ".ipt")

Dim oCtrlDef
oCtrlDef = ThisApplication.CommandManager.ControlDefinitions.Item("AppFileSaveCopyAsCmd")
oCtrlDef.ExecuteH   

 

0 Likes
Message 5 of 17

richterBKSAC
Advocate
Advocate

Hey Justin,

 

I'm glad it worked.

Unfortunately I don't know how to do this yet, but my guess is that you need to program this kind of routine on the Vault level.

If you happen to solve your problem, I'd be interested to know how you did it. 

 

cheers 

Matthias

0 Likes
Message 6 of 17

J.VandeMerckt
Advocate
Advocate

Hi

I'll try to look into it.
Could you also explain how these lines of code work? Trying to grasp a bit better what I'm doing.
(explain it like I'm five) 

ThisApplication.CommandManager.PostPrivateEvent(kFileNameEvent, SetTheFilePathHere &"\" & SetTheFilenameHere & ".ipt")

Dim oCtrlDef
oCtrlDef = ThisApplication.CommandManager.ControlDefinitions.Item("AppFileSaveCopyAsCmd")
oCtrlDef.Execute

 I'll also put this post on Solved. Since my original question has thus been solved.

0 Likes
Message 7 of 17

richterBKSAC
Advocate
Advocate

Hi,

in case you didn't know there is a programing/API-help inside inventor.

You can get to it by opening the dropdown menu next to the question mark in the upper right corner of inventor.

Then you select "help" -> "programing/API-help".

 

When you search for "postprivateevent" you get more information about the method.

 

"Method that posts data onto Autodesk Inventor's internal clipboard. Certain commands that usually obtain information using a dialog, i.e. Open, Save, etc., look first to see if data is on the clipboard before displaying the dialog. If valid information is on the clipboard the command will use it instead of displaying the dialog and asking the user to specify the filename."

 

So basically you post all the required data for the save command to the internal clipboard and then call the save command.

 

Which also helped me a lot to better understand the internal mechanisms of the api is the macro/vba environment (hit Alt+F11 in inventor).

In case you don't know, here is how I do it.

Open the VBA environment with ALT+F11. Create a new modul and insert the following code:

Sub Dokument()
    Dim Dok
    Set Dok = ThisApplication
End Sub

Then click left to "End" so a red dot appears and the line is also highlighted in red.

Right click on "ThisApplication" and add a monitoring (I'm not sure which word is the correct translation)

Ok the window poping up and keep the new bigger "monitoring" window open.

Then hit F5 to start. 

Now you can browse the internal tree of inventor in the monitoring window.

Hopefully you could understand what I was trying to explain 😛

VBA-1.pngVBA-2.png

 

Message 8 of 17

J.VandeMerckt
Advocate
Advocate
Hi

Thank you for walking me through everything.
I'll try to use your tips in the future!
0 Likes
Message 9 of 17

richterBKSAC
Advocate
Advocate

Hi,

 

you're welcome 😉 Glad I could help.

0 Likes
Message 10 of 17

J.VandeMerckt
Advocate
Advocate
Hi Richter

Does the monitor show life what I'm doing in inventor?
Or just all the commands of inventor in general.
0 Likes
Message 11 of 17

richterBKSAC
Advocate
Advocate
Hey,
it's not live but a snapshot of Inventor when you hit F5. For example if you select anything in Inventor and start monitoring you can see the current selection.
Message 12 of 17

J.VandeMerckt
Advocate
Advocate
Aha that is very interesting indeed.
And it works all the time in inventor? Also when making drawings or assemblies and such.
0 Likes
Message 13 of 17

richterBKSAC
Advocate
Advocate
It does to my knowledge. At least I didn't come across any situation where it hasn't worked.
0 Likes
Message 14 of 17

J.VandeMerckt
Advocate
Advocate
Ok I suppose I just have to try it out..
0 Likes
Message 15 of 17

richterBKSAC
Advocate
Advocate
You can't break anything by trying and exploring the tree. It's quite overwhelming at the beginning but in my opinion it helps a lot to better understand what you are doing with ilogic and what also might be possible.
0 Likes
Message 16 of 17

J.VandeMerckt
Advocate
Advocate
Sounds good. I'll definitely use it.
Btw. Do you think it's possible to put this part in a assembly. and use the configurator there.
The tricky part is that I need the original part to be replaced with the renamed part.

This is actually my goal to have a configurable assembly.
I thought it was a good place to start with the part.
0 Likes
Message 17 of 17

richterBKSAC
Advocate
Advocate
I'd say it's possible although I don't have any idea how to do it at the moment.
Did you try a custom iPart, maybe it's a viable solution as well.
0 Likes