Пример #1
0
        private void importOneParameter(string requestedParameterName, Autodesk.Revit.DB.Document targetDoc)
        {
            DefinitionFile m_sharedParamFile;
            // = ptr2TargetDoc.Application.OpenSharedParameterFile
            FamilyManager m_Manager = targetDoc.FamilyManager;

            // ptr2TargetDoc.Application.SharedParametersFilename = p_fileName
            m_sharedParamFile = targetDoc.Application.OpenSharedParameterFile();
            foreach (DefinitionGroup Group in m_sharedParamFile.Groups)
            {
                foreach (ExternalDefinition oneExternalDef in Group.Definitions)
                {
                    if ((oneExternalDef.Name.ToLower() == requestedParameterName.ToLower()))
                    {
                        Autodesk.Revit.DB.Transaction docTransaction = new Autodesk.Revit.DB.Transaction(targetDoc);
                        docTransaction.SetName("mertens3d.com - parameterJerk - Create Shared Parameter");
                        try
                        {
                            docTransaction.Start();
                            // m_Manager.AddParameter(oneExternalDef, oneExternalDef.ParameterGroup, True)
                            // see http://spiderinnet.typepad.com/blog/2011/04/parameter-of-revit-api-15-set-familyparameter.html
                            FamilyParameter returnedParameter = m_Manager.AddParameter(oneExternalDef, _groupParameterUnderEnum, _isInstance);
                            docTransaction.Commit();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                    }
                }
            }
        }
Пример #2
0
        public Transaction NewTransaction(string name)
        {
            Transaction toReturn = new Autodesk.Revit.DB.Transaction(Doc);

            toReturn.SetName(name);
            return(toReturn);
        }
Пример #3
0
        // Private Sub bindSharedParameterToFile()
        //     Dim userResponse As MessageBox.ShowResult
        //     userResponse = MessageBox.Show("Create the Shared Parameter " & vbCrLf & vbTab & thisParameterName & vbCrLf & "?", MessageBox.ShowStyle.YesNo)
        //     If userResponse = MessageBox.ShowResult.Yes Then
        //         'first we need to make sure the shared parameters file is setup correctly
        //         'If ptr2SharedParametersFile.checkStageForSetup() Then
        //         Dim docTransaction As New Autodesk.Revit.DB.Transaction(ptr2TargetDoc)
        //         docTransaction.SetName("mertens3d.com - parameterJerk - Create Shared Parameter")
        //         docTransaction.Start()
        //         'If Not ptr2SharedParametersFile.doesParameterAlreadyExistInGroup(thisParameterName) Then
        //         '    ptr2SharedParametersFile.addParameterToGroup(thisParameterName)
        //         'End If
        //         'now we need to add to the file
        //         bindParameterToFile()
        //         docTransaction.Commit()
        //         'Else
        //         '    MessageBox.Show("Canceled - Create New Parameter")
        //         'End If
        //     End If
        // End Sub
        // Private Sub createNONSharedParameterInFile()
        //     Dim docTransaction As New Autodesk.Revit.DB.Transaction(ptr2TargetDoc)
        //     docTransaction.SetName("mertens3d.com - parameterJerk - Create Shared Parameter")
        //     docTransaction.Start()
        //     'now we need to add to the file
        //     'bindParameterToFile()
        //     'we want it in the project, so bind to a category
        //     Dim cats As CategorySet = ptr2TargetDoc.Application.Create.NewCategorySet
        //     cats.Insert(ptr2TargetDoc.Settings.Categories.Item(BuiltInCategory.OST_ProjectInformation))
        //     'create a binding - instance or type
        //     Dim bind As InstanceBinding = ptr2TargetDoc.Application.Create.NewInstanceBinding(cats)
        //     ptr2TargetDoc.ParameterBindings.Insert(sharedParameterFileDef, bind, BuiltInParameterGroup.PG_TEXT)
        //     docTransaction.Commit()
        // End Sub
        // Private Sub bindParameterToFile()
        //     MessageBox.Show("bindParameterToFile")
        //     Dim m_Manager As FamilyManager = Nothing
        //     m_Manager = ptr2TargetDoc.FamilyManager
        //     Try
        //         MessageBox.Show("_thisExternalDefinition: " & _thisExternalDefinition.ToString())
        //         m_Manager.AddParameter(_thisExternalDefinition, _parameterGroup, True)
        //     Catch ex As Exception
        //         MessageBox.Show(ex.ToString())
        //     End Try
        // End Sub
        private void deleteExistingParameter(FamilyParameter paramToDelete, Autodesk.Revit.DB.Document targetDoc)
        {
            FamilyManager mgr = targetDoc.FamilyManager;

            JerkHub.Ptr2Debug.AddToDebug(("Deleting existing parameter: " + paramToDelete.Definition.Name));
            Autodesk.Revit.DB.Transaction docTransaction = new Autodesk.Revit.DB.Transaction(targetDoc);
            docTransaction.SetName("delete existing parameter");
            try
            {
                docTransaction.Start();
                mgr.RemoveParameter(paramToDelete);
                docTransaction.Commit();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }