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: 

parameter extraction

26 REPLIES 26
Reply
Message 1 of 27
Anonymous
1141 Views, 26 Replies

parameter extraction

Hi all,

 

For a project of mine i want to export a variable parameter lets Call this X but this parameter is dependent of the Plane called Y_layer.

So when te the plane Y_layer moves 1mm the variable X changes the value of X needs to be exported in an excell file. When the Y_layer moves again 1 mm then the value of X changes and that value needs to be written in another excell cell. when the Y_layer moves again the value of X changes and needs to be written in a new cell. 

 

Could someone help me please

 

I use inventor 2017

 

Greetz Lowie

26 REPLIES 26
Message 2 of 27
asiteur
in reply to: Anonymous

Hi,

 

This reminds me of a question I answered a few days ago:

 

https://forums.autodesk.com/t5/inventor-forum/export-a-changing-parameter-in-different-excel-cells/m...

 

Have a look at this, try somethings and then get back if you need more information!



Alexander Siteur
Project Engineer at MARIN | NL
LinkedIn

Message 3 of 27
Anonymous
in reply to: asiteur

hi well it was a bit help full but im stuck i think i need two loops 

1 that moves the Y_layer

and a second to export the data.

 

But the loop you gave doesnt realy work when i use it it writes the last value in all the excel cells. So i made a block like in that example from the link.

when the value changes from 0 to 100mm it has to write in each step of 10 mm the value in an excell cel the problem is that when it reaches 100 it should have written in excel A1= 10 A2= 20 A3=30 A4=40 A5= 50 A6=60 A7=70 A8=80 A9=90 A10=100 but instead it writes A1= 100 A2= 100 A3=100 A4=100 A5= 100 A6=100 A7=100 A8=100 A9=100 A10=100.

 

 

Message 4 of 27
asiteur
in reply to: Anonymous

Hi,

 

You are right, I forgot about that.

The problem I faced in answering the question, just I have with you, is that you don't tell how Y updates. That's why I gave all the ingredients to the solution, but couldn't provide the worryfree code.

 

Example 1:

X = Y * 10  (X is a function of Y) AND

Y = [1,2,3,4,5,6..] (a fixed set of values)

 

Then put both in the loop, update Y, update the document and export X.

 

Example 2:

X = Y * 10

Y = Manual input OR Area/param1*param2 (depending on all kinds of things which may not have direct parameterized input)

 

Then forget about the loop, make a TextParameter that you set to A1 and update after each iteration to A2, A3 etc.

 

So if you can tell me how you want to use it, then I can provide a code that suits your needs.



Alexander Siteur
Project Engineer at MARIN | NL
LinkedIn

Message 5 of 27
Anonymous
in reply to: asiteur

I made picture of my project.

 

The figure is diamond shaped.

What happens is the yellow plane called Y_Layer moves back and forward and makes an intersection with the edges of the diamond shaped figure those points have an X and Y coord when the Hight moves up the Xcoord changes. what i want is that the X and Y coord automaticaly is written to excel and in different cells when the hight changes but when the hight changes the Y_layer has to move back and or forwards. So wen the hight is set to 1 mm the Y_layer wil move 1mm and store that X and Y coord than the Y_layer moves another 1mm writes the X and Y coord in another cell and so on. Then the hight changes and the Y_layer moves again 1mm from its start point and does the whole thing again you call its a bit like slicing.

 

i made a video of what i want

  the Y_layer would move in passes of 1mm given in by the user.

greetz

Message 6 of 27
asiteur
in reply to: Anonymous

Hi,

 

First define a User Parameter Row_number=1 (first value)

 

Make an ilogic rule like this, should be straight forward:

 

 

'Define the excel columns A to D to write to:
Cell_X1="A" & Row_number
Cell_X2="B" & Row_number
Cell_Y1="C" & Row_number
Cell_Y2="D" & Row_number

'Write the values
GoExcel.CellValues(File, "Blad1", "Cell_X1") = X_Afstand_1_Ruit
GoExcel.CellValues(File, "Blad1", "Cell_X2") = X_Afstand_2_Ruit
GoExcel.CellValues(File, "Blad1", "Cell_Y1") = Y_Afstand_1_Ruit
GoExcel.CellValues(File, "Blad1", "Cell_Y2") = Y_Afstand_2_Ruit

'Update the rownumber such that next time you write to the next row
Row_no=Row_no+1

 

 

Now when a variable in the rule changes, here X_Afstand for example, the rule is triggered so it writes the values to Excel.

 

To be honest I didn't test this, so there might be a small issue running it like this.

 

Let me know how it goes.



Alexander Siteur
Project Engineer at MARIN | NL
LinkedIn

