Using SectionTools API?

Hi @rajaa,

Could you share how can we create a clippingplane or section plane active on all viewports using python?

Thanks in advance.

and use overload to give more viewport ids at the same time.

https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_DocObjects_Tables_ObjectTable_AddClippingPlane.htm

Yes, I know that but I want the section/clipping plane to be active on all viewports.

id = scriptcontext.doc.Objects.AddClippingPlane(plane, p0.DistanceTo(p1), p0.DistanceTo(p3), view.ActiveViewportID)

This is the python example and I don’t know where view.ActiveViewportID. is coming from there’s no view variable in the script nor in the imports

That is why I gave you the link to the AddClippingPlane overload that takes a list (enumerable) of viewport ids…

if you have trouble figuring out views:

Hi Nathan,

How can I get viewport’s ID?

from scriptcontext import doc
for view in doc.Views:
    clipping_plane = rs.AddClippingPlane(some_plane,10,10,view) # this fails because view is a viewport and not an ID

I also found these commands here RH-32856

Rhino.Geometry.ClippingPlaneSurface.AddClipViewportId
Rhino.Geometry.ClippingPlaneSurface.RemoveClipViewportId

Rhino.DocObjects.ClippingPlaneObject.AddClipViewport
Rhino.DocObjects.ClippingPlaneObject.RemoveClipViewport

Though I don’t know how to use them, it is confusing because AddClipViewportID wants the ID of the viewport and AddClipViewport requires the clipping plane as ID which I also don’t know how to get because rhinoscriptsyntax results in objects not IDs and they don’t have an attribute .Id()

====================================

UPDATE:
I got it working like this:

	for view in doc.Views:
		doc.Views.ActiveView = view
		vid = doc.Views.ActiveView.ActiveViewportID
		clp1 = rs.AddClippingPlane(pl1,10,10,vid)

But that creates several clippingplanes instead of one that’s active on all viewports.

That is because you create several clipping planes - one for each view. If you read

https://developer.rhino3d.com/api/RhinoScriptSyntax/#geometry-AddClippingPlane

you’ll see you can pass in a list of GUID. So first create your list, then pass it to the function.

Oh is that what views ([str|guid, ...]) means it is very unclear to me. I saw the [ ] but would it hurt to put the word List in there. I tried to pass a list of type RhinoView but it again showed me it wants an ID and I gave up that Idea.

Thanks @nathanletwory, I’ll try that now.

LoL you really don’t want it easy for your programmers :smiley:

image

BTW I was searching through the API for ViewTable and there were no results :smiley:

doc.Views = ViewTable I’ll have to write that down.

The ViewTable API is here https://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_DocObjects_Tables_ViewTable.htm

Use Find(Guid)

And your doc is Rhino.RhinoDoc.

I did this:

vList = []
for view in doc.Views:
	doc.Views.ActiveView = view
	vid = doc.Views.ActiveView.ActiveViewportID
	vList.append(vid)

Result is not very pretty :smiley:

I have no idea why you would be setting the active view.

The sample code I pasted earlier already shows you how to harvest data from the ViewTable.

The list comprehension for non_active_views.

because all I can see is .ActiveViewID there’s no get all IDs inside doc.views

So I have to loop through making them all current view then get that ID. It is stupid and I don’t know if it is me overlooking something or it is just missing from the API

Reread the sample, try to understand how the data is harvested…

I did that, to get all views first it’s naming the Active view then loops through ones that has no name and prompts them to the user to pick which one should be the active one. Still you can’t get the ID of non-active viewport.

It is not naming the active view…

[view for view in doc.Views] gives you a list of all views. You could also do [view.ActiveViewport for view in doc.Views] to get a list of active viewport per view… Now, do you see how you could get the ID?

crap I have to go to work.

I hate single-line loops I cannot read them very well. I’ll tryout some more in the evening.

This didn’t work I know it’s my fault because (the above)
vList = view.ActiveViewportID for view in doc.Views

Have a nice day, Nathan.

Just correction. This did work.

You are missing the square brackets. But you can also just take the information given and use a regular loop

vlist=[]
for v in doc.Views:
  vlist.append(v.ActiveViewportID)

No I dont miss them they were declared above I just didnt copy them here.

:roll_eyes: