Book a Demo

Author Topic: Sparx scripting API Diagram Notes & Notes text  (Read 8239 times)

Alexander.Golyshkin

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Sparx scripting API Diagram Notes & Notes text
« on: March 23, 2024, 12:33:17 am »
Hi,

1. How possible to add a diagram notes to diagram using an scripting API having an extracted pointer to Diagram Class?
2. How possible to change a text in Note element in existed Note using scripting API having an extracted pointer to diagram element by
Code: [Select]
getRepo().GetElementByID( diagramObject.ElementID )
« Last Edit: March 23, 2024, 12:40:53 am by Alexander.Golyshkin »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Sparx scripting API Diagram Notes & Notes text
« Reply #1 on: March 23, 2024, 01:30:08 am »
Basically like adding anything to a diagram. You create a note element with the desired content and create a diagramobjects element containing the diagram id and the position.

Changing notes is also simple by retrieving it from the elements, make changes and update it.

q.

Alexander.Golyshkin

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Re: Sparx scripting API Diagram Notes & Notes text
« Reply #2 on: March 25, 2024, 06:23:14 pm »
Since, there were no help from Sparx team, I have found the solution for adding diagram info note & diagram not with GUID and paperclip style to the diagram canvas:

Code: [Select]
def _addDiagramNotes( self, aDiagramNode: CDispatch ):
      pck = self._engine.getRepo().getPackageByID( aDiagramNode.packageID )
      text = pck.elements.addNew( "", "Text" )
      text.Subtype = 18
      text.Update()
      # coord. on diagram
      obj = aDiagramNode.diagramObjects.addNew( "l=10;r=110;t=-20;b=-80", "" )
      obj.elementID = text.elementId
      obj.Update()
      self._engine.getRepo().reloadDiagram( aDiagramNode.diagramID )
      LOGGER.info( "Added TextInfo to Diagram" )

   def _addDiagramGUIDNote( self, aDiagramNode: CDispatch ):
      pck = self._engine.getRepo().getPackageByID( aDiagramNode.packageID )
      note = pck.elements.addNew( "", "Note" )
      note.Notes = aDiagramNode.DiagramGUID
      note.StyleEx = "NS=5"
      note.Update()
      # coord. on diagram
      obj = aDiagramNode.diagramObjects.addNew( "l=10;r=250;t=-100;b=-155;DUID=A15050D3", "" )
      obj.elementID = note.elementId
      obj.Update()
      self._engine.getRepo().reloadDiagram( aDiagramNode.diagramID )
      LOGGER.info( "Added Notes GUID to Diagram" )