Is there a way to call an existing detail view that already exists in a template file? This is the exact functionality I need, but don’t want the user input to select the objects. Also, can this be identified with the Object name or must it be the GUID (see picture). Secondly, what are the numbers in the parenthesis for the ID?
@Me_Dave - I’ve moved your question to a new topic.
You might try to better explain what you are trying to do, and why, as your question isn’t clear to me.
Thanks,
– Dale
thanks for moving this to the appropriate location.
I am trying to create a python script that would find an existing detail view (preferably by Object Name) and hide an existing layer that was created within the script. I’m not really confident in my coding skills and am stumbling my way through this. Here is the mess of a code I have so far… I am trying to hide the “Pearl Diameter” layer only within the existing detail view “Detail-Perspective” (object name). I tried using the GUID highlighted in the image at the start of the thread, but anytime I included the numbers in parentheses, but it kicks an error that there are too many characters for GUID. I removed the extra numbers to solve the error, but the layer isn’t hidden in the detail view.
import sys
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino, System
import System.Guid
import Rhino.DocObjects as rhobj
__commandname__ = "PearlAutoDim"
# RunCommand is the called when the user enters the command name in Rhino.
# The command name is defined by the filname minus "_cmd.py"
def RunCommand( is_interactive ):
def SetGhostedObjDisplayModeAllViewports(objIDs):
if isinstance(objIDs,System.Guid): objIDs=[objIDs]
modeName="Ghosted"
dModes = Rhino.Display.DisplayModeDescription.GetDisplayModes()
modeNames=[dMode.LocalName for dMode in dModes if not dMode.PipelineLocked]
index=-1
for i in range(len(modeNames)):
if modeName==modeNames[i]:
index=i ; break
if index==-1: return
vIDs=[view.ActiveViewportID for view in sc.doc.Views]
for vID in vIDs:
for objID in objIDs:
objRef=sc.doc.Objects.Find(objID)
attr = objRef.Attributes
attr.SetDisplayModeOverride(dModes[i], vID)
sc.doc.Objects.ModifyAttributes(objID, attr, False)
#Number_Format = "{0:0<2.2f}"
class glassbeadDimensions:
msg="Pick objects for bounding box"
err_msg="Bounding box creation failed."
objs = rs.GetObjects(msg,preselect=True)
global bb
bb = rs.BoundingBox(objs)
#prec = sc.doc.DistanceDisplayPrecision
#tol = sc.doc.ModelAbsoluteTolerance
#sc.doc.ModelUnitSystem
#unit_sys = sc.doc.ModelUnitSystem
#unit_name=sc.doc.GetUnitSystemName(True,False,True,True)
global XL
XL = bb[1].DistanceTo(bb[0])
global YL
YL = bb[3].DistanceTo(bb[0])
global ZL
ZL = bb[4].DistanceTo(bb[0])
### Get the number of decimal places from the document settings
#decimal_places = rs.GetDocumentData("ROUND_DECIMALS")
#dimstyle = rs.CurrentDimStyle()
#precision = rs.DimStyleLinearPrecision(dimstyle)
#dec_places = rhobj.DimensionStyle.LengthResolution
#trailing_zeros = rhobj.DimensionStyle.LengthFactor.tr
# Get current dimension style
##current_style = rs.CurrentDimStyle()
# Get number of decimal places and trailing zeros from dimension style
dimstyle = rs.CurrentDimStyle()
precision = rs.DimStyleLinearPrecision(dimstyle)
### Round the number to the specified number of decimal places
rounded_Height = round(ZL, precision)
formatted_Height = "{0:.2f}".format(rounded_Height).zfill(4)
converted_Height = str(formatted_Height)
#User input for Hole Diameter
global holeDiameter
holeDiameter = input("Set Hole Diameter.")
convertHoleDiamNum = float(holeDiameter)
formattedHoleDiameter = "{0:.2f}".format(convertHoleDiamNum).zfill(4)
HoleDiameter = str(formattedHoleDiameter)
rs.SetDocumentData("PearlDims", "Hole Diameter", HoleDiameter)
minHoleTolerance=input("Set Min Tolerance for Hole Diameter.")
decimalMinHoleTolerance = float(minHoleTolerance)
formattedMinHoleTolerance = "{0:.2f}".format(decimalMinHoleTolerance).zfill(4)
converted_minHoleTolerance = str(formattedMinHoleTolerance)
rs.SetDocumentData("PearlDims", "minHoleTolerance", converted_minHoleTolerance)
maxHoleTolerance=input("Set Max Tolerance for Hole Diameter.")
decimalMaxHoleTolerance = float(maxHoleTolerance)
formattedMaxHoleTolerance = "{0:.2f}".format(decimalMaxHoleTolerance).zfill(4)
converted_maxHoleTolerance = str(formattedMaxHoleTolerance)
rs.SetDocumentData("PearlDims", "maxHoleTolerance", converted_maxHoleTolerance)
holeDepth=input("Set percentage of hole depth.")
decimalHoldDepth = holeDepth/100
minHoleDepthTolerance = input("Set Min Tolerance for Hole Depth.")
decimalMinHoleDepthTolerance = float(minHoleDepthTolerance)
formattedMinHoleDepthTolerance = "{0:.2f}".format(decimalMinHoleDepthTolerance).zfill(4)
converted_minHoleDepthTolerance = str(formattedMinHoleDepthTolerance)
rs.SetDocumentData("PearlDims", "minHoleTolerance", converted_minHoleDepthTolerance)
maxHoleDepthTolerance = input("Set Max Tolerance for Hole Depth.")
decimalMaxHoleDepthTolerance = float(maxHoleDepthTolerance)
formattedMaxHoleDepthTolerance = "{0:.2f}".format(decimalMaxHoleDepthTolerance).zfill(4)
converted_maxHoleDepthTolerance = str(formattedMaxHoleDepthTolerance)
rs.SetDocumentData("PearlDims", "minHoleTolerance", converted_maxHoleDepthTolerance)
#print(sys.version)
base = Rhino.Geometry.Point3d((bb[4]+bb[6])/2)
z_Offset = ZL*decimalHoldDepth
baseOffset = Rhino.Geometry.Point3d(base.X,base.Y,base.Z)
radius = holeDiameter/2
fillet_Radius = radius*.95
global depth
depth = Rhino.Geometry.Point3d(base.X,base.Y,base.Z-z_Offset)
depthOffset = Rhino.Geometry.Point3d(depth.X,depth.Y,depth.Z+radius)
pipePath = rs.AddLine(depth,baseOffset)
arrDomain = rs.CurveDomain(pipePath)
holeCutter = rs.AddPipe(pipePath,0,radius,blend_type=0,cap=0,fit=False)
newObject = rs.BooleanDifference(objs,holeCutter,True)
rs.DeleteObject(pipePath)
global bb2
bb2 = rs.BoundingBox(newObject)
rs.SetDocumentData("PearlDims", "Height", converted_Height)
rounded_Length = round(YL, precision)
formatted_Length = "{0:.2f}".format(rounded_Length).zfill(4)
converted_Length = str(formatted_Length)
rs.SetDocumentData("PearlDims", "Length", converted_Length)
rounded_Diameter = round(XL, precision)
formatted_Diameter = "{0:.2f}".format(rounded_Diameter).zfill(4)
converted_Diameter = str(formatted_Diameter)
rs.SetDocumentData("PearlDims", "Diameter", converted_Diameter)
def SizeHeight():
rs.AddLayer("Pearl Height")
rs.CurrentLayer("Pearl Height")
origin = Rhino.Geometry.Point3d((bb2[5]+bb2[4])/2)
offset = Rhino.Geometry.Point3d((bb2[0]+bb2[1])/2)
pt = Rhino.Geometry.Point3d((XL*-1),0,0)
plane = Rhino.Geometry.Plane.WorldZX
plane.Origin = origin
rc, u, v = plane.ClosestParameter(origin)
ext1 = Rhino.Geometry.Point2d(u,v)
rc, u, v = plane.ClosestParameter(offset)
ext2 = Rhino.Geometry.Point2d(u,v)
rc, u, v = plane.ClosestParameter(pt)
linePt = Rhino.Geometry.Point2d(u,v)
dimensionH = Rhino.Geometry.LinearDimension(plane, ext1, ext2, linePt)
if sc.doc.Objects.AddLinearDimension(dimensionH)!=System.Guid.Empty:
sc.doc.Views.Redraw()
return Rhino.Commands.Result.Success
return Rhino.Commands.Result.Failure
SizeHeight()
def SizeDiameter():
rs.AddLayer("Pearl Diameter")
rs.CurrentLayer("Pearl Diameter")
origin = Rhino.Geometry.Point3d((bb[7]+bb[4])/2)
offset = Rhino.Geometry.Point3d((bb[5]+bb[6])/2)
pt = Rhino.Geometry.Point3d(0,(YL),0)
plane = Rhino.Geometry.Plane.WorldXY
plane.Origin = origin
rc, u, v = plane.ClosestParameter(origin)
ext1 = Rhino.Geometry.Point2d(u,v)
rc, u, v = plane.ClosestParameter(offset)
ext2 = Rhino.Geometry.Point2d(u,v)
rc, u, v = plane.ClosestParameter(pt)
linePt = Rhino.Geometry.Point2d(u,v)
dimensionW = Rhino.Geometry.LinearDimension(plane, ext1, ext2, linePt)
if sc.doc.Objects.AddLinearDimension(dimensionW)!=System.Guid.Empty:
sc.doc.Views.Redraw()
return Rhino.Commands.Result.Success
return Rhino.Commands.Result.Failure
SizeDiameter()
#User input for Diameter/Diameter Tolerances
minDiameterTolerance=input("Set Min Tolerance for Diameter.")
decimalMinDiameterTolerance = float(minDiameterTolerance)
formattedMinDiameterTolerance = "{0:.2f}".format(decimalMinDiameterTolerance).zfill(4)
converted_minDiameterTolerance = str(formattedMinDiameterTolerance)
rs.SetDocumentData("PearlDims", "minDiameterTolerance", converted_minDiameterTolerance)
maxDiameterTolerance=input("Set Max Tolerance for Diameter.")
decimalMaxDiameterTolerance = float(minDiameterTolerance)
formattedMaxDiameterTolerance = "{0:.2f}".format(decimalMaxDiameterTolerance).zfill(4)
converted_maxDiameterTolerance = str(formattedMaxDiameterTolerance)
rs.SetDocumentData("PearlDims", "maxDiameterTolerance", converted_maxDiameterTolerance)
#User input for Height Tolerances.
minHeightTolerance=input("Set Min Tolerance for Height.")
decimalMinHeightTolerance = float(minHeightTolerance)
formattedMinHeightTolerance = "{0:.2f}".format(decimalMinHeightTolerance).zfill(4)
converted_minHeightTolerance = str(formattedMinHeightTolerance)
rs.SetDocumentData("PearlDims", "minHeightTolerance", converted_minHeightTolerance)
maxHeightTolerance=input("Set Max Tolerance for Height.")
decimalMaxHeightTolerance = float(maxHeightTolerance)
formattedMaxHeightTolerance = "{0:.2f}".format(decimalMaxHeightTolerance).zfill(4)
converted_maxHeightTolerance = str(formattedMaxHeightTolerance)
rs.SetDocumentData("PearlDims", "maxHeightTolerance", converted_maxHeightTolerance)
def HoleDiameterDim():
rs.AddLayer("Hole Diameter")
rs.CurrentLayer("Hole Diameter")
origin = Rhino.Geometry.Point3d(0,(holeDiameter/2)*-1,0)
offset = Rhino.Geometry.Point3d(0,(holeDiameter/2),0)
pt = Rhino.Geometry.Point3d(0,0,(ZL)*1.5)
plane = Rhino.Geometry.Plane.WorldYZ
plane.Origin = origin
rc, u, v = plane.ClosestParameter(origin)
ext1 = Rhino.Geometry.Point2d(u,v)
rc, u, v = plane.ClosestParameter(offset)
ext2 = Rhino.Geometry.Point2d(u,v)
rc, u, v = plane.ClosestParameter(pt)
linePt = Rhino.Geometry.Point2d(u,v)
dimensionW = Rhino.Geometry.LinearDimension(plane, ext1, ext2, linePt)
if sc.doc.Objects.AddLinearDimension(dimensionW)!=System.Guid.Empty:
sc.doc.Views.Redraw()
return Rhino.Commands.Result.Success
return Rhino.Commands.Result.Failure
HoleDiameterDim()
def HoleDepthDim():
rs.AddLayer("Hole Depth")
rs.CurrentLayer("Hole Depth")
origin = origin = Rhino.Geometry.Point3d((bb2[4]+bb2[6])/2)
offset = depth
pt = Rhino.Geometry.Point3d(0,YL*1.5,0)
plane = Rhino.Geometry.Plane(origin,offset,pt)
plane.Origin = origin
rc, u, v = plane.ClosestParameter(origin)
ext1 = Rhino.Geometry.Point2d(u,v)
rc, u, v = plane.ClosestParameter(offset)
ext2 = Rhino.Geometry.Point2d(u,v)
rc, u, v = plane.ClosestParameter(pt)
linePt = Rhino.Geometry.Point2d(u,v)
dimensionW = Rhino.Geometry.LinearDimension(plane, ext1, ext2, linePt)
dimensionW.Aligned = True
if sc.doc.Objects.AddLinearDimension(dimensionW)!=System.Guid.Empty:
sc.doc.Views.Redraw()
return Rhino.Commands.Result.Success
return Rhino.Commands.Result.Failure
HoleDepthDim()
def SetDetailsToPlastic(debug):
# Find the Plastic display mode
display_mode = Rhino.Display.DisplayModeDescription.FindByName("Plastic")
if display_mode:
DebugPrint(display_mode, debug)
# Get the GUID of the "Detail-Perspective" page view
page_view_guid = System.Guid("463cbf67-d054-43ab-9327-4cd2d7777cec")
page_view = Rhino.RhinoDoc.ActiveDoc.Views.Find(page_view_guid)
if page_view is None:
print("Detail-Perspective page view not found")
return
# Get all of the page view's details
details = page_view.GetDetailViews()
if details:
# Process each page view detail
for detail in details:
DebugPrint(detail, debug)
# If the detail's display mode is not Plastic...
if detail.Viewport.DisplayMode.Id != display_mode.Id:
# ...set it to Plastic.
detail.Viewport.DisplayMode = display_mode
detail.CommitViewportChanges()
# Redraw the page
page_view.Redraw()
def DebugPrint(object, debug):
if object and debug:
print object
SetDetailsToPlastic(True)
def toggle_layer_visibility():
# Get the active document
doc = Rhino.RhinoDoc.ActiveDoc
# Get the GUID of the "Detail-Perspective" page view
page_view_guid = System.Guid("463cbf67-d054-43ab-9327-4cd2d7777cec")
page_view = doc.Views.Find(page_view_guid)
if page_view is None:
print("Detail-Perspective page view not found")
return
# Get the layer index for the "Pearl Diameter" layer
layer_id = Rhino.RhinoDoc.ActiveDoc.Layers.FindByFullPath("::Pearl Diameter", -1)
if layer_id == System.Guid.Empty:
print("Pearl Diameter layer not found")
return
# Toggle the visibility of the layer in the page view
layer_table = page_view.MainViewport.LayerTable
layer_table.SetLayerVisible(layer_id, not layer_table[layer_id].IsVisible)
# Update the page view in the document
doc.Views.Redraw()
doc.Views.ActiveView.ActiveViewport.ZoomToScreenRect(page_view.MainViewport.Bounds, True)
# Call the function
toggle_layer_visibility()
uh oh, this looks like even more of a mess than my screen. sorry.
With this much code, you could upload a the source file…
– Dale
sure. I’m sure this doesn’t need explaining, but this is the result of someone trying to do something they don’t know how to do. It works up to a point (layer visibility), but I’m certain it’s far from correct/efficient.
PearlAutoDim_cmd.py (15.8 KB)
What is your end goal?
To hide the layer “Pearl Diameter” only in the detail view with the Object Name: “Detail-Perspective” (GUID 463cbf67-d054-43ab-9327-4cd2d7777cec). I’ve tried stumbling through various ways to accomplish this the but the layer is always visible in the detail view, it’s never hidden.
The entire script is a bit much. Maybe someone could type some sample code for how to hide a specific layer in a specific detail view using python? I just can’t find any examples online.
Hi @Me_Dave,
below sample script will hide a layer named “Layer 02” on the page named “Page 1” but only in the detail named “MyDetail”:
import Rhino
import scriptcontext
import rhinoscriptsyntax as rs
def HideLayerInDetail(page_name=None, detail_name=None, layer_path=None):
if not page_name or not detail_name or not layer_path: return
index = scriptcontext.doc.Layers.FindByFullPath(layer_path, - 1)
if index < 0: print "Layer: {} not found".format(layer_path); return
layer = scriptcontext.doc.Layers[index]
for page in scriptcontext.doc.Views.GetPageViews():
if page.PageName == page_name:
for detail in page.GetDetailViews():
if detail.Name == detail_name:
layer.SetPerViewportVisible(detail.Viewport.Id, False)
scriptcontext.doc.Views.Redraw()
HideLayerInDetail("Page 1", "MyDetail", "Layer 02")
You might try this with below example file, the perspective detail is the one named “MyDetail”…
HideLayerInDetail.3dm (55.1 KB)
_
c.
Thank you for the example script! This was very helpful!
Hi @clement - this inspires the question of whether this can be expanded so that all layers can be defaulted to off/locked in newly created Details - including layers created after any details, themselves
This would make it so new geo (eg. Section Tools geo) wouldn’t show up in previously created nice, neat details.
Pushing further - all new Geo at all (regardless of layer) would be banished from those details.
Rh8 seems to be working on this with the new visibility buttons, but this wld be a major time-saver in RH7. Thoughts?
Hi @Alan_Farkas,
i like the idea and often find myself in the situation that i have setup one detail view and later add layers or objects to the document which i do not want to display in the “finished” detail. However, having new objects not show up in any detail by default would imho be kind of irritating and could lead to confusion.
A script (for V7) could probably find out which objects have been added to a document after the detail has been added, but only during runtime. Once the document is closed and reopened, the runtime information would be gone.
So to accomplish this with newly added objects and layers, some kind of command would be required to “finalize” a detail and on demand, “unfinalize” it to make newly added objects and layers visible once added to the document.
I’ve been thinking about writing a script (for V7) which displays all layers in a dialog and allows to change their visibility for a list of pages and detail views found in the document, but:
Yes, the behaviour of newly added objects beeing automatically hidden (in modelspace, layoutspace and per detail) is working fine in Rhino 8 just by taking care to which layer these objects are added and by setting the desired visibility in the layer panel.
You should try this out in the WIP, once you’re in a layout page, the column in the layers panel for “Layout On” switches to “Detail On” as soon as you’re working in a detail view. So you can hide any layer per detail which is really cool. Once i’ve seen this UI for handling the problem, i quickly discarded my idea to write an UI for it using a script
_
c.