Author Topic: vlax-curve-getClosestPointTo Problem  (Read 2278 times)

0 Members and 1 Guest are viewing this topic.

Lemank

  • Guest
vlax-curve-getClosestPointTo Problem
« on: December 03, 2006, 11:34:29 AM »
Hi -

I am trying to communicate between VBA and VLisp to use the vlax-curve functions using the setlispvar and evallispexpression code. I cannot seem to get the code to work properly. The attached file contains my code. The code attempts to draw a line from (0,0,0) to (100,100,0), then find the closest point to (50,55,0). The problem seems to be in translating the point variant to a point list. Any help would be greatly appreciated as I am thoroughly frustrated and "brain dead" at this point, knowing that I am overlooking something very obvious or doing something very dumb!!

Thanks in advance

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: vlax-curve-getClosestPointTo Problem
« Reply #1 on: December 03, 2006, 01:42:31 PM »
Here's a snip of code from Frank Oquendo's VLAX.CLS that handles setting lisp symbols. Note how it differs from yours in that he uses lisp functions to convert the data types.
Code: [Select]
Public Sub SetLispSymbol(symbolName As String, value)

    Dim sym As Object, ret, symValue
   
    symValue = value
    Set sym = VLF.Item("read").funcall(symbolName)
    ret = VLF.Item("set").funcall(sym, symValue)
    EvalLispExpression "(defun translate-variant (data) (cond ((= (type data) 'list) (mapcar 'translate-variant data)) ((= (type data) 'variant) (translate-variant (vlax-variant-value data))) ((= (type data) 'safearray) (mapcar 'translate-variant (vlax-safearray->list data))) (t data)))"
    EvalLispExpression "(setq " & symbolName & "(translate-variant " & symbolName & "))"
    EvalLispExpression "(setq translate-variant nil)"

End Sub

Bryco

  • Water Moccasin
  • Posts: 1883
Re: vlax-curve-getClosestPointTo Problem
« Reply #2 on: December 03, 2006, 02:45:06 PM »

I use  Frank's class,it's easy to use and does what you need.
(I'm on 2006, I haven't tried it on 2007)
' Curve.cls v1.3 (Last updated 12/18/2001)
' Copyright 2000, 2001 by Frank Oquendo

Lemank

  • Guest
Re: vlax-curve-getClosestPointTo Problem
« Reply #3 on: December 05, 2006, 08:05:18 PM »
Thanks guys!!

I appreciate the tips. I am still trying to resolve the problem. I have tried the Curve class with some success. It seems to work fine for my test drawing which has only a few Aecc points at coordinates with values less than 10,000. I tried it on a larger drawing with about 300 points at state plane coordinates of 10,000,000 for x and 3,000,000 for y and it gives an error message at different points with no consistency. If I translate the points to values less than 10,000, it works flawlessly for the 300 points. Could the problem be with some values being expressed in scientific notation because I keep getting error code 13?

Anyway, I will keep playing with it. Thanks again for your help!!!

Bryco

  • Water Moccasin
  • Posts: 1883
Re: vlax-curve-getClosestPointTo Problem
« Reply #4 on: December 05, 2006, 09:21:11 PM »
Cad itself has problems offsetting when you are too far from the origin and vba's low  accuracy doesn't help much.
If you only want closest point I will post some code w/ math that I like better.