Skip to content

Commit

Permalink
General Obj Edit Functions
Browse files Browse the repository at this point in the history
  • Loading branch information
rpakishore committed Mar 8, 2024
1 parent a0f541c commit 3d8e352
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 3 deletions.
21 changes: 21 additions & 0 deletions documentation/Layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ sap.Model.set_logs('Add this comment') #Adds user comments/logs

Collection of methods and attributes that apply changes to elements in the model

```python
object = sap.Object
object.move_selected(dx=0.5, dy=0, dz=1.0) #Move selected object
object.copy(dx=0.5, dy=0, dz=0, num=10)#copy selected object

#Mirror and create object
from ak_sap import Coord
pt1 = Coord(x=10, y=20, z=0)
p2 = Coord(x=10, y=30, z=0)
object.mirror(plane='Z', coord1=pt1, coord2=pt2) #Mirror replicate selected obj.
```

### 2.2.1. Point

Manipulate Point Elements
Expand All @@ -74,6 +86,15 @@ points.all() #Lists all defined points
points.rename(old_name='1', new_name='1_1') #Rename point
points.check_obj_legal(name='1') #Asserts point's existance
points.delete(name='1') #Delete point

#Manipilate
points.deselect_all() #Deselect all points
points.select(name='1') #Select a single point
points.align(axis='Z', ordinate = 100) #Align selected points
points.deselect(name='1') #Deselect a single point

points.merge(tolerance=2) #Merge points that are within tol
points.change_coord(name='1', x=0, y=0, z=0)#Change point coordinate
```

### 2.2.2. Frames
Expand Down
28 changes: 27 additions & 1 deletion documentation/Usage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,23 @@
"### Element"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"object = sap.Object\n",
"object.move_selected(dx=0.5, dy=0, dz=1.0) #Move selected object\n",
"object.copy(dx=0.5, dy=0, dz=0, num=10)#copy selected object\n",
"\n",
"#Mirror and create object\n",
"from ak_sap import Coord\n",
"pt1 = Coord(x=10, y=20, z=0)\n",
"p2 = Coord(x=10, y=30, z=0)\n",
"object.mirror(plane='Z', coord1=pt1, coord2=pt2) #Mirror replicate selected obj."
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -114,7 +131,16 @@
"points.all() #Lists all defined points\n",
"points.rename(old_name='1', new_name='1_1') #Rename point\n",
"points.check_obj_legal(name='1') #Asserts point's existance\n",
"points.delete(name='1') #Delete point"
"points.delete(name='1') #Delete point\n",
"\n",
"#Manipilate\n",
"points.deselect_all() #Deselect all points\n",
"points.select(name='1') #Select a single point\n",
"points.align(axis='Z', ordinate = 100) #Align selected points\n",
"points.deselect(name='1') #Deselect a single point\n",
"\n",
"points.merge(tolerance=2) #Merge points that are within tol\n",
"points.change_coord(name='1', x=0, y=0, z=0)#Change point coordinate"
]
},
{
Expand Down
29 changes: 28 additions & 1 deletion src/ak_sap/Object/obj.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from typing import Literal

from .point import Point
from .frame import Frame
from ak_sap.utils.decorators import smooth_sap_do
from ak_sap.misc import Coord

class Object:
def __init__(self, mySapObject) -> None:
self.__mySapObject = mySapObject
self.__EditGeneral = mySapObject.SapModel.EditGeneral
self.Point = Point(mySapObject=mySapObject)
self.Frame = Frame(mySapObject=mySapObject)

Expand All @@ -17,4 +21,27 @@ def move_selected(self, dx: float, dy: float, dz: float) -> bool:
dy (float): y offsets
dz (float): z offsets
"""
self.__mySapObject.SapModel.EditGeneral.Move(dx, dy, dz)
self.__EditGeneral.Move(dx, dy, dz)

@smooth_sap_do
def copy(self, dx: float, dy: float, dz: float, num: int) -> tuple:
"""linearly replicates selected objects.
Args:
dx (float): x offset
dy (float): y offset
dz (float): z offset
num (int): number of times the selected objects are to be replicated.
"""
return self.__EditGeneral.ReplicateLinear(dx, dy, dz, num)

@smooth_sap_do
def mirror(self, plane: Literal['X', 'Y', 'Z'], coord1: Coord, coord2: Coord):
"""mirror replicates selected objects
Args:
plane (Literal['X', 'Y', 'Z']): parallel to this plane
coord1 (Coord), coord2 (Coord): define the intersection of the mirror plane with the perp. plane
"""
axis = ['Z', 'X', 'Y'].index(plane.upper().strip()) + 1
return self.__EditGeneral.ReplicateMirror(axis, *coord1.as_tuple(), *coord2.as_tuple())
2 changes: 1 addition & 1 deletion src/ak_sap/Object/point.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def merge(self, tolerance: float) -> tuple:
return self.__EditPoint.Merge(tolerance)

@smooth_sap_do
def change_coordinate(self, name: str, x: float, y: float, z: float) -> bool:
def change_coord(self, name: str, x: float, y: float, z: float) -> bool:
"""changes the coordinates of a specified point object.
Args:
Expand Down
1 change: 1 addition & 0 deletions src/ak_sap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from ak_sap.utils.logger import log
from ak_sap.wrapper import Sap2000Wrapper
from ak_sap.misc import Coord

#log = Log()

Expand Down
1 change: 1 addition & 0 deletions src/ak_sap/misc/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .coordinates import Coord
10 changes: 10 additions & 0 deletions src/ak_sap/misc/coordinates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from dataclasses import dataclass

@dataclass
class Coord:
x: float
y: float
z: float

def as_tuple(self) -> tuple[float]:
return (self.x, self.y, self.z)

0 comments on commit 3d8e352

Please sign in to comment.