Author Topic: Set view with ucs & clipping planes  (Read 3482 times)

0 Members and 1 Guest are viewing this topic.

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Set view with ucs & clipping planes
« 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??

Quote
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.

Code: [Select]
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
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Set view with ucs & clipping planes
« Reply #1 on: January 16, 2008, 07:24:15 PM »
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.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Set view with ucs & clipping planes
« Reply #2 on: January 16, 2008, 07:34:52 PM »
My answer to set the clipping planes just bit me on the ... it's right there anyway (frontz/backz)  :roll:
« Last Edit: January 16, 2008, 07:39:48 PM by MickD »
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Set view with ucs & clipping planes
« Reply #3 on: January 16, 2008, 07:39:03 PM »
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.

Code: [Select]
'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
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Set view with ucs & clipping planes
« Reply #4 on: January 16, 2008, 08:25:15 PM »
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
10View CenterCenter (safe array)
11View DirDirection (safe array)
12View TargetTarget (safe array)
43Front ZN/A
44Back ZN/A
50View TwistN/A
71View ModeN/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.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Set view with ucs & clipping planes
« Reply #5 on: January 16, 2008, 08:32:31 PM »
Thanks Michael, that's probably why I can't set them, bummer!

I can get the vardata ok though, what good it does me :(
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Set view with ucs & clipping planes
« Reply #6 on: January 16, 2008, 11:12:40 PM »
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.
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

Bryco

  • Water Moccasin
  • Posts: 1882
Re: Set view with ucs & clipping planes
« Reply #7 on: January 16, 2008, 11:38:16 PM »
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.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Set view with ucs & clipping planes
« Reply #8 on: January 17, 2008, 12:56:20 AM »
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.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst