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?
Tags:
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.
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?
Welcome to
Grasshopper
© 2024 Created by Scott Davidson.
Powered by