1

I tried running this script as a macro on Magicdraw, but kept getting an error at line 142 where the script calls JsonSlurper. Then, when I tried importing the Jsonslurper function from the Json library import groovy.json.JsonSlurper;, it gives me a new error at that line. My magicdraw uses Groovy 3.0.7, which I checked has Jsonslurper in its libraries. I'm not sure how to further figure out where the problem is. I am originally trying to take an excel file, make some new columns, and use those columns to create boxes, ports, and interfaces. I got the excel processing done in Python, but am still figuring out the Magicdraw API.

Error 1:

MagicDraw cannot execute the Groovy macro, please make sure that the C:\Users\elevy\Downloads\rapid-modeling-tools-master\player-piano\player-piano-script.groovy is correct. startup failed: C:\Users\elevy\Downloads\rapid-modeling-tools-master\player-piano\player-piano-script.groovy: 142: unable to resolve class JsonSlurper @ line 142, column 18. jsonSlurper = new JsonSlurper(); ^ 1 error org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: C:\Users\elevy\Downloads\rapid-modeling-tools-master\player-piano\player-piano-script.groovy: 142: unable to resolve class JsonSlurper @ line 142, column 18. jsonSlurper = new JsonSlurper(); ^ 1 error

Error 2:

MagicDraw cannot execute the Groovy macro, please make sure that the C:\Users\elevy\Downloads\rapid-modeling-tools-master\player-piano\player-piano-script.groovy is correct. startup failed: C:\Users\elevy\Downloads\rapid-modeling-tools-master\player-piano\player-piano-script.groovy: 14: unable to resolve class groovy.json.JsonSlurper @ line 14, column 1. import groovy.json.JsonSlurper; ^ 1 error org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: C:\Users\elevy\Downloads\rapid-modeling-tools-master\player-piano\player-piano-script.groovy: 14: unable to resolve class groovy.json.JsonSlurper @ line 14, column 1. import groovy.json.JsonSlurper; ^ 1 error enter code here

Ethan Levy
  • 21
  • 1

1 Answers1

0

groovy.json.JsonSlurper is part of the artifactorg.codehaus.groovy:groovy-json:3.0.7 I would assume that this artifact is not part the magic draw distribution.

You could try adding

@Grab(group='org.codehaus.groovy', module='groovy-json', version='3.0.7')

This would download the artifact, but I can't guarantee that this works within MagicDraw.

Leonard Brünings
  • 12,408
  • 1
  • 46
  • 66
  • this didn't work, but I think getting json into magicdraw is the solution. I will try finding another way to add the library. – Ethan Levy Jul 29 '22 at 13:50