PowerMill macros with variables

PowerMill macros with variables

Anonymous
Not applicable
7,612 Views
27 Replies
Message 1 of 28

PowerMill macros with variables

Anonymous
Not applicable

Hello everyone 🙂

I‘m from Germany so I hope you‘ll understand me as good as you can.

 

I have to work with 5 models in my project which are everyday the same. Different in a small way.. But everytime the same steps. The only difference is, that the number of the 5 models is everyday another one, eg: 

17171010_I.        —> 18181010_I

17171010_ISh     —> 18181010_ISh

17171010_IE       —> 18181010_IE

17171010_IOSur —> 18181010_IOSur

17171010_ISUR  —> 18181010_ISur

 

I can use macros for lots of operations now. But when I have to say: turn 18181010_I, 18181010_ISh (...) by 180 degrees or something like this. There is no way to use macros for me. But that would be so helpfull! I get a xsml file with my models everyday  where are the filenames included. The name of the xsml file and the sequence are always the same.

So is there any way to use macros with Variables? I saw this video but I don‘t understand how to manage it...

https://youtu.be/zqtqQ37VCH4

 

So if there‘s anybody to help me I would be so grateful.

 

regards

David

 

0 Likes
Accepted solutions (2)
7,613 Views
27 Replies
Replies (27)
Message 2 of 28

kukelyk
Advisor
Advisor

Can You upload a sample xsml file?

0 Likes
Message 3 of 28

Anonymous
Not applicable

Hey,

here you have:

 

 

David 🙂

 

0 Likes
Message 4 of 28

kukelyk
Advisor
Advisor

And where are the numbers like 17171010_I :?

0 Likes
Message 5 of 28

Anonymous
Not applicable

Sorry I'm not into XML... I don't know how to create the file correctly so that it reads out the numbers everytime automaticilly..
But do you understand my problem or my way to work with variables in macros?

The XML file is not delivered with the models but the excel as you can see in attachments (Komponententabelle)

 

Thank you very much!!! 

 

David

0 Likes
Message 6 of 28

kukelyk
Advisor
Advisor

So, as I understand:

You have an excel file, and have an xsml file. 

The excel file contains the model names and their function.

the xsml contains the functions and some other data. 

A macro can read the xsml file, but not the excel. (There is an indirect way to read the excel.)

What we need is the excel table data.

 

Afterall, You get the models, the excel and the xsml files. Right?

 

If the xsml has the same data as the excel (in different format), than please upload one of them.

 

0 Likes
Message 7 of 28

Anonymous
Not applicable

First of all thank you at this point for your help! 

 

I get the models and the excel table like: Komponententabelle. 

Is there no way to make out an XML from excel table?

If it's not so easy, I don't know what takes longer... make this xml file for the macros or do a couple of clicks in PowerMill 😄

Nevertheless it would be so great!

 

 

 

David

0 Likes
Message 8 of 28

kukelyk
Advisor
Advisor

OK, the excel looks like the same every time? Does only the rows between 2 and 7 contain component data in the excel file?

If yes, then a small vbs can grab the needed cells.

 

0 Likes
Message 9 of 28

Anonymous
Not applicable

You're right!

The rows between A2 and A7 are different every time. But only the number changes!.

The ending like    _I      _IESur      _IISur     IOSur   (...) are the same every time 🙂

Rows B2 to B7 are only a description to every model.

 

 

 

David

0 Likes
Message 10 of 28

kukelyk
Advisor
Advisor
Accepted solution

save attached files to the same directory, and run the macro (.mac)

after the macro You can reference the variable by their name, ie. $project.gravur

 

Message 11 of 28

Anonymous
Not applicable

Wow! Looks very good. I don‘t exactly understand what you wrote in your files but what stands: FILESELECT "Modell beolvasása.." " for?

of course I will try this tomorrow and let you know whether it worked or not.

one more question if it‘s okay...

 

In which directory do I have to save your files? Once or every time in my new project folder?

Do I have to start the .vba file or just put in folder?

After clicking on your macro in PowerMill I can address every single model by only writing; $project.gravur, $project.IOSur?

a little guide would be the cherry on the cake 🙂

 

Thank you very muchSmiley Happy

 

0 Likes
Message 12 of 28

5axes
Advisor
Advisor

Realy nice code @kukelyk Heart  I vote to elect it code of the month ! Smiley Happy

 

Sample code very usefull, to read directly some data in a Excel file.  

Message 13 of 28

5axes
Advisor
Advisor

Just one question : In the vbs script why do you create the initial DAT file in the C:\temp directory.  And not directly in the script directory ?

 

 

0 Likes
Message 14 of 28

Anonymous
Not applicable

Hello together,

got this error 😞 (attachment)

 

 

0 Likes
Message 15 of 28

5axes
Advisor
Advisor

Well very strange , the error is on the first lines of the code. The exact syntax for this line should be :

 

STRING read_xls_vbs = macro_path(0) + "\read_xls.vbs"

 

but  STRING read_xls_vbs = macro_path() + "\read_xls.vbs" is also correct .

 

I don't now when the function macro_path was introduce in the macro langage, could be the origin of your issue. What is your PowerMill release ?  Is it older than a 2016 release ?

 

 

0 Likes
Message 16 of 28

Anonymous
Not applicable

There are some more errors when I skip the first one but maybe they are caused of the first error so we will work from top to bottom.

 

I use PowerMill Pro 2014 R2.

 

Thank you

0 Likes
Message 17 of 28

5axes
Advisor
Advisor

This is certainly the origin of your issue.  If your read the Macro reference langage it's impossible to know when a new function was introduce in the software.

 

macro_path  was available since 2016 but for 2014 ?  You can try just in the Windows command to run the code :

 

print $macro_path(0) 

 

Should return (null)  if it's not the case then the code is not compatible with your relase. But it's not a big problem in such case just replace :

 

$macro_path(0)   by the path to your file hardcoded  "C:\Users\bahrmannd\Documents\PowerMill Makros Variable\Testumgbung\read_xls.vbs"

 

 

0 Likes
Message 18 of 28

Anonymous
Not applicable

Works with path instead of $macro_path(0)    Smiley Happy

 

But then I get the next error. It reads the tempvbs.vbs file and says he can not fin the file in: row 3, character 1. (see attachment)

0 Likes
Message 19 of 28

5axes
Advisor
Advisor

there is an error in the script \read_xls.vbs is written 2 times .. change STRING read_xls_vbs  to get the correct path

 

Fehlermeldung1.JPG

0 Likes
Message 20 of 28

Anonymous
Not applicable

the tempvbs.vbs is genrated new every time I click the macro. So I don't have to change the tempvbs file but which one?

There must be a command which generates the tempvbs.vbs, am I right?

 

I hope you understand what I mean Smiley Very Happy

0 Likes