# Macro in another macro

**URL:** <https://root-forum.cern.ch/t/macro-in-another-macro/38279>\
**Category:** Newbie\
**Created:** [March 5, 2020, 2:05pm UTC](https://root-forum.cern.ch/t/macro-in-another-macro/38279 "2020-03-05T14:05:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevinlinxc](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kevinlinxc/32/21030_2.png) [@kevinlinxc](https://root-forum.cern.ch/u/kevinlinxc)\
**Post date:** [March 5, 2020, 2:05pm UTC](https://root-forum.cern.ch/t/macro-in-another-macro/38279/1 "2020-03-05T14:05:29Z")

</div>

Is there a modern way to run a macro from another macro? The search results that come up for this are emails from 2001 and 2003, so I’m hoping there’s a better way now.  
The problem with gROOT-\>ProcessLine(“macro”); is that if I try to pass parameters into the inner macro that were declared in C, root doesn’t recognize them.

_ROOT Version:_ 6.18/04  
_Platform:_ Windows  
_Compiler:_ Not Provided

* * *

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [March 5, 2020, 2:33pm UTC](https://root-forum.cern.ch/t/macro-in-another-macro/38279/2 "2020-03-05T14:33:53Z")

</div>

I guess this is related to the post you did about axis. Answer [the other](https://root-forum.cern.ch/t/graph-with-strings-as-x-axis/38274/2) one with some code and I will see what is wrong.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [March 6, 2020, 3:04pm UTC](https://root-forum.cern.ch/t/macro-in-another-macro/38279/3 "2020-03-06T15:04:42Z")

</div>

what kind of parameter do you want to pass ?

---

<div class="post-metadata">

**Author:** ![kevinlinxc](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kevinlinxc/32/21030_2.png) [@kevinlinxc](https://root-forum.cern.ch/u/kevinlinxc)\
**Post date:** [March 6, 2020, 3:14pm UTC](https://root-forum.cern.ch/t/macro-in-another-macro/38279/4 "2020-03-06T15:14:41Z")

</div>

I will try to explain it clearly, as it is a little bit complicated.  
You gave me a macro to use called GraphDoubleString.C, which took two parameters, a graph and an array of strings.  
If I made a graph and an array on the root command line, and then called

```auto
.x GraphDoubleString.C(gr,colour)

```

I would have no problem. Everything would work as intended. However, if I instead created the double and array in C++, and then tried to call  
`gROOT->ProcessLine(“.x GraphDoubleString.C(gr,colour);")`,  
root will not know what gr and colour are for whatever reason.  
So I’m wondering, is there an alternative way to call macros from C++ that would allow the passing of C++ variables?

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [March 6, 2020, 3:29pm UTC](https://root-forum.cern.ch/t/macro-in-another-macro/38279/5 "2020-03-06T15:29:27Z")

</div>

> [@kevinlinxc](#):
>
> So I’m wondering, is there an alternative way to call macros from C++ that would allow the passing of C++ variables?

Yes it is tricky. See an example here:  
[https://root.cern/doc/master/THistPainter\_8cxx\_source.html#l03376](https://root.cern/doc/master/THistPainter_8cxx_source.html#l03376)
