Пример #1
0
        // Upload children and collect json info,
        // set references
        bool uploadSubDocs(string strFile, ref string refJson)
        {
            // 1) Get all referenced files and collect json ref
            string strName = Path.GetFileName(strFile);

            // 2) Upload subdocs and collect JSON info
            Inv.ApprenticeServerComponent app = new Inv.ApprenticeServerComponent();
            Inv.ApprenticeServerDocument  doc = app.Open(strFile);
            //IList<string> urns = new List<string>();
            Inv.FilesEnumerator files = doc.File.ReferencedFiles;
            foreach (Inv.File file in files)
            {
                string subUrn = "";
                if (uploadFile(file.FullFileName, ref subUrn))
                {
                    string strSubName = Path.GetFileName(file.FullFileName);
                    refJson +=
                        "{ \"file\" : \"" + subUrn + "\"," +
                        "\"metadata\" : { " +
                        //              "\"childPath\" : \"" + file.FullFileName + "\"," +
                        //              "\"parentPath\" : \"" + strFile + "\"" +
                        "\"childPath\" : \"" + strSubName + "\"," +
                        "\"parentPath\" : \"" + strName + "\"" +
                        "},";
                }

                uploadSubDocs(file.FullFileName, ref refJson);
            }

            return(true);
        }
Пример #2
0
        private string GetPropertiesLocal(string filePath)
        {
            string result = "";

            try
            {
                Inv.ApprenticeServerComponent asc = new Inv.ApprenticeServerComponent();
                Inv.ApprenticeServerDocument  asd = asc.Open(filePath);

                // "Inventor Summary Information"
                Inv.PropertySet ps = asd
                                     .PropertySets["{F29F85E0-4FF9-1068-AB91-08002B27B3D9}"];

                foreach (Inv.Property p in ps)
                {
                    result += string.Format("{0}={1};",
                                            p.DisplayName,
                                            p.Value);
                }

                asd.Close();
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }

            return(result);
        }
Пример #3
0
        // Upload file, upload children and collect json info,
        // set references
        bool uploadSubDocs_old(string strFile, ref string fileUrn)
        {
            // 1) Upload file
            if (!uploadFile(strFile, ref fileUrn))
            {
                return(false);
            }

            // 2) Get all referenced files and collect json ref
            string strName = Path.GetFileName(strFile);
            string refJson =
                "{ " +
                "\"master\" : \"urn:adsk.objects:os.object:alexbicalhobucket2/A1.iam\"," +
                "\"dependencies\" : [";

            Inv.ApprenticeServerComponent app = new Inv.ApprenticeServerComponent();
            Inv.ApprenticeServerDocument  doc = app.Open(strFile);
            IList <string> urns = new List <string>();

            Inv.FilesEnumerator files = doc.File.ReferencedFiles;
            foreach (Inv.File subDoc in files)
            {
                string subUrn = "";
                if (uploadSubDocs(subDoc.FullFileName, ref subUrn))
                {
                    string strSubName = Path.GetFileName(subDoc.FullFileName);
                    refJson +=
                        "{ \"file\" : \"urn:adsk.objects:os.object:alexbicalhobucket2/A1A1.iam\"," +
                        "\"metadata\" : { " +
                        "\"childPath\" : \"" + strSubName + "\"," +
                        "\"parentPath\" : \"" + strName + "\"" +
                        "},";
                }
            }

            // 3) Set the reference for the main file
            if (files.Count > 0)
            {
                refJson += "] }";

                RestRequest request = new RestRequest();
                request.Resource = "/oss/v1/setreference";
                request.Method   = Method.POST;
                request.AddParameter("Authorization", "Bearer " + _token, ParameterType.HttpHeader);
                request.AddParameter("Content-Type", "application/json", ParameterType.HttpHeader);

                // Bucketname is the name of the bucket.
                request.AddParameter("application/json", refJson, ParameterType.RequestBody);

                IRestResponse response = _client.Execute(request);
                logText(request.Method.ToString() + " " + request.Resource);
                logText(response.StatusCode.ToString() + ": " + response.StatusDescription);
            }

            return(true);
        }
Пример #4
0
        private void SaveWithApprentice()
        {
            string NewFolder       = "C:\\Temp\\";
            string AsmFullFilename = "C:\\Program Files\\Autodesk\\Inventor 2013\\Samples\\Models\\Tube & Pipe\\Tank\\Tank.iam";

            Inventor.ApprenticeServerDocument oApprenticeDoc = mApprenticeApp.Open(AsmFullFilename);

            SaveRec(ref NewFolder, ref oApprenticeDoc);
            mApprenticeApp.FileSaveAs.ExecuteSaveCopyAs();
            oApprenticeDoc.Close();
        }