Message 7 of 27
Anonymous
in reply to: asiteur

Ok thx i will try and let u know if run in to any problems

Message 8 of 27
Anonymous
in reply to: asiteur

Hi,

 

 

I tried it and it works partialy it writes the value in the cell but each time a value changes it opens a new excel file so when the X_afstand changes 5 times i have 5 different excell files.

 

I made a picture of what the excell file looks like

 

greetz

Message 9 of 27
asiteur
in reply to: Anonymous

Hi,

 

I made some updates to the code. I realized there were some issues. In order for this to work make sure that the excel sheet behind "FILE" exists.

The Save and close commands are there such that you will be able to see the results whenever you want.

 

File="C:\Users\asiteur\Desktop\TESTEXCEL.xlsx"

'Define the excel columns A to D to write to:
Cell_X1="A" & Row_number
Cell_X2="B" & Row_number
Cell_Y1="C" & Row_number
Cell_Y2="D" & Row_number

MsgBox("Exporting data to: " + File + " Row number: " + CStr(Row_number))

'Write the values
GoExcel.CellValue(File, "Sheet1", Cell_X1) = X_Afstand_1_Ruit
GoExcel.CellValue(File, "Sheet1", Cell_X2) = X_Afstand_2_Ruit
GoExcel.CellValue(File, "Sheet1", Cell_Y1) = Y_Afstand_1_Ruit
GoExcel.CellValue(File, "Sheet1", Cell_Y2) = Y_Afstand_2_Ruit

GoExcel.Save
GoExcel.Close


'Update the rownumber such that next time you write to the next row
Row_number=Row_number+1


Alexander Siteur
Project Engineer at MARIN | NL
LinkedIn

Message 10 of 27
Anonymous
in reply to: asiteur

thanks

 

I will try it and let you know and also thx for the fast response

 

greetz

Message 11 of 27
Anonymous
in reply to: Anonymous

Hi, 

 

I tried the code you gave but it only worked for 1 value so i modified the code a bit. Now it writes for each value in the designated folder thats ment for it.

SyntaxEditor Code Snippet

'Define the excel columns A to D to write to:
Cell_X1="A" & Row_no
Cell_X2="B" & Row_no
Cell_Y1="C" & Row_no
Cell_Y2="D" & Row_no

'Write the values
GoExcel.Open("C:\Users\lowie\Documents\Inventor\X1.xls", "Blad1")
GoExcel.CellValue("C:\Users\lowie\Documents\Inventor\X1.xls", "Blad1", Cell_X1) = X_Afstand_1_Ruit
GoExcel.Save
GoExcel.Close

GoExcel.Open("C:\Users\lowie\Documents\Inventor\X2.xls", "Blad1")
GoExcel.CellValue("C:\Users\lowie\Documents\Inventor\X2.xls", "Blad1", Cell_X2) = X_Afstand_2_Ruit
GoExcel.Save
GoExcel.Close

GoExcel.Open("C:\Users\lowie\Documents\Inventor\Y1.xls", "Blad1")
GoExcel.CellValue("C:\Users\lowie\Documents\Inventor\Y1.xls", "Blad1", Cell_Y1) = Y_Afstand_1_Ruit
GoExcel.Save
GoExcel.Close

GoExcel.Open("C:\Users\lowie\Documents\Inventor\Y1.xls", "Blad1")
GoExcel.CellValue("C:\Users\lowie\Documents\Inventor\Y1.xls", "Blad1", Cell_Y2) = Y_Afstand_2_Ruit
GoExcel.Save
GoExcel.Close

Row_no= Row_no+1

But can it be done so when i press a button or something that the y_layer automaticly moves over a defined distance with pases that also are defined im not good with coding so i thought maybe you could help me?

 

Thanks again 

Message 12 of 27
asiteur
in reply to: Anonymous

Hi,

 

It was never clear to me that you wanted to write the values to different excel files. Beaware btw that you are writing Y2 to Y1.xls in your script.

 

Well, you can define a list in iLogic (not a multivalue list because they are annoying) in which you document the steps. You could start with a 0 step such that the initial Afstand is also used.

 

 

myStepList={1,3,10} 

Afstand=Afstand + myStepList(Row_no-1)

