- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone,
I am developing a Python script using the Revit API to insert multiple electrical outlets into selected walls and automatically assign them to electrical circuits. However, I am encountering a problem when defining the electrical parameters of the inserted outlets. Specifically, the voltage and number of phases parameters are being set to 0 after creating the circuit, indicating that the electrical data is not being assigned correctly.
Project Characteristics:
- Outlet Height: 1.10 meters
- Number of Outlets: Defined by the user (e.g., 1)
- Interval Between Outlets: Defined by the user or uses the total length of the wall
- Wall Face: Front or Rear
- Electrical Parameters:
- Apparent Power (VA): 1000 VA (example)
- Power Factor (cos φ): 0.8 (example)
- Voltage (V): 220 V (example)
- Number of Phases: 1 (example)
Detailed Description of the Problem:
When executing the script, the outlets are correctly inserted at the desired positions on the selected wall. However, when attempting to set the electrical parameters (voltage and number of phases) on the family instance and the electrical circuit, these values are not being assigned correctly and appear as 0 in Revit. I believe the issue is related to how the string parameters are being defined in the code.
Error Message Received:
Erro ao inserir tomada: global name 'string' is not defined
Relevant Code Snippets:
Below are the sections of my script related to defining the electrical parameters and creating the electrical circuit. I believe the problem lies in these parts of the code.
# Defining the electrical parameters on the family instance # Apparent Power (VA) parametro_S = tomada_instancia.LookupParameter('Potência Aparente (VA)') if parametro_S and parametro_S.StorageType == StorageType.Double: parametro_S.Set(potencia_aparente) # Power Factor parametro_cos_phi = tomada_instancia.LookupParameter('Fator de Potência') if parametro_cos_phi and parametro_cos_phi.StorageType == StorageType.Double: parametro_cos_phi.Set(fator_potencia) # Voltage (V) parametro_tensao = tomada_instancia.LookupParameter('Tensão (V)') if parametro_tensao and parametro_tensao.StorageType == StorageType.Double: parametro_tensao.Set(tensao) # Number of Phases parametro_fases = tomada_instancia.LookupParameter('N° de Fases') if parametro_fases and parametro_fases.StorageType == StorageType.Integer: parametro_fases.Set(numero_fases) # Correction Added: Correctly setting string parameters # For example, setting the instance comment parametro_comentario = tomada_instancia.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS) if parametro_comentario and parametro_comentario.StorageType == StorageType.String: parametro_comentario.Set("") # Uses an empty string instead of string.Empty
def criar_circuito_eletrico(tomadas_inseridas, tensao, numero_fases, parametros_elet): """Creates an electrical circuit with the inserted outlets and adjusts the parameters.""" potencia_aparente, fator_potencia, _, _ = parametros_elet try: with revit.Transaction("Criar Circuito Elétrico"): # Get the ElementIds of the outlets tomadas_ids = [t.Id for t in tomadas_inseridas] # Create a list of ElementIds elementos_ids = List[ElementId](tomadas_ids) # Define the electrical system type (PowerCircuit) sistema_tipo = ElectricalSystemType.PowerCircuit # Create the electrical circuit circuito = ElectricalSystem.Create(doc, elementos_ids, sistema_tipo) if circuito: forms.alert("Circuito elétrico criado com sucesso.", exitscript=False) # Correction Added: Correctly setting string parameters on the circuit # For example, setting the circuit comment parametro_comentario = circuito.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS) if parametro_comentario and parametro_comentario.StorageType == StorageType.String: parametro_comentario.Set("") # Uses an empty string instead of string.Empty # Set the voltage and number of phases of the circuit based on the provided values voltage_param = circuito.get_Parameter(BuiltInParameter.RBS_ELEC_VOLTAGE) if voltage_param and voltage_param.StorageType == StorageType.Double: voltage_param.Set(tensao) number_of_poles_param = circuito.get_Parameter(BuiltInParameter.RBS_ELEC_NUMBER_OF_POLES) if number_of_poles_param and number_of_poles_param.StorageType == StorageType.Integer: number_of_poles_param.Set(numero_fases) # Set the Apparent Power and Power Factor on the circuit apparent_load_param = circuito.get_Parameter(BuiltInParameter.RBS_ELEC_APPARENT_LOAD) if apparent_load_param and apparent_load_param.StorageType == StorageType.Double: apparent_load_param.Set(potencia_aparente) power_factor_param = circuito.get_Parameter(BuiltInParameter.RBS_ELEC_POWER_FACTOR) if power_factor_param and power_factor_param.StorageType == StorageType.Double: power_factor_param.Set(fator_potencia) # Regenerate the document to update calculated parameters doc.Regenerate() except Exception as e: tb = traceback.format_exc() forms.alert("Erro ao criar circuito elétrico:\n{0}".format(tb))
Attempts to Solve:
- Replacing string.Empty with "": Initially, I tried using string.Empty to set string parameters but received the error global name 'string' is not defined. Subsequently, I replaced it with "" (empty string) as suggested by ChatGPT, but the parameters still return 0.
- Checking Storage Type: I ensured that the parameters I am trying to set correspond to the expected StorageType (Double for voltage and power, Integer for the number of phases).
Questions:
- Why are the electrical parameters for voltage and number of phases being set to 0 in Revit after creating the circuit?
- I am using empty strings ("") to set string parameters. Is this correct, or is there another recommended way to avoid null values?
- Are there any specific details in the Revit API that I should consider when setting electrical parameters for families and circuits?
Solved! Go to Solution.