TheSwamp
Code Red => VB(A) => Topic started by: MickD on January 16, 2008, 07:18:07 PM
-
There are a couple of threads here that touch on this but not quite what I'm after.
The code below works to set up a basic view using the current ucs, what I want to do now is to turn on clipping planes.
So far I have found the sysvar VIEWMODE which can be toggled with a bitmask, this is failing, any ideas?
The next problem will be setting the clipping distances, has anyone had any luck using functions from arx dll's??
Controls the View mode for the current viewport using bitcode. The value is the sum of the following:
0 Turned off.
1 Perspective view active.
2 Front clipping on.
4 Back clipping on.
8 UCS Follow mode on.
16 Front clip not at eye. If on, the front clip distance (FRONTZ) determines the front clipping plane. If off, FRONTZ is ignored, and the front clipping plane is set to pass through the camera point (vectors behind the camera are not displayed). This flag is ignored if the front clipping bit (2) is off.
Public Sub SetClippedView()
' This example creates a new view.
' It then changes the active viewport to
' the newly created view.
' Create a new view
Dim viewObj As AcadView
Set viewObj = ThisDrawing.Views.Add("TESTVIEW")
' Set the view characteristics
' get the current ucs values:
Dim xdir As Variant, ydir As Variant, zdir(2) As Double, ucsorigin As Variant
xdir = ThisDrawing.GetVariable("UCSXDIR")
ydir = ThisDrawing.GetVariable("UCSYDIR")
'cross the x and y vecs to get the zdir
Dim xv(2) As Double, yv(2) As Double
InitVec xv, xdir: InitVec yv, ydir
VecCross zdir, xv, yv
ucsorigin = ThisDrawing.GetVariable("UCSORG")
viewObj.Center(0) = ucsorigin(0): viewObj.Center(1) = ucsorigin(1)
viewObj.Direction = zdir
viewObj.Target = ucsorigin
'set the clipping planes on:
ThisDrawing.SetVariable "VIEWMODE", 6 '<<-------- fails here
' Get the current active viewport
Dim viewportObj As AcadViewport
Set viewportObj = ThisDrawing.ActiveViewport
' Set the view in the viewport
viewportObj.SetView viewObj
ThisDrawing.ActiveViewport = viewportObj
ThisDrawing.Regen True
ThisDrawing.SendCommand "_zoom" & vbCr & "a" & vbCr
End Sub
-
It's been a decade or more since I'd done it (think it was '95), but I have established clipping planes successfully from lisp. I'll see if I can find the code and salient bits; so to speak.
-
My answer to set the clipping planes just bit me on the ... it's right there anyway (frontz/backz) :roll:
-
Ok, my biggest problem is setting the sysvar's, it seems you need to do some gymnastics to set them, this is what I have so far but it's still failing, I'll have a bit of a dig around in the meantime.
'set the clipping planes on:
Dim distF As Double, distB As Double, vmode As Integer, vardata As Variant
distF = 500#: distB = -500#: vmode = 6
vardata = distF
ThisDrawing.SetVariable "FRONTZ", vardata
vardata = distB
ThisDrawing.SetVariable "BACKZ", vardata
vardata = vmode
ThisDrawing.SetVariable "VIEWMODE", vardata
-
I found the code Mick but yeow, it's fugly.
In essence what I had done was create a temporary view object, entmod it to suit, and then set it active. The view object variables (dxf group codes) I modified were:
Group Code | Description | Activex Equivalent |
10 | View Center | Center (safe array) |
11 | View Dir | Direction (safe array) |
12 | View Target | Target (safe array) |
43 | Front Z | N/A |
44 | Back Z | N/A |
50 | View Twist | N/A |
71 | View Mode | N/A |
What I found trying to complete the table above is that, once again, the object model fails to map 1:1 with the dxf group codes; grrrr. Note that I interrogated a view object directly rather than rely on the help file, so I'm pretty sure the noted properties are not exposed (not even as hidden properties). Could be wrong though.
So (if I understand correctly) it means if one is using VB[A] you are limited to using the sys vars to set the clipping planes et al, as you're doing in your last post.
The blue vars above are what you're addressing in your code; the red ones are vars you may need to set (or confirm their value) in order to complete your quest. Sorry, that's all I've got for now.
Sorry.
-
Thanks Michael, that's probably why I can't set them, bummer!
I can get the vardata ok though, what good it does me :(
-
Oh well, got the old arx crutch out again :D
The attached arx (for 2007/8) has 2 commands:
SETCLIPVIEW - set the view to the current ucs with clipping planes turned on front and back at a distance of 500mm/-500mm respectively. Set your ucs to a point and direction you want to work and run.
VIEWSEISO - sets the view to the std south east iso view and turns clipping off.
If anyone wants the solution or code just holler.
ADDED: I just added an imperial version that sets the clip planes to 24 inches, hope that suits, if not let me know.
-
Mick the Arx is probably the way to go.
Center- being a 2d point it is very difficult to figure out the plane this 2d point needs to be on, I thought it would be in dcs but that doesn't necessarily work.
The origin of the DCS is the point stored in the AutoCAD system variable TARGET, and its Z axis is the viewing direction, however the target doesn't update.
"VIEWMODE" is read only.
I'll look a little more.
-
The sad thing is one line of lisp can set the orientation, clipping planes, yada If it weren't late and I hadn't already taken a sleeping pill I'd toss up a snip but my noggin' is be getting slammed.