Skip to content

Commit

Permalink
ADD: annen step import
Browse files Browse the repository at this point in the history
  • Loading branch information
petrasvestartas committed Oct 10, 2024
1 parent 1353240 commit 44241bd
Show file tree
Hide file tree
Showing 4 changed files with 44,883 additions and 1 deletion.
52 changes: 52 additions & 0 deletions src/rhino/plugin/commands/w_dataset_annen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import Rhino
from Rhino.DocObjects import ObjectType
from wood_rui import wood_rui_globals, ensure_layer_exists

def import_step_file(step_file_path, new_layer_name):
# Step 1: Get the current object count before importing
before_import_objects = [obj.Id for obj in Rhino.RhinoDoc.ActiveDoc.Objects]

# Step 2: Use RhinoCommon to import the .STEP file via command
import_command = '-_Import "{}" _Enter _Pause'.format(step_file_path)
Rhino.RhinoApp.RunScript(import_command, False)

# Step 3: Get the new object count after importing
after_import_objects = [obj.Id for obj in Rhino.RhinoDoc.ActiveDoc.Objects]

# Step 4: Identify newly imported objects by comparing the IDs
new_object_ids = set(after_import_objects) - set(before_import_objects)
if new_object_ids:
last_imported_objects = [Rhino.RhinoDoc.ActiveDoc.Objects.FindId(obj_id) for obj_id in new_object_ids]

# Step 5: Ensure the new layer exists
layer_index = ensure_layer_exists("compas_wood", "annen", "surface")

# Step 6: Change the layer of each imported object
for obj in last_imported_objects:
obj.Attributes.LayerIndex = layer_index
obj.CommitChanges()

return last_imported_objects
else:
return None



if __name__ == "__main__":

dataset_name = "annen"
wood_rui_globals.init_data(dataset_name)

# Example usage:
step_file_path = r"C:\brg\2_code\compas_wood\src\rhino\plugin\shared\datasets\annen.stp"
new_layer_name = "compas_wood::annen::surface"
imported_objects = import_step_file(step_file_path, new_layer_name)

if imported_objects:
print(f"Successfully imported {len(imported_objects)} object(s) to layer '{new_layer_name}':")
for obj in imported_objects:
print(f"Object ID: {obj.Id}, Type: {obj.ObjectType}")
geometry = obj.Geometry
Rhino.RhinoDoc.ActiveDoc.Objects.Add(geometry)
else:
print("No objects were imported.")
1 change: 0 additions & 1 deletion src/rhino/plugin/commands/w_dataset_folded_plates.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,5 @@ def update():

if __name__ == "__main__":
dataset_name = "folded_plates"

wood_rui_globals.init_data(dataset_name)
command_line_input(dataset_name)
6 changes: 6 additions & 0 deletions src/rhino/plugin/libraries/wood_rui/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def init_data(self, name):
self.dataset[name] = {
"mesh": None, # INPUT meshes that are good inputs for generating polylines
"mesh_guid": None,
"surface": None, # INPUT surface that is good for generating meshes
"surface_guid": None,
"axes": None, # INPUT axis that is good for generating polylines
"axes_guid": None,
"polylines": [], # INPUT top and bottom outlines of a plate
"polylines_guid": [],
"insertion_lines": [], # USER lines for direction of a joint
Expand All @@ -55,6 +59,8 @@ def init_data(self, name):
from System.Drawing import Color
from .layer import ensure_layer_exists as create_layer
create_layer(self.plugin_name, name, "mesh", Color.Black)
create_layer(self.plugin_name, name, "surface", Color.Black)
create_layer(self.plugin_name, name, "axes", Color.Black)
create_layer(self.plugin_name, name, "polylines", Color.Red)
create_layer(self.plugin_name, name, "insertion", Color.Blue)
create_layer(self.plugin_name, name, "joint_types", Color.Gray)
Expand Down
Loading

0 comments on commit 44241bd

Please sign in to comment.