-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #272 from gramaziokohler/Surface_model_show_beam_type
Surface_model_show_beam_type
- Loading branch information
Showing
4 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/compas_timber/ghpython/components/CT_ShowSurfaceModelBeamTypes/code.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from compas.scene import Scene | ||
from ghpythonlib.componentbase import executingcomponent as component | ||
from Grasshopper.Kernel.GH_RuntimeMessageLevel import Warning | ||
from System.Windows.Forms import ToolStripSeparator | ||
|
||
from compas_timber.ghpython.ghcomponent_helpers import rename_gh_output | ||
|
||
|
||
class SurfaceModelJointRule(component): | ||
def __init__(self): | ||
super(SurfaceModelJointRule, self).__init__() | ||
self.beam_type = None | ||
if ghenv.Component.Params.Output[0].NickName == "type": | ||
self.joint_type = None | ||
else: | ||
self.beam_type = ghenv.Component.Params.Output[0].NickName | ||
|
||
def RunScript(self, model): | ||
self.names = set(element.attributes.get("category") for element in model.elements()) | ||
self.names.remove(None) | ||
if not self.beam_type: | ||
ghenv.Component.Message = "Select beam type from context menu (right click)" | ||
self.AddRuntimeMessage(Warning, "Select beam type from context menu (right click)") | ||
return None | ||
else: | ||
ghenv.Component.Message = self.beam_type | ||
scene = Scene() | ||
for beam in model.beams: | ||
if beam.attributes["category"] == self.beam_type: | ||
scene.add(beam.geometry) | ||
return scene.draw() | ||
|
||
def AppendAdditionalMenuItems(self, menu): | ||
if not self.RuntimeMessages(Warning): | ||
menu.Items.Add(ToolStripSeparator()) | ||
for name in self.names: | ||
item = menu.Items.Add(name, None, self.on_item_click) | ||
if self.beam_type and name == self.beam_type: | ||
item.Checked = True | ||
|
||
def on_item_click(self, sender, event_info): | ||
self.beam_type = str(sender) | ||
rename_gh_output(self.beam_type, 0, ghenv) | ||
ghenv.Component.ExpireSolution(True) |
Binary file added
BIN
+863 Bytes
src/compas_timber/ghpython/components/CT_ShowSurfaceModelBeamTypes/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions
26
src/compas_timber/ghpython/components/CT_ShowSurfaceModelBeamTypes/metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "ShowSurfaceModelBeamTypes", | ||
"nickname": "ShowBeamType", | ||
"category": "COMPAS Timber", | ||
"subcategory": "Show", | ||
"description": "allows user to visualize beam types in surface model.", | ||
"exposure": 2, | ||
"ghpython": { | ||
"isAdvancedMode": true, | ||
"iconDisplay": 0, | ||
"inputParameters": [ | ||
{ | ||
"name": "Model", | ||
"description": "Model object.", | ||
"typeHintID": "none", | ||
"scriptParamAccess": 0 | ||
} | ||
], | ||
"outputParameters": [ | ||
{ | ||
"name": "type", | ||
"description": "beam type to visualize." | ||
} | ||
] | ||
} | ||
} |