Issue with assigning shared parameter programaticly

Issue with assigning shared parameter programaticly

johan.kleijn
Participant Participant
213 Views
2 Replies
Message 1 of 3

Issue with assigning shared parameter programaticly

johan.kleijn
Participant
Participant

Ive been wanting to add some shared project parameters to my plugin to use as identifiers for other aspects that i will develop later but cant seem to get the shared parameter to actually be assigned. After a lot of searching i still havent found a solution or indication what i might be doing wrong.

In my case im programaticly creating the shared parameter file, ive tested that the generated file works by assigning it manualy and there are no issues so the problem must be where i assign it.

What im trying to achieve is a shared project parameter called Refrencing element and asigning it to the views category. 

Does anyone know what i might be doing wrong?

 

private void CreateSharedParameter(Document doc, Application app)
        {
            Category category = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Views);
            CategorySet categorySet = app.Create.NewCategorySet();
            categorySet.Insert(category);

            string originalFile = app.SharedParametersFilename;
            string folderName = @"c:\LRCZ_Tools";
            string fileName = @"C:\LRCZ_Tools\LRCZ_SharedParameters.txt";


            try
            {
                //Create shared parameter file
                System.IO.Directory.CreateDirectory(folderName);
                // Check if file already exists. If yes, delete it.     

                if (File.Exists(fileName))
                {
                    //File.Delete(fileName);
                }
                else
                {
                    // Create a new file     
                    using (StreamWriter sw = File.CreateText(fileName))
                    {
                        sw.WriteLine("# This is a Revit shared parameter file.");
                        sw.WriteLine("# Do not edit manually.");
                        sw.WriteLine("*META	VERSION	MINVERSION");
                        sw.WriteLine("META	2	1");
                        sw.WriteLine("*GROUP	ID	NAME");
                        sw.WriteLine("GROUP	1	References");
                        sw.WriteLine("*PARAM	GUID	NAME	DATATYPE	DATACATEGORY	GROUP	VISIBLE	DESCRIPTION	USERMODIFIABLE	HIDEWHENNOVALUE");
                        sw.WriteLine("PARAM	2b9956a3-7075-40ae-92d6-bc999927bbd4	Refrencing Element	TEXT		1	1		1	0");

                    }

                }
                app.SharedParametersFilename = fileName;
                DefinitionFile sharedParamterFile = app.OpenSharedParameterFile();
               
                foreach (DefinitionGroup dg in sharedParamterFile.Groups)
                {
                    if(dg.Name == "References")
                    {
                        ExternalDefinition externalDefinition = dg.Definitions.get_Item("Referencing Element") as ExternalDefinition;
                        var v = from ExternalDefinition d in dg.Definitions select d;
                   
                        using (Transaction t = new Transaction(doc))
                        {
                            t.Start("Add shared parameters");
                            //Bind parameters
                            Binding newIB = app.Create.NewInstanceBinding(categorySet);
                            //Parrameter group
                            doc.ParameterBindings.Insert(externalDefinition, newIB, BuiltInParameterGroup.PG_IDENTITY_DATA);
                            t.Commit();
                            
                        }
                    
                    }
                }
            }
            catch
            {
               app.SharedParametersFilename = originalFile;
            }
            finally
            {
               app.SharedParametersFilename = originalFile;
            }
        }

 

0 Likes
214 Views
2 Replies
Replies (2)
Message 2 of 3

jeremy_tammik
Alumni
Alumni

One of my last forays into the area of programmatic creation of shared parameters was for ExportCncFab:

 

https://thebuildingcoder.typepad.com/blog/2015/06/cnc-direct-export-wall-parts-to-dxf-and-sat.html

 

Maybe that will provide new ideas?

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 3

johan.kleijn
Participant
Participant
Thanks, Ill take a look and see if i can get anything from that to fix it!
0 Likes