This example would add the step to "Afstand" and then keep adding (afstand= initial Afstand + 1+3+10). Put this is a separate rule which you surpress (such that it doesn't run automatically)

 

You could make an iLOgic form with a button that runs this rule.

 

Because Afstand makes changes to 'X1' etc that rule will be triggered

 



Alexander Siteur
Project Engineer at MARIN | NL
LinkedIn

Message 13 of 27
Anonymous
in reply to: asiteur

I tried it but with a while loop.

when afstand tot center is lower then 7.10 then the loop will add 0.5 to its value.

But in excell it writes the same value in all the cells.

I added a picture of the excel file of X1 for the others its the same

 

I use a start button to trigger the loop.

 

SyntaxEditor Code Snippet

If Start= True Then 
While Afstand_tot_center_Ruit < 7.10
Afstand_tot_center_Ruit= Afstand_tot_center_Ruit+0.5

'Define the excel columns A to D to write to:
Cell_X1="A" & Row_no
Cell_X2="B" & Row_no
Cell_Y1="C" & Row_no
Cell_Y2="D" & Row_no
Cell_H1="E" & Row_no
Cell_H2="F" & Row_no

'Write the values
GoExcel.Open("C:\Users\lowie\Documents\Inventor\laser_cladder_Lowie\X1.xls", "Blad1")
GoExcel.CellValue("C:\Users\lowie\Documents\Inventor\laser_cladder_Lowie\X1.xls", "Blad1", Cell_X1) = X_Afstand_1_Ruit
GoExcel.Save
GoExcel.Close

GoExcel.Open("C:\Users\lowie\Documents\Inventor\laser_cladder_Lowie\X2.xls", "Blad1")
GoExcel.CellValue("C:\Users\lowie\Documents\Inventor\laser_cladder_Lowie\X2.xls", "Blad1", Cell_X2) = X_Afstand_2_Ruit
GoExcel.Save
GoExcel.Close

GoExcel.Open("C:\Users\lowie\Documents\Inventor\laser_cladder_Lowie\Y1.xls", "Blad1")
GoExcel.CellValue("C:\Users\lowie\Documents\Inventor\laser_cladder_Lowie\Y1.xls", "Blad1", Cell_H1) = Y_Afstand_1_Ruit
GoExcel.Save
GoExcel.Close

GoExcel.Open("C:\Users\lowie\Documents\Inventor\laser_cladder_Lowie\Y2.xls", "Blad1")
GoExcel.CellValue("C:\Users\lowie\Documents\Inventor\laser_cladder_Lowie\Y2.xls", "Blad1", Cell_H2) = Y_Afstand_2_Ruit
GoExcel.Save
GoExcel.Close

GoExcel.Open("C:\Users\lowie\Documents\Inventor\laser_cladder_Lowie\Hoek_1.xls", "Blad1")
GoExcel.CellValue("C:\Users\lowie\Documents\Inventor\laser_cladder_Lowie\Hoek_1.xls", "Blad1", Cell_Y2) = Hoek_1_Ruit
GoExcel.Save
GoExcel.Close

GoExcel.Open("C:\Users\lowie\Documents\Inventor\laser_cladder_Lowie\Hoek_2.xls", "Blad1")
GoExcel.CellValue("C:\Users\lowie\Documents\Inventor\laser_cladder_Lowie\Hoek_2.xls", "Blad1", Cell_Y2) = Hoek_2_Ruit
GoExcel.Save
GoExcel.Close
Row_no= Row_no+1
End While
End If

 

Message 14 of 27
asiteur
in reply to: Anonymous

Hi,

 

You have a valid point there, it doesn't work as I would expect.

 

First when you do something like this add a document update within your loop:

 

InventorVb.DocumentUpdate()

Otherwise the parameters will only update after the last iteration.

 

But then still it doens't write the values properly.

I'm not sure why, but it does work when you get rid of all the Open, Save, and Close commands. (It makes you code 100 times faster too)

 

You can save and close at the end of the code to save the excelsheet once.

 

Best,

 

Alexander



Alexander Siteur
Project Engineer at MARIN | NL
LinkedIn

Message 15 of 27
Anonymous
in reply to: asiteur

Is this the correct way to use  ? Inventorvb.documentupdate( )

If Start= True Then 

Do While Afstand_tot_center_Ruit <5
Afstand_tot_center_Ruit= Afstand_tot_center_Ruit+0.5

'Define the excel columns A to D to write to:
Cell_X1="A" & Row_no
Cell_X2="B" & Row_no
Cell_Y1="C" & Row_no
Cell_Y2="D" & Row_no
Cell_H1="E" & Row_no
Cell_H2="F" & Row_no

'Write the values
GoExcel.CellValue("C:\Users\lowie\Documents\Inventor\laser_cladder_Lowie\X1.xls", "Blad1", Cell_X1) = X_Afstand_1_Ruit
InventorVb.DocumentUpdate(True)


GoExcel.CellValue("C:\Users\lowie\Documents\Inventor\laser_cladder_Lowie\X2.xls", "Blad1", Cell_X2) = X_Afstand_2_Ruit
InventorVb.DocumentUpdate(True)


GoExcel.CellValue("C:\Users\lowie\Documents\Inventor\laser_cladder_Lowie\Y1.xls", "Blad1", Cell_H1) = Y_Afstand_1_Ruit
InventorVb.DocumentUpdate(True)



GoExcel.CellValue("C:\Users\lowie\Documents\Inventor\laser_cladder_Lowie\Y2.xls", "Blad1", Cell_H2) = Y_Afstand_2_Ruit
InventorVb.DocumentUpdate(True)


GoExcel.CellValue("C:\Users\lowie\Documents\Inventor\laser_cladder_Lowie\Hoek_1.xls", "Blad1", Cell_Y2) = Hoek_1_Ruit
InventorVb.DocumentUpdate(True)


GoExcel.CellValue("C:\Users\lowie\Documents\Inventor\laser_cladder_Lowie\Hoek_2.xls", "Blad1", Cell_Y2) = Hoek_2_Ruit
InventorVb.DocumentUpdate(True)
Row_no= Row_no+1

Loop
End If

 

Message 16 of 27
asiteur
in reply to: Anonymous

No,

 

The update command updates the Inventor Document, it's the exact same thing as the yellow lightning button in the top menu in Inventor.

 

What you do now makes no sense ,you do an update after making no changes to the document, which is just a waste of time and coding.

 

Typically you need 1 update command per rule.

 

You only need to ask yourself, when do I need to update this document. Well probably, after the afstand=afstand+0.5 line, and BEFORE the construction of the Cell identifiers.

 

 

 



Alexander Siteur
Project Engineer at MARIN | NL
LinkedIn

Message 17 of 27
Anonymous
in reply to: asiteur

Hi,

 

Well i tried it but doesn"t seem to work. 😞

I have put my inventor pat in attachement incase i maybe could help you.

To use You have to klik on form Keuze figuur and then select ruit and then the form for ruit shows up.

the problem we are talking about you can find it in the rule on the bottom of the page.

SyntaxEditor Code Snippet

If Start= True Then 

Do While Afstand_tot_center_Ruit <5
Afstand_tot_center_Ruit= Afstand_tot_center_Ruit+0.5
InventorVb.DocumentUpdate(True)

'Define the excel columns A to D to write to:
Cell_X1="A" & Row_no
Cell_X2="B" & Row_no
Cell_Y1="C" & Row_no
Cell_Y2="D" & Row_no
Cell_H1="E" & Row_no
Cell_H2="F" & Row_no

'Write the values
GoExcel.Open("C:\Users\lowie\Documents\Inventor\laser_cladder_Lowie\X1.xls", "Blad1")
GoExcel.CellValue("C:\Users\lowie\Documents\Inventor\laser_cladder_Lowie\X1.xls", "Blad1", Cell_X1) = X_Afstand_1_Ruit
GoExcel.Save
GoExcel.Close

GoExcel.Open("C:\Users\lowie\Documents\Inventor\laser_cladder_Lowie\X2.xls", "Blad1")
GoExcel.CellValue("C:\Users\lowie\Documents\Inventor\laser_cladder_Lowie\X2.xls", "Blad1", Cell_X2) = X_Afstand_2_Ruit
GoExcel.Save
GoExcel.Close

GoExcel.Open("C:\Users\lowie\Documents\Inventor\laser_cladder_Lowie\Y1.xls", "Blad1")
GoExcel.CellValue("C:\Users\lowie\Documents\Inventor\laser_cladder_Lowie\Y1.xls", "Blad1", Cell_Y1) = Y_Afstand_1_Ruit
GoExcel.Save
GoExcel.Close

GoExcel.Open("C:\Users\lowie\Documents\Inventor\laser_cladder_Lowie\Y2.xls", "Blad1")
GoExcel.CellValue("C:\Users\lowie\Documents\Inventor\laser_cladder_Lowie\Y2.xls", "Blad1", Cell_Y2) = Y_Afstand_2_Ruit
GoExcel.Save
GoExcel.Close

GoExcel.Open("C:\Users\lowie\Documents\Inventor\laser_cladder_Lowie\Hoek_1.xls", "Blad1")
GoExcel.CellValue("C:\Users\lowie\Documents\Inventor\laser_cladder_Lowie\Hoek_1.xls", "Blad1", Cell_H1) = Hoek_1_Ruit
GoExcel.Save
GoExcel.Close

GoExcel.Open("C:\Users\lowie\Documents\Inventor\laser_cladder_Lowie\Hoek_2.xls", "Blad1")
GoExcel.CellValue("C:\Users\lowie\Documents\Inventor\laser_cladder_Lowie\Hoek_2.xls", "Blad1", Cell_H2) = Hoek_2_Ruit
GoExcel.Save
GoExcel.Close
Row_no= Row_no+1
Loop
End If

 

 

Message 18 of 27
asiteur
in reply to: Anonymous

Hi,

 

Oke well there is a dozen of things that I don't understand why you are working like this.

 

First and probably most importantly: get the export to excel part of the rule in a separate rule. Now you trigger everything over and over again.

 

2) Then get the Open close and Save commands out as I said,

3) Put the document update in properly

 

Then if  that doesn't work:

4) why have you linked the excelsheets? There is no need to do this and I would suspect it to do more wrong than right

 

Ultimately if you could make a screencast of what's happening that would 'boekdelen spreken' probably.

 

Best,

 

Alexander



Alexander Siteur
Project Engineer at MARIN | NL
LinkedIn

Message 19 of 27
Anonymous
in reply to: asiteur

Hi so i did what you told me.

 

1) Made a new rule with the excel code.

 

2) Getting rid of the open close and save command.

 

  -I did the code whit the open, close and save commands because when i didn't do it i've got some msgboxes that tel me that the file X1 ect is already open and when the code is done i have to save manualy and when i open excel i see that there is only value has been written to my excel.

 

 

3)I've put the update command where i think it should be good.

 

4)I deleted the excell links in the parameter menu.

 

5)In attachement you will find a small movie of my program showing my code ect.

 

Greetings

 

 

My new code 

 

 

SyntaxEditor Code Snippet

If Start= True Then 

Do While Afstand_tot_center_Ruit <5
Afstand_tot_center_Ruit= Afstand_tot_center_Ruit+0.5
InventorVb.DocumentUpdate(True)

'Define the excel columns A to D to write to:
Cell_X1="A" & Row_no
Cell_X2="B" & Row_no
Cell_Y1="C" & Row_no
Cell_Y2="D" & Row_no
Cell_H1="E" & Row_no
Cell_H2="F" & Row_no

