ahmedmigo/Move-to-library-sketchplugin

Not working in Sketch 72.x

Opened this issue · 11 comments

I tried to move selected items to the Library and it is not moving them.

Hi @ahmedmigo

Is this plugin still supported? I use it a lot and now it's no longer working since Sketch 72.x
I hope you can update the plugin. Or is there a workaround?

@maartenvh I messaged Ahmed and he has since moved to Figma, so is not longer supporting this, which is a massive pain for me too, it was one of my most useful fave plugins.

It looks like this is the issue

New in Sketch 72
Released 5 May, 2021 – read release notes

Changes

The internal class MSApplicationMetadata has been refactored into a new class, BCSketchInfo.

If a plugin was relying on any of the internal methods in MSApplicationMetadata, its code will not work (and may even crash Sketch if it’s passing the returned value unchecked to other parts of its code). The methods that previously lived in MSApplicationMetadata have been replaced with methods in BCSketchInfo.shared(), and most of the metadata you may need is available directly as a dictionary in BCSketchInfo.shared().metadata().

However, as mentioned in our Internal API page, these are internal classes that should never be used.

We recommend using the JavaScript API where possible. Something is missing? Please submit feedback and feature requests.

If I change from "MSApplicationMetadata.metadata().appVersion" to "BCSketchInfo.metadata().appVersion" in this block in the JS file to the following It seems to move ok, I have not done any extensive testing yet though

function localSymbolForSymbol_inLibrary(context, symbol, library) {
  if (BCSketchInfo.metadata().appVersion >= 50) {
    var shareableObjectReference = MSShareableObjectReference.referenceForShareableObject_inLibrary(symbol, library);
    var importedSymbol = AppController.sharedInstance().librariesController().importShareableObjectReference_intoDocument(shareableObjectReference, context.document.documentData());
  } else {
    var importedSymbol = AppController.sharedInstance().librariesController().importForeignSymbol_fromLibrary_intoDocument_(symbol, library, context.document.documentData());
  }

  return importedSymbol.symbolMaster();
}

Ok the above seems to move the component to another library. The Dialog still appears open on the initial file so it is not completing the process. The symbol on the original file is still connected to the symbol in the original file. So it is not connecting to the library and deleting from the original file still.

Actually I never had the new API right, if should have been written as "BCSketchInfo.shared().metadata()", I had missed out the .shared() so it should be

function localSymbolForSymbol_inLibrary(context, symbol, library) {
  if (BCSketchInfo.shared().metadata().appVersion >= 50) {
    var shareableObjectReference = MSShareableObjectReference.referenceForShareableObject_inLibrary(symbol, library);
    var importedSymbol = AppController.sharedInstance().librariesController().importShareableObjectReference_intoDocument(shareableObjectReference, context.document.documentData());
  } else {
    var importedSymbol = AppController.sharedInstance().librariesController().importForeignSymbol_fromLibrary_intoDocument_(symbol, library, context.document.documentData());
  }

  return importedSymbol.symbolMaster();
}

Still unresolved in Sketch 86. Pity.

Hey Guys.

I lost the source code of the project. if somebody can modify the code I and fix the issues I will merge it to the main branch

@custa1200 How did you manage to get the source code.

It would be great if you can send me a way to reverse the export project so I can fix the issues. because i lost the source code.
or you can email me.

The only code I have is in this repo. When I was asking you about the UI code you said it wasn't needed to fix the issue. I was talking to sketch Help and they are the ones the flagged it incompatible with the most recent releases. The code that you accepted from me worked for only a couple of versions.

I have not looked into things any further to fix again. They suggested I use some feature from the Automate Sketch plugin https://ashung.github.io/Automate-Sketch/ which kinda worked but I found to not work 100% as expected killing a bunch of overrides I had. It really is a shame, your plugin when it was working was a daily lifesaver. I see in the latest beta release notes they are changing their document object model again so I would anticipate there to be issues again after it comes out of Beta. I am sure if you reached out to them directly they might be able to help you?

Currently using the plugin: Symbol Swapper