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

PowerMill macros with variables

27 REPLIES 27
SOLVED
Reply
Message 1 of 28
Anonymous
4467 Views, 27 Replies

PowerMill macros with variables

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

 

27 REPLIES 27
Message 2 of 28
kukelyk
in reply to: Anonymous

Can You upload a sample xsml file?

Message 3 of 28
Anonymous
in reply to: kukelyk

Hey,

here you have:

 

 

David ๐Ÿ™‚

 

Message 4 of 28
kukelyk
in reply to: Anonymous

And where are the numbers like 17171010_I :?

Message 5 of 28
Anonymous
in reply to: kukelyk

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

Message 6 of 28
kukelyk
in reply to: Anonymous

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.

 

Message 7 of 28
Anonymous
in reply to: kukelyk

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

Message 8 of 28
kukelyk
in reply to: Anonymous

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.

 

Message 9 of 28
Anonymous
in reply to: kukelyk

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

Message 10 of 28
kukelyk
in reply to: Anonymous

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
in reply to: kukelyk

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

 

Message 12 of 28
5axes
in reply to: kukelyk

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
in reply to: kukelyk

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 ?

 

 

Message 14 of 28
Anonymous
in reply to: Anonymous

Hello together,

got this error ๐Ÿ˜ž (attachment)

 

 

Message 15 of 28
5axes
in reply to: Anonymous

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 ?

 

 

Message 16 of 28
Anonymous
in reply to: 5axes

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

Message 17 of 28
5axes
in reply to: Anonymous

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"

 

 

Message 18 of 28
Anonymous
in reply to: 5axes

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)

Message 19 of 28
5axes
in reply to: Anonymous

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

Message 20 of 28
Anonymous
in reply to: 5axes

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

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report