accessing shared parameter file using python

accessing shared parameter file using python

barasalah
Participant Participant
3,885 Views
3 Replies
Message 1 of 4

accessing shared parameter file using python

barasalah
Participant
Participant

i am trying to access shared parameter file to create or get parameters from file based on an excel sheet 

using PyRevit in Revit 2021

 

import Autodesk
from Autodesk.Revit.DB import *
doc = __revit__.ActiveUIDocument.Document
from Autodesk.Revit.ApplicationServices import Application
app=Application
group = 'test'
name = 'hitest'
type='Text'
visible=True
originalFile = app.SharedParametersFilename
tempFile = "C:\\SharedParameters.txt"
app.SharedParametersFilename=tempFile
defFile = app.OpenSharedParameterFile()
dg = defFile.Groups.Create(group)
d = dg.Definitions.Create(name, type, visible)

 

this is the code that i come up with by looking up api docs and its version of dynamo (github for dynamo version  )

attached SharedParameters file 

when i run the code in pyrevit i get the error 

 

AttributeError: static property 'SharedParametersFilename' of 'Application' can only be assigned to through a type, not an instance


Script Executor Traceback:
System.MissingMemberException: static property 'SharedParametersFilename' of 'Application' can only be assigned to through a type, not an instance
 at CallSite.Target(Closure , CallSite , Object , Object )
 at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
 at Microsoft.Scripting.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
 at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
 at PyRevitLabs.PyRevit.Runtime.IronPythonEngine.Execute(ScriptRuntime& runtime)

 

 

i don't understand the error and how to fix it thank you. 

0 Likes
Accepted solutions (1)
3,886 Views
3 Replies
Replies (3)
Message 2 of 4

jeremy_tammik
Alumni
Alumni
Accepted solution

Search for SharedParametersFilename in this sample:

 

https://thebuildingcoder.typepad.com/blog/2013/12/driving-cnc-fabrication-and-shared-parameters.html

 

You see that it is referenced on an Application instance retrieved from the document Application property:

  

    Application app = doc.Application;
 
    // Retrieve shared parameter file name
 
    string sharedParamsFileName
      = app.SharedParametersFilename;

 

That is different from what you are doing.

  

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

barasalah
Participant
Participant

thank you for the reply this fixed my problem 

0 Likes
Message 4 of 4

pedroengeletrica21
Community Visitor
Community Visitor

How did you manage to solve your problem I'm having the same problem

0 Likes