TypeError in Axis.Reset and CrossMember.ByParameters when using Python node in Dynamo

Hi there. I am using Dynamo with the Bridge Modeler addon and am using a Python node to try to attach a family on an axis. I have a complete working Dynamo Script but when trying to translate it into Python I am getting Type Errors in some of them. For example, I am trying to regenerate the axis with the placement and get this typeerror:
“TypeError: No method matches given arguments for Reset: (<class ‘NoneType’>, <class ‘NoneType’>, <class ‘NoneType’>, <class ‘NoneType’>, <class ‘SOFiSTiK.Dynamo.Infra.Alignmenmt.Placement’>, <class ‘NoneType’>, <class ‘NoneType’>, <class ‘NoneType’>, <class ‘NoneType’>, <class ‘NoneType’>, <class ‘NoneType’>,)[’ File “”, line 30, in \n’]”

and when I use the dynamo script with this Axis.Reset function and inputs from the same nodes I get no error message.

I tried adding code blocks with null variables in that node to see what happens and they were working and when using the function in Python I have tried both None and “null” or just putting in the axis and the placement to no avail. The function has 13 possible inputs and I have tried putting in the axis along with the placement at their corresponding positions and filling rest out with 11 Nones.

So the question is, could anyone help me with this, or does anyone know where to find the dynamo documentation for Axis.Reset and CrossMember.ByParameters? I tried following a link to the online library on the sofistik website but the link was dead. On the sofistik website there is also no information on Axis.Reset or CrossMember.ByParameters. I can find information on what arguments that you are supposed to put in in the dynamo program but seeing as they give me error messages I might be missing something.

Thanks in advance.

Hi,
The Visual Programming interface is designed to be used in the Dynamo Context. If you want to write a Python or C# Script, I recommend using the SBiM API directly as it is shown in the usage examples that you find next to the Dynamo Nodes.

C:\ProgramData\Autodesk\ApplicationPlugins\sofistik_bridge_modeler_2023.bundle\Contents\SDK\python

If I understand correctly, what you are trying to achieve is adding some Placements to an existing Axis and creating a CrossMember between them. The next code embedded in a Python Node in Dynamo could be used for it, of course the FamilySymbol, Placement Names and Variables should be adapted.

import sys
import clr
import math

from System import Guid
clr.AddReference("System.Collections")
from System.Collections.Generic import List

clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

# SBiM Library 
clr.AddReference("sof_sbim_api_six")
from SOFiSTiK.Infrastructure.API import *

# --------------------------------------------------------------------------------------
# Definitions
# --------------------------------------------------------------------------------------
PlacementAtStart = "PX.0"
PlacementAtEnd = "PX.1"
VariableName = "h"

# --------------------------------------------------------------------------------------
# Functions
# --------------------------------------------------------------------------------------

def m2ft(v) :
   return v / 0.3048

def CreatePlacement(name, station, globalRot = None, localRotX = None, localRotY = None, localRotZ = None) :
   pl = Placement()
   pl.Name = name
   pl.Station = m2ft(station)

   if globalRot != None :
      pl.GlobalRotation = globalRot

   if localRotX != None :
      pl.LocalRotationX = localRotX

   if localRotY != None :
      pl.LocalRotationY = localRotY

   if localRotZ != None :
      pl.LocalRotationZ = localRotZ
   
   return pl 

def AddPlacementToAxis(dynAxis) :
   # Create Entity
   ax = dynAxis.Entity

   # Placements
   pdata = ax.Placements
   if( not any (p for p in pdata if p.Name == PlacementAtStart )) :
      pdata.Add(CreatePlacement(PlacementAtStart, 30.0))

   if( not any (p for p in pdata if p.Name == PlacementAtEnd )) :  
      pdata.Add(CreatePlacement(PlacementAtEnd, 50.0))
      
   return ax

def CreateCrossMember(ax, eId, famType) :
   # create Cross Member
   c00 = CrossMember()
   c00.Id = eId.ToString()
   c00.Axis = ax
   c00.Orientation = PlacementOrientation.Vertical
   c00.RotationMode = PlacementRotationMode.PureRotation
   c00.CreateAtPlacements = False
   c00.ApplyLayoutForeachInterval = False
   c00.ApplyInterpolationLayout = True

   # Cross Member placements
   pdata = PlacementCollection()
   pl0 = next (p for p in ax.Placements if p.Name == PlacementAtStart )   
   pl1 = next (p for p in ax.Placements if p.Name == PlacementAtEnd )   
   pdata.Add(pl0)
   pdata.Add(pl1)
   c00.Placements = pdata

   # Distribution rule
   layout = SpacingRule()
   layout.Distance = m2ft(10.0)
   layout.Layout = SpacingLayout.FixedNumber
   layout.Quantity = 10
   layout.JustificationRule = SpacingJustification.Beginning
   layout.MeasurementType = SpacingMeasurementType.CurveParameter
   c00.Layout = layout

   # Cross Member parameters
   variableH = next (v for v in ax.Variables if v.Name == VariableName )
   parameters = ParameterCollection()

   p0 = ComponentParameter()
   p0.Name = "H00"
   p0.VariationType = ParameterVariationType.ReferenceToVariable
   p0.Expression = variableH
   p0.LocalStation = ComponentLocalStation()
   p0.LocalStation.MeasurementType = LocalStationMeasurementType.NormalizedParameter
   p0.LocalStation.MeasureSense = LocalStationMeasureStart.Beginning
   p0.LocalStation.NormalizedParameter = 0.0
   parameters.Add(p0)

   p1 = ComponentParameter()
   p1.Name = "H01"
   p1.Expression = variableH
   p1.VariationType = ParameterVariationType.ReferenceToVariable
   p1.LocalStation = ComponentLocalStation()
   p1.LocalStation.MeasurementType = LocalStationMeasurementType.NormalizedParameter
   p1.LocalStation.MeasureSense = LocalStationMeasureStart.Beginning
   p1.LocalStation.NormalizedParameter = 1.0
   parameters.Add(p1)

   c00.Parameters = parameters

   # set symbol (crossLinie_01)
   symbol = UnwrapElement(famType)
   c00.SetSymbol(symbol)

   return c00

# --------------------------------------------------------------------------------------
# Main
# --------------------------------------------------------------------------------------
TransactionManager.Instance.TransactionTaskDone()
doc = DocumentManager.Instance.CurrentDBDocument

# create main axis
ax = AddPlacementToAxis(IN[0])
cm = CreateCrossMember(ax, IN[1], IN[2])
#e00 = CrossMemberElement.Create(doc, cm)

OUT = [ax, cm]

Note that the modification/creation of Revit Elements as well of the Definition of the CrossMember’s Id is actually occurring outside the Python Script, this to avoid recreating the same Element each time the Script runs. It is also possible to Create the SBiM Elements inside the Python Script in case you need it, simply by : CrossMemberElement.Create(doc, cm).

1 Like

Thank you for the help! I will try this for a moment.

Thanks again for the help. I tried this and it seems to be working as well, and I also found out what caused my error message. Apparently the placements should have been formatted as a list for it to be working, and then I had no problems.