InternalDefinition to ExternalDefinition

InternalDefinition to ExternalDefinition

Extraneous
Advisor Advisor
1,771 Views
4 Replies
Message 1 of 5

InternalDefinition to ExternalDefinition

Extraneous
Advisor
Advisor

Hi everyone.

I try to create plugin to transfer shared parameters from one family to next. Across FamilyManager I can get list of shared parameters in family and their Definitions.

Next, I try to add parameters in my family across FamilyManager.AddParameter method.

But I ran into a problem. Definition of parameter which I can get from Family is "InternalDefinition". But Definition for addition of parameter should be ExternalDefinition. I can't convert "InternalDefinition" to "ExternalDefinition".

 

I can easily get ExternalDefinition by SharedParametersFile, but how to get it from other family? The only way is to create a temporary txt-file, create shared parameter with GUID, and only then add shared parameter to next family?

 

Thank for answer.

Alexander Zuev
In BIM we trust
Facebook | Linkedin | Telegram

0 Likes
1,772 Views
4 Replies
Replies (4)
Message 2 of 5

Extraneous
Advisor
Advisor

Still did it through creating a temporary .txt file.

It helped that when creating the ExternalDefinition, you can specify the GUID, and the method immediately returns the ExternalDefinition, so you do not need to gut the file a second time.

Here is the idea:

 

 

public void SampleExternalDefinition()
{
   [...]
    string familyFolder = Path.GetDirectoryName(analogFamilyPath);
    string familyTitle = analogFamilyDoc.Title.Remove(analogFamilyDoc.Title.Length - 4);
    string txtPath = Path.Combine(familyFolder, familyTitle + ".txt");
    FileStream fs = File.Create(txtPath);
    fs.Close();

    commandData.Application.Application.SharedParametersFilename = txtPath;
    DefinitionFile defFile = app.OpenSharedParameterFile();

    foreach (SharedParameterContainer spc in analogParams)
    {
        DefinitionGroup tempGroup = defFile.Groups.Create(spc.name);
        Definitions defs = tempGroup.Definitions;
        ExternalDefinitionCreationOptions defOptions = 
new ExternalDefinitionCreationOptions(spc.name, spc.intDefinition.ParameterType); defOptions.GUID = spc.guid; spc.exDefinition = defs.Create(defOptions) as ExternalDefinition; } [...]
FamilyManager fMan = famdoc.FamilyManager;
using (Transaction t = new Transaction(famdoc))
{
t.Start("Parameters");
foreach (SharedParameterContainer spc in analogParams)
{
fMan.AddParameter(spc.exDefinition, spc.paramGroup, spc.isInstance);
}
t.Commit();
}
System.IO.File.Delete(txtPath);
} public class SharedParameterContainer { public string name; public BuiltInParameterGroup paramGroup; public bool isInstance; public InternalDefinition intDefinition; public Guid guid; public ExternalDefinition exDefinition; }

 

Alexander Zuev
In BIM we trust
Facebook | Linkedin | Telegram

Message 3 of 5

jeremytammik
Autodesk
Autodesk

Dear Alexander,

 

Thank you for your interesting query and solution.

 

I think this is a valid approach. Sorry it is a bit convoluted 🙂

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 4 of 5

Extraneous
Advisor
Advisor

@jeremytammik, next, I ran into a problem, the plugin did not start in Revit 2015.

I found the problem with the fact that in 2015 "ExternalDefinitionCreationOptions" was renamed to "ExternalDefinitonCreationOptions" (sounds like a joke). Creation without "options" is obsolete in the 2016 version.

Please, tell me if it is possible to make a plug-in that will be launched in 2015 and 2017, without creating separate solutions. Because of a misprint in one symbol it's sad.

Alexander Zuev
In BIM we trust
Facebook | Linkedin | Telegram

0 Likes
Message 5 of 5

jeremytammik
Autodesk
Autodesk

Dear Alexander,

 

Thank you for your update.

 

Yes, sorry about the typo in the class name in previous versions.

 

Yes, this can be easily worked around.

 

You can use .NET Reflection to query a class for existing member names and invoke them accordingly.

 

Using this, you can check whether to use `ExternalDefinitionCreationOptions` or `ExternalDefinitonCreationOptions`.

 

Here is an example of a Multi-Version Add-in that uses .NET Reflection to implement a call to a piece of Revit 2013 API functionality in an add-in that is compiled using the Revit 2012 API:

 

http://thebuildingcoder.typepad.com/blog/2012/07/multi-version-add-in.html

 

You can also explore the use of Reflection in Magson Leone's Compatibilizar entre versões - API Compatibility Helper:

 

http://thebuildingcoder.typepad.com/blog/2015/05/compatibilizar-entre-vers%C3%B5es-api-compatibility...

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder