GH Filename is Python - Grasshopper2024-03-19T10:28:00Zhttps://www.grasshopper3d.com/forum/topics/gh-filename-is-python?commentId=2985220%3AComment%3A1093760&feed=yes&xn_auth=noThank you David and Giulio!…tag:www.grasshopper3d.com,2014-06-26:2985220:Comment:10940682014-06-26T19:59:01.767ZBrian Ringleyhttps://www.grasshopper3d.com/profile/bringley
<p>Thank you David and Giulio!</p>
<p></p>
<p>Giulio, I started a new forum post with a few follow-up questions here:</p>
<p><a href="http://www.grasshopper3d.com/forum/topics/pulling-grasshopper-metadata-document-properties" target="_blank">http://www.grasshopper3d.com/forum/topics/pulling-grasshopper-metadata-document-properties</a></p>
<p>Thank you David and Giulio!</p>
<p></p>
<p>Giulio, I started a new forum post with a few follow-up questions here:</p>
<p><a href="http://www.grasshopper3d.com/forum/topics/pulling-grasshopper-metadata-document-properties" target="_blank">http://www.grasshopper3d.com/forum/topics/pulling-grasshopper-metadata-document-properties</a></p> Same in Python, following Dav…tag:www.grasshopper3d.com,2014-06-26:2985220:Comment:10937602014-06-26T10:41:17.565ZGiulio Piacentinohttps://www.grasshopper3d.com/profile/GiulioPiacentino
<p>Same in Python, following David's sample.</p>
<p><span>Giulio</span><br/><span>--</span><br/><span>Giulio Piacentino</span><br/><span>for Robert McNeel & Associates</span><br/><span>giulio@mcneel.com</span></p>
<p>Same in Python, following David's sample.</p>
<p><span>Giulio</span><br/><span>--</span><br/><span>Giulio Piacentino</span><br/><span>for Robert McNeel & Associates</span><br/><span>giulio@mcneel.com</span></p> It's not particularly easy, b…tag:www.grasshopper3d.com,2014-06-26:2985220:Comment:10938372014-06-26T09:42:46.508ZDavid Ruttenhttps://www.grasshopper3d.com/profile/DavidRutten
<p>It's not particularly easy, but it is reasonably straightforward. The attached file contains a C# script component which outputs all libraries used in the current file (separated into core and add-on libs).</p>
<p></p>
<p>--</p>
<p>David Rutten</p>
<p>david@mcneel.com</p>
<p>It's not particularly easy, but it is reasonably straightforward. The attached file contains a C# script component which outputs all libraries used in the current file (separated into core and add-on libs).</p>
<p></p>
<p>--</p>
<p>David Rutten</p>
<p>david@mcneel.com</p> Hi Brian,
this post is old; m…tag:www.grasshopper3d.com,2014-06-26:2985220:Comment:10937572014-06-26T09:05:06.698ZGiulio Piacentinohttps://www.grasshopper3d.com/profile/GiulioPiacentino
<p>Hi Brian,</p>
<p>this post is old; maybe may I ask to start a new discussion next time?<br></br>On the part that you wrote, it can slightly be shortened to:</p>
<p>f = ghdoc.Name<br></br>d = ghenv.Component.OnPingDocument().Properties.Description<br></br>a = gh.CentralSettings.AuthorName<br></br>c = ghenv.Component.OnPingDocument().Properties.Date<br></br>p = ghdoc.Path</p>
<p>About i, I would wait for David to tell the right approach, as there might be some Grasshopper-SDK-specific method to query, which I am…</p>
<p>Hi Brian,</p>
<p>this post is old; maybe may I ask to start a new discussion next time?<br/>On the part that you wrote, it can slightly be shortened to:</p>
<p>f = ghdoc.Name<br/>d = ghenv.Component.OnPingDocument().Properties.Description<br/>a = gh.CentralSettings.AuthorName<br/>c = ghenv.Component.OnPingDocument().Properties.Date<br/>p = ghdoc.Path</p>
<p>About i, I would wait for David to tell the right approach, as there might be some Grasshopper-SDK-specific method to query, which I am not aware of. Or maybe we have to just go though all document objects and check if they belong to external libraries. Let's see what David says on this,</p>
<p>Giulio<br/>--<br/>Giulio Piacentino<br/>for Robert McNeel & Associates<br/>giulio@mcneel.com</p> ghenv.LocalScope should be on…tag:www.grasshopper3d.com,2014-06-26:2985220:Comment:10935082014-06-26T08:11:55.928ZGiulio Piacentinohttps://www.grasshopper3d.com/profile/GiulioPiacentino
<p>ghenv.LocalScope should be only used for scope manipulation. Of course, given that it is the local scope, it will contain all variables of it. Including ghenv. So you could write ghenv.LocalScope.ghenv.LocalScope... But please rather use <span>ghdoc.Path :)</span></p>
<p><span>Giulio<br/>--<br/>Giulio Piacentino<br/>for Robert McNeel & Associates<br/>giulio@mcneel.com</span></p>
<p>ghenv.LocalScope should be only used for scope manipulation. Of course, given that it is the local scope, it will contain all variables of it. Including ghenv. So you could write ghenv.LocalScope.ghenv.LocalScope... But please rather use <span>ghdoc.Path :)</span></p>
<p><span>Giulio<br/>--<br/>Giulio Piacentino<br/>for Robert McNeel & Associates<br/>giulio@mcneel.com</span></p> Oh there's an "import Grassho…tag:www.grasshopper3d.com,2014-06-25:2985220:Comment:10934642014-06-25T20:31:09.132ZBrian Ringleyhttps://www.grasshopper3d.com/profile/bringley
<p>Oh there's an "import Grasshopper as gh" in there btw</p>
<p>Oh there's an "import Grasshopper as gh" in there btw</p> Hey d00dz
I'm trying to pull…tag:www.grasshopper3d.com,2014-06-25:2985220:Comment:10936422014-06-25T20:12:16.339ZBrian Ringleyhttps://www.grasshopper3d.com/profile/bringley
<p>Hey d00dz</p>
<p></p>
<p>I'm trying to pull a bunch of metadata from different locations - here's what I've got:</p>
<p></p>
<p>"""Displays document metadata<br></br> Outputs:<br></br> f: file name<br></br> d: document description<br></br> a: file creator<br></br> c: creation date<br></br> p: file path<br></br> r: revision count<br></br> v: Grasshopper version<br></br> l: list of add-ons used<br></br>"""</p>
<p>def Main():<br></br> global f, d, a, c, p, r, v<br></br> f = ghenv.LocalScope.ghdoc.Name<br></br> d =…</p>
<p>Hey d00dz</p>
<p></p>
<p>I'm trying to pull a bunch of metadata from different locations - here's what I've got:</p>
<p></p>
<p>"""Displays document metadata<br/> Outputs:<br/> f: file name<br/> d: document description<br/> a: file creator<br/> c: creation date<br/> p: file path<br/> r: revision count<br/> v: Grasshopper version<br/> l: list of add-ons used<br/>"""</p>
<p>def Main():<br/> global f, d, a, c, p, r, v<br/> f = ghenv.LocalScope.ghdoc.Name<br/> d = ghenv.Component.Attributes.Owner.OnPingDocument().Properties.Description<br/> a = gh.CentralSettings.AuthorName<br/> c = ghenv.Component.Attributes.Owner.OnPingDocument().Properties.Date<br/> p = ghenv.LocalScope.ghdoc.Path<br/> r = ghenv.Component.Attributes.Owner.OnPingDocument().Properties.Revisions.Count<br/> v = gh.Versioning.Version<br/> l = 1</p>
<p>Main()</p>
<p></p>
<p>The first question is that I'm bouncing between gh. and ghenv. for different things - can I/should I be more consistent? Are there consequences?</p>
<p></p>
<p>The second question is that I'm trying to pull the list of add-ons (variable "l") used in a definition. This data exists in the ghXML in the Library chunk:</p>
<p><chunk name="Library" index="0"><br/> <items count="4"><br/> <item name="Author" type_name="gh_string" type_code="10"></item><br/> <item name="Id" type_name="gh_guid" type_code="9">9d96da9c-9354-ef32-7983-0acb11a3d493</item><br/> <item name="Name" type_name="gh_string" type_code="10">LunchBox</item><br/> <item name="Version" type_name="gh_string" type_code="10">2014.4.27.0</item><br/> </items><br/> </chunk></p>
<p></p>
<p>Any ideas on how to get that bad boy?</p>
<p></p>
<p>Thanks!</p>
<p></p>
<p>B</p> Hi Ryan
ghdoc contains a refe…tag:www.grasshopper3d.com,2013-11-19:2985220:Comment:9603172013-11-19T09:00:01.937ZGiulio Piacentinohttps://www.grasshopper3d.com/profile/GiulioPiacentino
<p>Hi Ryan</p>
<p><code>ghdoc</code><br></br> contains a reference to the current Grasshopper document (solution). By accessing its Path attribute, we could get the location where the file is saved. As you can see in other answers, all of which are working and are good, other ways are possible. They are side-effects of providing a reference to the component (which can understand where it is placed) and ghenv.LocalScope, which shows which variables are defined in the last iteration (scope).…</p>
<p>Hi Ryan</p>
<p><code>ghdoc</code><br/> contains a reference to the current Grasshopper document (solution). By accessing its Path attribute, we could get the location where the file is saved. As you can see in other answers, all of which are working and are good, other ways are possible. They are side-effects of providing a reference to the component (which can understand where it is placed) and ghenv.LocalScope, which shows which variables are defined in the last iteration (scope). So,</p>
<p><code>import os<br/> <br/> if ghdoc.Path:<br/> a = os.path.dirname(ghdoc.Path)</code></p>
<p>should get your folder.</p>
<p>I hope it helps,<br/> Giulio<br/> --<br/> Giulio Piacentino<br/> for Robert McNeel & Associates<br/> giulio@mcneel.com</p> Haha! Well I just learned whe…tag:www.grasshopper3d.com,2013-11-18:2985220:Comment:9598912013-11-18T23:34:00.881ZMostapha Sadeghipour Roudsarihttps://www.grasshopper3d.com/profile/MostaphaSadeghipour
<p>Haha! Well I just learned where can I find the right OnPingDocument method for the GHPython component... Thank you for that. :)</p>
<p>Haha! Well I just learned where can I find the right OnPingDocument method for the GHPython component... Thank you for that. :)</p> Ha! Mostapha beat me to it wi…tag:www.grasshopper3d.com,2013-11-18:2985220:Comment:9600592013-11-18T23:31:19.118ZAndrew Heumannhttps://www.grasshopper3d.com/profile/AndrewHeumann
<p>Ha! Mostapha beat me to it with a more concise answer :D</p>
<p>Ha! Mostapha beat me to it with a more concise answer :D</p>