Skip to content

Error with section_id for "rigid" member type in members.py #2

@Jeroen124

Description

@Jeroen124

Problem

In the members.py file, the following code snippet is provided:

class Members(ModelCollectionComponent):
    """Creates an instance of the SkyCiv Members class.
    """

    def add(
        self,
        node_A: int,
        node_B: int,
        section_id: int,
        fixity_A: str = 'FFFFFF',
        fixity_B: str = 'FFFFFF',
        type: Literal["normal", "normal_continuous",
                      "cable", "rigid"] = 'normal',
        cable_length: float = None

The section_id parameter is currently required and not optional. However, when attempting to create a member with the type set to "rigid", the solver returns the following error:

"/members/16/section_id should be null",
It seems that for the "rigid" member type, section_id should be null, but the current implementation does not accommodate this requirement.

Possible solutions

  1. Making section_id Optional
    In this solution, we modify the add method to make the section_id parameter optional by giving it a default value of None. We then add logic to ensure that section_id is provided unless the member type is rigid. This approach directly addresses the requirement by conditionally enforcing the need for section_id.
class Members(ModelCollectionComponent):
    """Creates an instance of the SkyCiv Members class.
    """

    def add(
        self,
        node_A: int,
        node_B: int,
        section_id: Optional[int] = None,
        fixity_A: str = 'FFFFFF',
        fixity_B: str = 'FFFFFF',
        type: Literal["normal", "normal_continuous",
                      "cable", "rigid"] = 'normal',
        cable_length: float = None
    ) -> int:
        """Create a member with the next available ID.

        Args:
            node_A (int): The ID of the node at the beginning of the member.
            node_B (int): The ID of the node at the end of the member.
            section_id (int, optional): The ID of the section to apply to the member.
            fixity_A (str, optional): See docs for restraint code. https://skyciv.com/api/v3/docs/s3d-model#restraint-code. Defaults to 'FFFFFF'.
            fixity_B (str, optional): See docs for restraint code. https://skyciv.com/api/v3/docs/s3d-model#restraint-code. Defaults to 'FFFFFF'.
            type (str, optional): The type of member. Defaults to 'normal'. {"normal" | "normal_continuous" | "cable" | "rigid"}.
            cable_length (float, optional): Required only when type = cable. Defaults to None.

        Returns:
            int: The ID of the newly created member.
        """
        if type != 'rigid' and section_id is None:
            raise ValueError("section_id must be provided unless the member type is 'rigid'.")
  1. Overwriting section_id for Rigid Members
    In this approach, section_id remains a required parameter in the method signature, but we add a check within the method to overwrite section_id with None if the member type is rigid. This ensures that even if a section_id is provided, it will be ignored for rigid members.
class Members(ModelCollectionComponent):
    """Creates an instance of the SkyCiv Members class.
    """

    def add(
        self,
        node_A: int,
        node_B: int,
        section_id: int,
        fixity_A: str = 'FFFFFF',
        fixity_B: str = 'FFFFFF',
        type: Literal["normal", "normal_continuous",
                      "cable", "rigid"] = 'normal',
        cable_length: float = None
    ) -> int:
        """Create a member with the next available ID.

        Args:
            node_A (int): The ID of the node at the beginning of the member.
            node_B (int): The ID of the node at the end of the member.
            section_id (int): The ID of the section to apply to the member.
            fixity_A (str, optional): See docs for restraint code. https://skyciv.com/api/v3/docs/s3d-model#restraint-code. Defaults to 'FFFFFF'.
            fixity_B (str, optional): See docs for restraint code. https://skyciv.com/api/v3/docs/s3d-model#restraint-code. Defaults to 'FFFFFF'.
            type (str, optional): The type of member. Defaults to 'normal'. {"normal" | "normal_continuous" | "cable" | "rigid"}.
            cable_length (float, optional): Required only when type = cable. Defaults to None.

        Returns:
            int: Required only when type = cable.
        """
        next_index = next_object_key(self)
        element_ids = self.get_member_ids_from_nodes_ids(node_A, node_B)

        if element_ids is not None:
            print(
                'There is more than one member with the same end nodes. Ensure they have different offsets.')

        # Set section_id to None if type is 'rigid'
        if type == 'rigid':
            section_id = None

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions