cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

Can you pass parameters to a macro

TimSharp
12-Amethyst

Can you pass parameters to a macro

I'm used to a different macro programming language in which you can have 1 macro do several different things by passing parameter(s) along with the macro name - e.g. macro_name 'yes' The macro then declares the parameter(s) e.g. parameter yes_no The parameter yes_no is then a variable yes_no with a value of 'yes' The macro then uses this variable to determine an action later on. For example, I have a macro that changes a drawing and saves it down again, but I now find I want a very similar macro that does everything except save the drawing down again. With a parameter, I could include an if statement in the macro to either save the drawing or not depending on the value of the parameter. Otherwise I will have to either copy the macro twice or split it into bits and run as separate macros Is there something similar to this in Isodraw? I have looked but can't find anything, though the terminology may be different.
15 REPLIES 15

I'm not sure how you are planning to specify the parameter. My approach is to basically break it apart as you mention. It can be done at a high level though. Have a global variable that is set and then basically three macros. 1) Your main macro with the addition of an "if" statement surrounding your save down coding. For our purposes let's refer to this as a submacro called "Change_and_Maybe_Save_Down" (long, but descriptive). 2 & 3) Something similar to this...
209c292858
and then another such as...
209c292858
Then just check the value of this variable in your if statement used in Change_and_Maybe_Save_Down.

Yes this is a good way of doing it. A global variable will do the same job as a parameter. Unfortunately I always compare things to ME10 and try to do things a similar way - I programmed ME10 for over 20 years so it's ingrained!

In IsoDraw 7.1 you can pass parameters to submacros like this:

SubMacro Change_drawing( Boolean save_down )
If ( save_down ) Then
# Change and Save Down ...
Else
# Change only ...
End If
End SubMacro

Macro Test_Change_drawing
Run Change_drawing( true )
# or
Run Change_drawing( false )
End Macro

There are 2 parts to this question. 1. When you create a global variable, is there a way to set a value to it like you can with variables set within macros? The example below gives an error global move_dist as float #This bit's OK move_dist = 100 #causes Invalid Macro File error It works fine of course if it's within a macro in the macro file, but in this case I want the macro created and the value set when the macro file is loaded, not when a macro is run. 2. If it's possible to set a global variable's value, is it then possible to use this value as a default in a get string? example move_dist = get string "Enter distance to move" But instead of popping up the value 0 in the input window, have it use whatever value is currently set for the variable move_dist?

In regards to #1, my method is to have a separate macro to set all my global variables. I just call it at the start of any macro that uses those variables. Not as handy as what you're asking, but it works.

Yes of course I remember doing that in past, I forgot the simple obvious - thanks.

Forgot to mention what I was told in regards to #2. I had asked a similar question. I was told that there was no way to pre-fill a get statement as a default. I'm going out on a limb, but I doubt that changes in the 7.1 release.

Again thanks. I thought it would have been documented if it was available. I guess the macro language was never intended to be comprehensive, hence the omission of so many features that I've taken for granted, such as being able to create screen menus to set/choose values before running a macro.

Hi,

Actually I have two problems about this topic :

- First, I can't see the code examples quoted in this topic, all I can see is :

In IsoDraw 7.1 you can pass parameters to submacros like this:

d008373291

- Next, I really need to pass parameters to a macro, but in a command line like this :

C:\Program Files\PTC\Arbortext IsoDraw 7.1\Program\IsoDraw71.exe file.cgm -macro macroName(parameter)

The PTC support told me that was possible, but they are not able to tell me how to write the macro to get the parameters. I tried several ways :

-> Macro macroName(String param) : I have a 'parameter error ""'
-> Macro macroName(define param as String) : isodraw crashes
-> Macro macroName(param) : isodraw crashes

Can anyone help me, please?

Thanks

Damien

In regards to the code not being visible, it appears that when they updated to this new forum format they lost anything marked as code as well as many of the attachments.

I've attached what I was given from PTC support about running from the cmd line. I've used it quite a bit, but don't recall anything showing the possibility of specifying a parameter. Can you explain what you are attempting to do in more detail? The more specific, the better.

First of all, thank you for your instant answer!

About the code quotes, I already had your embeded text file from PTC support, but thank you.

Here are my needs:

- Open automatically a lot of cgm files (more than 2000)

- Create several active areas in each cgm files at some exact places defined in an other file.

- Save each cgm file

I tried several ways to reach my needs :

- I found a way in this forum to read a text file in a variable and so get the information about the active areas. But Isodraw is not enough robust to bear so much charge. I had some random bad behaviour, with or without the collection treatment.

- Now, I'm making a java program which will read the information about the active areas and I would like to launch from this Java program, a macro having as parameter the information about the active area and let Isodraw do only its job : create the active area.

- Waiting for an answer about parameters, I'm trying to create from my java program a new macro file for each cgm file which will create all the active areas, and launch it.

Any idea?

Thanks again.

ps : Benno, I just saw your answer, I think I already tried this solution, it wasn't working. I'll try again to be sure, thanks anyway.

Hi,

I restored the code snipplet above. This:

Macro macroName(String param)

# Do something with param

End Macro

would be the right thing in your case. To resolve the parameter error, check the quotes in the command line.

E.g. this should work:

IsoDraw71.exe file.cgm -macro macroName("ABCD")

Please note that environment variables in the cmd shell are resolved without quotes, so they also need to be quoted,

if you want to pass them as string parameters to a macro:

IsoDraw71.exe file.cgm -macro macroName("%MY_ENVIRONMENTVAR%")

Hi,

Well, my new test seems to work... I'm trying with my whole treatment.

Thank you,

Damien

Hi,

I tried with my whole treatment but I failed 😕

I only used the Isodraw macro to create an active area in a graphic file, so it means a lot of macro calls, between 1 to around 20 for one graphic file, and I have more than 2000 graphic files.

The problem is that Isodraw doesn't manage so many quick macro calls on the same file. Between each active area, I have to save and close the file, to keep the changes, and really soon, Isodraw tells me that the file is still opened. I tried to put a timer between each macro call, but it would need several seconds to let enough time for the treatment, and it's far too much.

I know it would be better to have a macro for a graphic file and not for an active area, but the number of active areas is not fixed. And I would need an array or something like that to pass in parameter to the macro, but I didn't find anything about this in this forum or in the documentation.

You can find attached my Isodraw macro file, my java program and an instance of active area information file (.hts).

Any idea?

Thanks.

Damien

As another approach, you might want to look at using the batch tool that comes with IsoDraw. It allows you to cycle through a folder of files and run a macro on each.

In regards to the macro, reference the alternate forum thread about getting input from an outside file. A generic overview would be something like what follows:

1) When each file is opened, a macro is run.

2) Text element is created and mock text excerpt is created.

3) The macro loops calling out a batch/java file giving the name of the hts file needed for input as well as a line number (loop in IsoDraw just keeps adding one to line number each time it processes.

4) Batch/java references that line and updates the text excerpt.

5) IsoDraw import file (pause will be necessary to allow batch/java to run).

6) String is validated (If nul, exit loop. If not nul, continue.)

7) Parse string and create your active area.

😎 Add to line number, export text excerpt...

It wouldn't be terribly fast, but once set up, you could allow it to run overnight.

Announcements

Top Tags