How to use the method SetFromXML(?Val) in macro?

  • 1
  • Question
  • Updated 2 years ago

hello,

 I would like to set some formats of central topic via macro. For example, check the option"organic appearance", adjust the setting"main topic line width"......


 However, I can't find the wanted method in Document.CentralTopic. I see there's a method "Document.CentralTopic.SetFromXml(?val)" in object browser. I don't know if possible to check the option by this way.

 If possible, how to assign value for "?val" in SetFromXML(). Thanks for your

Photo of Daping

Daping

  • 7 Posts
  • 0 Reply Likes

Posted 2 years ago

  • 1
Photo of Nick Duffill

Nick Duffill, Champion

  • 508 Posts
  • 169 Reply Likes
You are right that the many of the topic format settings are not exposed with properties or methods.

The XML property is the XML of the topic and all its subtopics. This fact in itself has the potential for big performance issues; if you modify one little thing on the central topic, it could end up re-writing the whole map. You could try reading the XML, making a modification and writing it back. But some of the settings may not appear in the topic XML, as they belong to the default format, which would only be defined in the XML for the whole document and not in each topic. Also, my own experience with writing XML back to topics in the API is that instability sometimes follows. Maybe my XML was not good enough. API methods and properties are much safer than overwriting the XML.

You might be able to do enough of what you need using Topic Styles, as these can be applied and removed through the API.
Photo of Ary Velstra, Expert Trainer

Ary Velstra, Expert Trainer

  • 1245 Posts
  • 186 Reply Likes
Just out of curiosity: If you want to change the format of central topic. Why not use a template or map style format for that?
Photo of Daping

Daping

  • 7 Posts
  • 0 Reply Likes
Thanks for you both.

To ARY: Your suggestion is very good and useful. My screenshot is just an example. There're so many settings in formats of topic, but I can't find the right method for most of them in macro editor. I want to know if possible to to change settings via XML.

To Nick Duffill: Thanks for your professional comments. I have not enough knowledge to do API development and not plan to do that. I only have some skills of VB language. Create simple macros is for the purpose of reducing duplicate manual work. If you can show me a simple example of XML, it will be very good.
Photo of Daping

Daping

  • 7 Posts
  • 0 Reply Likes
I can see the structure of XML via XMLNotePad as illustrated. But it always get errors while using SetFromXML("Map/StyleGroup/Structure/UseOrganicLines"). Anyone can give me a hint please? Thanks!
Photo of aHa!Coaching

aHa!Coaching, Champion

  • 1192 Posts
  • 116 Reply Likes
Could you please share some details about the errors? Normally, when opening a malformed document MindManager should bring up two errors: one XML error (unexpected value etc.) and then a 2nd error that it cannot open the document.
Photo of Daping

Daping

  • 7 Posts
  • 0 Reply Likes
Thanks for your response.
 
I did a simple test like the following, but get an error.

sub main
      ActiveDocument.CentralTopic.SetFromXml("ap:Map/ap:StyleGroup/ap:Structure/UseOrganicLines")
end sub
Photo of Nick Duffill

Nick Duffill, Champion

  • 508 Posts
  • 169 Reply Likes
The string "ap:Map/ap:StyleGroup/ap:Structure/UseOrganicLines" is not a valid XML document. This is only a fragment of an XML document, and I think this method expects the whole XML document. You might be able to read the XML from the node first, amend it to change the line setting then write it all back.