'Write the values

GoExcel.CellValue("C:\Users\lowie\Documents\Inventor\laser_cladder_Lowie\X1.xls", "Blad1", Cell_X1) = X_Afstand_1_Ruit

GoExcel.CellValue("C:\Users\lowie\Documents\Inventor\laser_cladder_Lowie\X2.xls", "Blad1", Cell_X2) = X_Afstand_2_Ruit

GoExcel.CellValue("C:\Users\lowie\Documents\Inventor\laser_cladder_Lowie\Y1.xls", "Blad1", Cell_Y1) = Y_Afstand_1_Ruit

GoExcel.CellValue("C:\Users\lowie\Documents\Inventor\laser_cladder_Lowie\Y2.xls", "Blad1", Cell_Y2) = Y_Afstand_2_Ruit

GoExcel.CellValue("C:\Users\lowie\Documents\Inventor\laser_cladder_Lowie\Hoek_1.xls", "Blad1", Cell_H1) = Hoek_1_Ruit

GoExcel.CellValue("C:\Users\lowie\Documents\Inventor\laser_cladder_Lowie\Hoek_2.xls", "Blad1", Cell_H2) = Hoek_2_Ruit

Row_no= Row_no+1
Loop
End If
Message 20 of 27
asiteur
in reply to: Anonymous

Hi,

 

Thank you for taking the time to make the screencast.

 

Oke I understand your problem. I wasn't aware of this issue because the 'excel already open'-message doesn't appear on my system, that might be due to the version of excel you are running or a setting somewhere. Regardless you should be able to run your rule properly. For next time, whenever you add something to your code that wasn't asked or even advised against, explain clearly what made you do so.

 

What we are encountering here is a limitation to iLogic, in the sense that you cannot control the excel instance you open using these snippets. In a normal programcode you can use a handle on a program instance such that handleonexcel.close() would close this specific instance. Now what you are doing in excel is always closing the last openend.

 

Slowly we are getting to what I think is the issue: the first 'Open' command, because you open the excelsheet first and then the next statement ALSO opens the sheet. Then you only close the last one such that you get an enormous amount of warnings.

 

You should also reset your 'row_number' parameter sometimes otherewise you'll have to scroll more and more in your sheet.

 

 

So what I think you should do:

1) Strip the 'Open'commands out

2) LEAVE the close and save commands

 

For me (again) this works. If you have trouble doing it like this, I'm really running out of ideas on how to get this right.



Alexander Siteur
Project Engineer at MARIN | NL
LinkedIn

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

Post to forums  

Autodesk Design & Make Report