Author Topic: Set dxf 50 w/ lisp  (Read 3565 times)

0 Members and 1 Guest are viewing this topic.

Bryco

  • Water Moccasin
  • Posts: 1882
Set dxf 50 w/ lisp
« on: May 22, 2006, 11:32:52 AM »
Does anyone know how to set a views twistangle with Frank's VLAX.CLS.
Since I don't know lisp Ican' figure it out.

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: Set dxf 50 w/ lisp
« Reply #1 on: May 22, 2006, 12:51:41 PM »
As Tony T. would say, it makes more sense to have a lisp function that can be called rather than try to do it all with the VL interface. Here is a small function that does what you need, but I'm not sure what the TwistAngle actually does......I can cahnge it with this function, and the View dialog shows it as changed, but the actual view that gets restored is the same as it started out.

Anyway, you could just call this from VBA like so:
Code: [Select]
''First 2 functions from Tony T's example sent to me
Public vlApp As Object

' Initialize and/or return vl application object
' Note that we don't try to cache any other Vl
' objects, because they are all document-specific

Public Function GetVlApp() As Object
    If (vlApp Is Nothing) Then
        Set vlApp = AcadApplication.GetInterfaceObject("Vl.Application.16")
    End If
    Set GetVlApp = vlApp
End Function

' Call this to get a LISP function defined in the Active document
' (do not cache the result because it is document-specific)

Public Function VlFunc(Name As String) As Object
    Set VlFunc = GetVlApp.ActiveDocument.Functions.Item(Name)
End Function

''This calls the setviewangle lisp function
Sub testViewAngle()
Dim oView As AcadView
Dim dRot As Double

Set oView = ThisDrawing.Views.Item("test")
dRot = 1.57
    VlFunc("setviewangle").Funcall oView.Handle, dRot

End Sub

and the lisp:
Code: [Select]
(defun setviewangle (hndl ang / elist)
  (setq elist (entget (handent hndl)))
  (entmod (subst (cons 50 ang)(assoc 50 elist) elist))
  )
HTH,
Jeff

Bryco

  • Water Moccasin
  • Posts: 1882
Re: Set dxf 50 w/ lisp
« Reply #2 on: May 22, 2006, 04:06:47 PM »
Thanks Jeff, I'll give it a run tonight.

Bryco

  • Water Moccasin
  • Posts: 1882
Re: Set dxf 50 w/ lisp
« Reply #3 on: May 23, 2006, 04:02:41 PM »
Jeff this works
Code: [Select]
Sub testViewAngle()
Dim oView As AcadView
Dim dRot As Double

Set oView = ThisDrawing.Views.Add("test")
dRot = 1.57
    VlFunc("setviewangle").Funcall oView.handle, dRot
Set oView = ThisDrawing.Views.Item("test")
Dim V As AcadViewport
Set V = ThisDrawing.ActiveViewport
V.SetView oView
 ThisDrawing.ActiveViewport = V

End Sub
But as to the exact nature of 3d things, I've just reach a new low.
It seems this rotates about the z axis which may be the viewdir, and this is situated at the viewctr?????
Still needs a bit of work at my end.
I'm aiming at simulating the commands ucs->object then plan. I'm close but dang.

Bryco

  • Water Moccasin
  • Posts: 1882
Re: Set dxf 50 w/ lisp
« Reply #4 on: May 28, 2006, 01:38:47 PM »
Jeff I'm having trouble with the lisp autoloading, I have added the necessary to my acaddoc.lisp and no go. I have to load it in each new  drawing or I get the key not found. Then I tried using it as a string in the vlax class and I cant quite get that right.
Dim Vl As New VLAX
Dim sLisp As String
sLisp = "(setq elist (entget (handent """ & oView.handle & """))" & _
  "(entmod (subst (cons 50 """ & dRot & """)(assoc 50 elist) elist)))"
Vl.EvalLispExpression sLisp

Otherwise I did find a way to update a viewport, it seems it needs to be new to update. Previously I've used thisdrawing.save, which works but has some drawbacks (Doesn't work in refedit).
Looking at the handles, application.update does nothing as usual
Moving to ps/ms creates a new handle (and viewport)
Deleting works great.   thisdrawing.activeviewport.delete
The new activeviewport is updated

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: Set dxf 50 w/ lisp
« Reply #5 on: May 28, 2006, 03:11:54 PM »
Bryco, if you place that lisp I posted into your acaddoc.lsp, and the acaddoc.lsp is in the search path, it should load in each drawing. If it's not, there is something not right....

As for using it in VBA as you tried, here is the correct syntax, but it still does not work. The lisp variable "elist" gets set correctly, but the (entmod) fails and I don't see any reason for it to fail.

Bryco

  • Water Moccasin
  • Posts: 1882
Re: Set dxf 50 w/ lisp
« Reply #6 on: May 28, 2006, 03:25:17 PM »
I googled vl for about a very confusing hour and read something about needing vl-load-com. Whereever I put it it did no good so perhaps you do something at startup that allows for lisp calls from vl, or like you said there is something  wrong.

Jeff 
Quote
here is the correct syntax
didn't show up.
« Last Edit: May 28, 2006, 03:31:14 PM by Bryco »

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: Set dxf 50 w/ lisp
« Reply #7 on: May 28, 2006, 03:54:55 PM »
didn't show up.
Probably because I'm a moron and didn't paste it....really shouldn't try to post here and watch racing at the same time.....
Code: [Select]
sLisp = "(setq elist (entget (handent """ & oView.handle & """)))" & _
  "(entmod (subst (cons 50 " & dRot & ")(assoc 50 elist) elist))"
The (vl-load-com) only need be called once per Acad session. Just place it in your acad.lsp and forget about it.