public void saveToFile() { if (!string.IsNullOrEmpty(readIntoLibraryFromRelativeAXOBJPath)) { string filepath = ArchimatixUtils.getAbsoluteLibraryPath(readIntoLibraryFromRelativeAXOBJPath); if (File.Exists(filepath)) { AX.SimpleJSON.JSONNode jn = AX.SimpleJSON.JSON.Parse(File.ReadAllText(filepath)); AX.SimpleJSON.JSONNode pon = jn[0]; if (jn ["parametric_objects"] != null) { pon = jn ["parametric_objects"] [0]; } pon["name"] = Name; pon["includeInSidebarMenu"] = includeInSidebarMenu.ToString(); pon["description"] = description; if (!string.IsNullOrEmpty(author)) { pon["author"] = author; } if (!string.IsNullOrEmpty(tags)) { pon["tags"] = tags; } if (!string.IsNullOrEmpty(documentationURL)) { pon["documentationURL"] = documentationURL; } if (!string.IsNullOrEmpty(readIntoLibraryFromRelativeAXOBJPath)) { pon["readIntoLibraryFromRelativeAXOBJPath"] = readIntoLibraryFromRelativeAXOBJPath; } // resave File.WriteAllText(filepath, jn.ToString().Replace("\\", "")); //Debug.Log(jn.ToString().Replace("\\","")); } } }
public void saveParametricObjectMetadata(AXParametricObject head_po) { //Debug.Log("SAVING head_po.author="+head_po.author); AX.SimpleJSON.JSONNode hn = AX.SimpleJSON.JSON.Parse(JSONSerializersAX.ParametricObjectAsJSON(head_po)); string filename = ArchimatixUtils.getAbsoluteLibraryPath(head_po.readIntoLibraryFromRelativeAXOBJPath); AX.SimpleJSON.JSONNode jn = AX.SimpleJSON.JSON.Parse(File.ReadAllText(filename)); jn["parametric_objects"][0] = hn; File.WriteAllText(filename, jn.ToString()); rebuildTagListsFromExistingPOs(); }
public static void removeLibraryItem(LibraryItem li) { string filepath = ArchimatixUtils.getAbsoluteLibraryPath(li.readIntoLibraryFromRelativeAXOBJPath); // First remove the item from the live library. THat way when the file is deleted, AX will not try to rebuild the library. //string nodeName = System.IO.Path.GetFileNameWithoutExtension(filepath); //LibraryItem li = ArchimatixEngine.library.getLibraryItem(nodeName); ArchimatixEngine.library.removeLibraryItemFromList(li); //string localFilepath = filepath.Substring(filepath.IndexOf("Assets/")); string axobjRelativePath = ArchimatixUtils.getRelativeFilePath(filepath);; // [Darkwell: change "undoable" to "cannot be undone" - 2016.06.02] if (EditorUtility.DisplayDialog("Delete Library Object?", "Are you sure you want to delete " + li.Name + "? This cannot be undone!", "Really Delete", "Cancel")) { AssetDatabase.DeleteAsset(axobjRelativePath); string prefix = (li.is2D) ? "zz-AX-2DLib-" : "zz-AX-3DLib-"; string filename = System.IO.Path.GetFileNameWithoutExtension(li.readIntoLibraryFromRelativeAXOBJPath); string noPrefixThumbnailPath = System.IO.Path.ChangeExtension(li.readIntoLibraryFromRelativeAXOBJPath, ".jpg"); string ThumbnailPathWithPrefix = noPrefixThumbnailPath.Replace(filename, prefix + filename); AssetDatabase.DeleteAsset(ThumbnailPathWithPrefix); //Debug.Log(thumbnailRelativePath + " deleted"); // Refresh the AssetDatabase after all the changes AssetDatabase.Refresh(); //library.readLibraryFromFiles(); } }
public static AXParametricObject instantiateParametricObject(string readIntoLibraryFromRelativeAXOBJPath) { AXModel model = null; // 1. First choice is to use a selected model.... if (ArchimatixEngine.currentModel != null) { model = ArchimatixEngine.currentModel; } bool doInstantiation = true; if (model == null) { // ok, are there other models in the scene that the user doesn't realize arene't selected? AXModel[] axModels = GameObject.FindObjectsOfType(typeof(AXModel)) as AXModel[]; if (axModels != null) { if (axModels.Length == 1) { // Offer this model as a button, but also give opportunity to create a new one... int option = EditorUtility.DisplayDialogComplex("Instantiating Library Item", "There is no AX model currently selected", "Cancel", "Add to " + axModels[0], "Create a new Model"); switch (option) { // Save Scene case 0: doInstantiation = false; break; // Save and Quit. case 1: model = axModels[0]; break; case 2: GameObject axgo = AXEditorUtilities.createNewModel(); model = axgo.GetComponent <AXModel>(); doInstantiation = false; break; default: doInstantiation = false; break; } } else if (axModels.Length > 1) { // Throw up a dialog to see if use wants to go select one of the existing models or create a new one. if (EditorUtility.DisplayDialog("Instantiating Library Item", "There is no AX model currently selected", "Select and Existing Model", "Create a new Model")) { return(null); } } } } if (!doInstantiation) { return(null); } if (model == null) { // Well, then, we tried everything.... GameObject axgo = AXEditorUtilities.createNewModel(); model = axgo.GetComponent <AXModel>(); } //Library.lastInstantiation = po; // This file path is where the metadata // for this head_po was found. Go back to this file // and get the rest of the data... string filepath = ArchimatixUtils.getAbsoluteLibraryPath(readIntoLibraryFromRelativeAXOBJPath); List <AXParametricObject> poList = new List <AXParametricObject>(); List <AXRelation> relationList = new List <AXRelation>(); AX.SimpleJSON.JSONNode json = AX.SimpleJSON.JSON.Parse(File.ReadAllText(filepath)); foreach (AX.SimpleJSON.JSONNode poNode in json["parametric_objects"].AsArray) { poList.Add(JSONSerializersAX.ParametricObjectFromJSON(poNode)); } foreach (AX.SimpleJSON.JSONNode rNode in json["relations"].AsArray) { relationList.Add(AXRelation.fromJSON(rNode)); } //Debug.Log (rNode); // make sure there is a game object ready to instantiate this on if (model == null) { // check if the user really wants to create a new model... GameObject axgo = AXEditorUtilities.createNewModel(); model = axgo.GetComponent <AXModel>(); } Undo.RegisterCompleteObjectUndo(model, "Add Library Object"); // ADD AND RIGUP // !!! Actually add the library item (as a list of PO's and Relations) to the model model.addAndRigUp(poList, relationList); AXParametricObject head_po = poList[0]; head_po.startStowInputs(); //if (poList[0].is2D() && ArchimatixEngine.workingAxis != (int) Axis.NONE) // poList[0].intValue ("Axis", ArchimatixEngine.workingAxis); model.setRenderMode(AXModel.RenderMode.GameObjects); model.generate(); ArchimatixEngine.currentModel = model; Selection.activeGameObject = model.gameObject; model.deselectAll(); model.selectOnlyPO(head_po); head_po.focusMe = true; //AXParametricObject mostRecentPO = model.recentlySelectedPO; AXParametricObject mostRecentPO = model.recentlySelectedPO; //getPOSelectedBefore(head_po); //Debug.Log ("model.focusPointInGraphEditor="+model.focusPointInGraphEditor); float pos_x = (model.focusPointInGraphEditor.x) + 100; // + UnityEngine.Random.Range(-100, 300); float pos_y = (model.focusPointInGraphEditor.y - 250) + UnityEngine.Random.Range(-10, 0); if (mostRecentPO != null) { //pos_x = mostRecentPO.rect.x + 200; //pos_y = mostRecentPO.rect.y; } //Debug.Log (new Rect(pos_x, pos_y, 150, 100)); head_po.rect = new Rect(pos_x, pos_y, 150, 500); //Debug.Log ("OK "+po.Name+".focusMe = " + po.focusMe); // make sure it is in view in the editor window.... //model.startPanningToRect(head_po.rect); //model.cleanGraph(); model.remapMaterialTools(); model.autobuild(); head_po.generator.adjustWorldMatrices(); model.build(); model.selectOnlyPO(head_po); //model.beginPanningToRect(head_po.rect); //AXNodeGraphEditorWindow.zoomToRectIfOpen(head_po.rect); //Debug.Log(" 1 model.selectedPOs.Count="+model.selectedPOs.Count + " " + model.selectedPOs[0].Name ); // EDITOR WINDOW ArchimatixEngine.repaintGraphEditorIfExistsAndOpen(); // SCENEVIEW if (SceneView.lastActiveSceneView != null) { //Debug.Log("REPAINT"); SceneView.lastActiveSceneView.Repaint(); } //Debug.Log("--> ArchimatixEngine.currentModel=" + ArchimatixEngine.currentModel); return(head_po); }