Grasshopper

algorithmic modeling for Rhino

I want read comments from script useing XDocument.

LINQ-to-XML introduces XDocument, designed to overcome the enormous list of shortcomings and complexities relating to XmlDocument. It is now the preferred object model for reading, querying and otherwise operating upon XML documents (or even fragments, the implementation doesn’t care).

Assuming the XML documentation file is in the same location as the executable, it’s ludicrously simple to get the XML comments for a reflected member:

When use code:

AssemblyName assemblyName = this.GetType().Assembly.GetName();

XDocument xml = XDocument.Load(assemblyName.Name + ".xml");

Get error:

error: File 'C:\Program Files (x86)\Rhinoceros 5\System\1996b995-eb5b-4da0-96e5-c11336b4126a.xml' not found. (line: 0)

May be this is a problem with script environment.

If this behavior by design, than how I can get this information?

Views: 1152

Replies to This Discussion

Does the xml file exist? If it's not there then obviously it cannot be loaded.

If this dll is compiled by the C# component, then there shouldn't be an Xml file.

--

David Rutten

david@mcneel.com

Whether there is another way, get this information?

What information?

--

David Rutten

david@mcneel.com

Sorry, I unclear described the task.

Reading XML Documentation at Run-Time

How I can get XML Documentation in GH script at Run-Time?

When the C# script component compiles the code, it doesn't generate an xml file, as the assembly is just temporary and nobody would ever reference it. It does create a pdb file which allows me to figure out on which line numbers runtime errors occurred, but there's no xml compilation of source comments.

--

David Rutten

david@mcneel.com

Can I enable this generation?

Else, how I can get raw C# script source for parsing?

The xml doesn't contain any source code, even if it did exist. It just contains the names of types and methods and the comments that were present in the source code.

Let's back it up a few steps... what exact problem are you trying to solve?

--

David Rutten

david@mcneel.com

I write scripts for GH C# component.

Write from "Script Editor", not use Visual Studio for this.

All scripts run from GH.

All methods describe with comments "///<summary>" etc.

First problem - generate documentation for this scripts.

Second problem - some methods should print this information.

I see two ways to solve this problems.

1. Get generated xml after compiling code.

2. Get raw script source code(code which i write in editor) and parse.

Ok, now I understand the goal here. You cannot get the xml as it isn't generated. You can however get the source code and then either parse it yourself or compile it again, this time with xml.

When I get back from my cycling trip today I'll have a look to see if it can be done easily, whether it requires reflection hacking or whether I have to provide some public functionality. I won't be back for at least 7 hours though, today's trip is a big one...

The method that will return the code is protected and looks like:

protected string CreateSourceForEdit(ScriptSource code);

You can probably access it through reflection, but I can also make it public. This will give you the source including the comments. There's another method will generates the actual source being used during compilation:

protected string CreateSourceForCompile(ScriptSource code);

Both of these methods are on the script component class.

If you only care about the comments you wrote yourself perhaps it's enough to just get the ScriptSource out of the script components (that's a public property). The ScriptSource class has public properties for ScriptCode and AdditionalCode (both return a string)

--

David Rutten

david@mcneel.com

I dont understand where I can find this methods :)

Can you write sample code with using reflection?

And I think, that make this methods public not good idea.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service