예제 #1
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
              Application app = uiapp.Application;
              Document doc = uiapp.ActiveUIDocument.Document;

              if( string.IsNullOrEmpty( doc.PathName ) )
              {
            message = "Please store RVT file "
              + "before launching this command";

            return Result.Failed;
              }

              // Retrieve LMV credentials.

              string client_key;
              string client_secret;

              if( !Util.GetLvmCredentials(
            out client_key, out client_secret ) )
              {
            message = _key_secret_prompt;
            return Result.Failed;
              }

              // Upload and translate model file.
              // Todo: add linked files as well.

              ArrayList fileList = new ArrayList();
              //fileList.Add( asm.FullFileName );
              //fileList.Add( doc.PathName );

              // Revit blocks the current file.
              // Copy it to a location with no spaces in the name.
              // From then on, the whole upload process could be spawned off into a separate thread.
              // Well, no, we do need the URN.

              string filename = Path.Combine(
            Path.GetTempPath(),
            Path.GetFileName( doc.PathName ) );
              filename.Replace( ' ', '_' );
              Debug.Print( filename );
              File.Delete( filename );
              File.Copy( doc.PathName, filename, true );
              fileList.Add( filename );

              //foreach( Document oRefDoc in asm.AllReferencedDocuments )
              //{
              //  fileList.Add( oRefDoc.FullDocumentName );
              //}

              MultiFileUploader.Util u = new MultiFileUploader.Util(
            "https://developer.api.autodesk.com" );

              string urn = u.UploadFilesWithReferences(
            client_key, client_secret, "comphoundrvtbucket",
            fileList, null, true );

              if( string.IsNullOrEmpty( urn ) )
              {
            message = "View and Data API upload and "
              + "translation failed.";

            return Result.Failed;
              }

              Transform projectLocationTransform
            = Util.GetProjectLocationTransform( doc );

              // Loop through all family instance elements
              // and export their data.

              FilteredElementCollector instances
            = new FilteredElementCollector( doc )
              .OfClass( typeof( FamilyInstance ) );

              Result rc = Result.Succeeded;

              InstanceData instanceData;

              int n = 0;

              foreach( FamilyInstance e in instances )
              {
            Debug.Print( e.Id.IntegerValue.ToString() );

            instanceData = new InstanceData( e,
              projectLocationTransform, urn );

            if( !Util.Put( "instances/" + e.UniqueId,
              instanceData, out message ) )
            {
              rc = Result.Failed;
              break;
            }
            ++n;
              }
              Debug.Print(
            "CompHound uploaded {0} instance{1}.",
            n, ( 1 == n ? "" : "s" ) );

              return rc;
        }
예제 #2
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            Application   app   = uiapp.Application;
            Document      doc   = uiapp.ActiveUIDocument.Document;

            if (string.IsNullOrEmpty(doc.PathName))
            {
                message = "Please store RVT file "
                          + "before launching this command";

                return(Result.Failed);
            }

            // Retrieve LMV credentials.

            string client_key;
            string client_secret;

            if (!Util.GetLvmCredentials(
                    out client_key, out client_secret))
            {
                message = _key_secret_prompt;
                return(Result.Failed);
            }

            // Upload and translate model file.
            // Todo: add linked files as well.

            ArrayList fileList = new ArrayList();
            //fileList.Add( asm.FullFileName );
            //fileList.Add( doc.PathName );

            // Revit blocks the current file.
            // Copy it to a location with no spaces in the name.
            // From then on, the whole upload process could be spawned off into a separate thread.
            // Well, no, we do need the URN.

            string filename = Path.Combine(
                Path.GetTempPath(),
                Path.GetFileName(doc.PathName));

            filename.Replace(' ', '_');
            Debug.Print(filename);
            File.Delete(filename);
            File.Copy(doc.PathName, filename, true);
            fileList.Add(filename);

            //foreach( Document oRefDoc in asm.AllReferencedDocuments )
            //{
            //  fileList.Add( oRefDoc.FullDocumentName );
            //}

            MultiFileUploader.Util u = new MultiFileUploader.Util(
                "https://developer.api.autodesk.com");

            string urn = u.UploadFilesWithReferences(
                client_key, client_secret, "comphoundrvtbucket",
                fileList, null, true);

            if (string.IsNullOrEmpty(urn))
            {
                message = "View and Data API upload and "
                          + "translation failed.";

                return(Result.Failed);
            }

            Transform projectLocationTransform
                = Util.GetProjectLocationTransform(doc);

            // Loop through all family instance elements
            // and export their data.

            FilteredElementCollector instances
                = new FilteredElementCollector(doc)
                  .OfClass(typeof(FamilyInstance));

            Result rc = Result.Succeeded;

            InstanceData instanceData;

            int n = 0;

            foreach (FamilyInstance e in instances)
            {
                Debug.Print(e.Id.IntegerValue.ToString());

                instanceData = new InstanceData(e,
                                                projectLocationTransform, urn);

                if (!Util.Put("instances/" + e.UniqueId,
                              instanceData, out message))
                {
                    rc = Result.Failed;
                    break;
                }
                ++n;
            }
            Debug.Print(
                "CompHound uploaded {0} instance{1}.",
                n, (1 == n ? "" : "s"));

            return(rc);
        }